@trezor/connect 9.0.2 → 9.0.4
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/README.md +5 -5
- package/lib/api/authorizeCoinJoin.js +6 -2
- package/lib/api/bitcoin/TransactionComposer.js +2 -1
- package/lib/api/bitcoin/enhanceSignTx.js +1 -1
- package/lib/api/bitcoin/inputs.js +3 -2
- package/lib/api/bitcoin/outputs.js +2 -4
- package/lib/api/bitcoin/refTx.js +3 -3
- package/lib/api/bitcoin/signtxVerify.d.ts +3 -3
- package/lib/api/bitcoin/signtxVerify.js +16 -15
- package/lib/api/blockchainDisconnect.js +1 -1
- package/lib/api/blockchainSetCustomBackend.js +1 -1
- package/lib/api/cardano/cardanoAuxiliaryData.d.ts +1 -1
- package/lib/api/cardano/cardanoAuxiliaryData.js +38 -16
- package/lib/api/cardanoSignTransaction.d.ts +1 -0
- package/lib/api/cardanoSignTransaction.js +23 -3
- package/lib/api/getAddress.d.ts +2 -1
- package/lib/api/getAddress.js +12 -1
- package/lib/api/getOwnershipProof.d.ts +1 -5
- package/lib/api/getOwnershipProof.js +5 -3
- package/lib/api/getPublicKey.d.ts +1 -0
- package/lib/api/getPublicKey.js +22 -7
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +5 -1
- package/lib/api/setBusy.d.ts +7 -0
- package/lib/api/setBusy.js +27 -0
- package/lib/api/signTransaction.d.ts +2 -1
- package/lib/api/signTransaction.js +24 -5
- package/lib/api/unlockPath.d.ts +10 -0
- package/lib/api/unlockPath.js +35 -0
- package/lib/backend/BackendManager.d.ts +21 -0
- package/lib/backend/BackendManager.js +91 -0
- package/lib/backend/Blockchain.d.ts +72 -0
- package/lib/backend/Blockchain.js +204 -0
- package/lib/backend/BlockchainLink.d.ts +6 -71
- package/lib/backend/BlockchainLink.js +12 -288
- package/lib/constants/cardano.d.ts +3 -1
- package/lib/constants/cardano.js +3 -1
- package/lib/core/AbstractMethod.d.ts +1 -0
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/method.d.ts +1 -1
- package/lib/data/config.js +2 -2
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +1 -1
- package/lib/device/Device.js +8 -2
- package/lib/device/DeviceCommands.d.ts +8 -2
- package/lib/device/DeviceCommands.js +48 -25
- package/lib/factory.js +2 -0
- package/lib/types/api/authorizeCoinJoin.d.ts +1 -0
- package/lib/types/api/bitcoin/index.d.ts +5 -0
- package/lib/types/api/cardano/index.d.ts +13 -10
- package/lib/types/api/eos/index.d.ts +0 -4
- package/lib/types/api/eosGetPublicKey.d.ts +4 -4
- package/lib/types/api/getAddress.d.ts +1 -0
- package/lib/types/api/getPublicKey.d.ts +5 -0
- package/lib/types/api/index.d.ts +4 -0
- package/lib/types/api/setBusy.d.ts +4 -0
- package/lib/types/api/setBusy.js +3 -0
- package/lib/types/api/unlockPath.d.ts +8 -0
- package/lib/types/api/unlockPath.js +3 -0
- package/lib/utils/pathUtils.d.ts +2 -3
- package/lib/utils/pathUtils.js +42 -15
- package/package.json +19 -7
- package/lib/api/bitcoin/__fixtures__/inputs.d.ts +0 -112
- package/lib/api/bitcoin/__fixtures__/inputs.js +0 -102
- package/lib/api/bitcoin/__fixtures__/signtxVerify.d.ts +0 -147
- package/lib/api/bitcoin/__fixtures__/signtxVerify.js +0 -216
- package/lib/api/common/__fixtures__/paramsValidator.d.ts +0 -596
- package/lib/api/common/__fixtures__/paramsValidator.js +0 -355
- package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.d.ts +0 -225
- package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.js +0 -341
- package/lib/utils/__fixtures__/accountUtils.d.ts +0 -4
- package/lib/utils/__fixtures__/accountUtils.js +0 -32
- package/lib/utils/__fixtures__/addressUtils.d.ts +0 -10
- package/lib/utils/__fixtures__/addressUtils.js +0 -214
- package/lib/utils/__fixtures__/ethereumUtils.d.ts +0 -3
- package/lib/utils/__fixtures__/ethereumUtils.js +0 -20
- package/lib/utils/__fixtures__/formatUtils.d.ts +0 -3
- package/lib/utils/__fixtures__/formatUtils.js +0 -15
- package/lib/utils/__fixtures__/hdnodeUtils.d.ts +0 -186
- package/lib/utils/__fixtures__/hdnodeUtils.js +0 -206
- package/lib/utils/bufferUtils.d.ts +0 -3
- package/lib/utils/bufferUtils.js +0 -11
|
@@ -1,75 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare type Options = {
|
|
6
|
-
coinInfo: CoinInfo;
|
|
7
|
-
postMessage: (message: CoreMessage) => void;
|
|
8
|
-
proxy?: Proxy;
|
|
9
|
-
onionDomains?: {
|
|
10
|
-
[domain: string]: string;
|
|
11
|
-
};
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export declare class Blockchain {
|
|
15
|
-
link: BlockchainLink;
|
|
16
|
-
serverInfo?: ServerInfo;
|
|
17
|
-
coinInfo: Options['coinInfo'];
|
|
18
|
-
onionDomains: {
|
|
19
|
-
[onion: string]: string;
|
|
20
|
-
};
|
|
21
|
-
postMessage: Options['postMessage'];
|
|
22
|
-
feeForBlock: BlockchainLinkResponse<'estimateFee'>;
|
|
23
|
-
feeTimestamp: number;
|
|
24
|
-
constructor(options: Options);
|
|
25
|
-
onError(error: ERRORS.TrezorError): void;
|
|
26
|
-
init(): Promise<void>;
|
|
27
|
-
getTransactions(txs: string[]): Promise<import("@trezor/blockchain-link").TypedRawTransaction[]>;
|
|
28
|
-
getCurrentFiatRates(params: {
|
|
29
|
-
currencies?: string[];
|
|
30
|
-
}): Promise<{
|
|
31
|
-
ts: number;
|
|
32
|
-
rates: import("@trezor/blockchain-link").FiatRates;
|
|
33
|
-
}>;
|
|
34
|
-
getFiatRatesForTimestamps(params: {
|
|
35
|
-
timestamps: number[];
|
|
36
|
-
}): Promise<{
|
|
37
|
-
tickers: {
|
|
38
|
-
ts: number;
|
|
39
|
-
rates: import("@trezor/blockchain-link").FiatRates;
|
|
40
|
-
}[];
|
|
41
|
-
}>;
|
|
42
|
-
getAccountBalanceHistory(params: BlockchainLinkParams<'getAccountBalanceHistory'>): Promise<import("@trezor/blockchain-link").AccountBalanceHistory[]>;
|
|
43
|
-
getNetworkInfo(): Promise<ServerInfo>;
|
|
44
|
-
getAccountInfo(request: BlockchainLinkParams<'getAccountInfo'>): Promise<import("@trezor/blockchain-link").AccountInfo>;
|
|
45
|
-
getAccountUtxo(descriptor: string): Promise<import("@trezor/blockchain-link").Utxo[]>;
|
|
46
|
-
estimateFee(request: {
|
|
47
|
-
blocks?: number[];
|
|
48
|
-
}): Promise<{
|
|
49
|
-
feePerUnit: string;
|
|
50
|
-
feePerTx?: string | undefined;
|
|
51
|
-
feeLimit?: string | undefined;
|
|
52
|
-
}[]>;
|
|
53
|
-
subscribe(accounts?: SubscriptionAccountInfo[]): Promise<{
|
|
54
|
-
subscribed: boolean;
|
|
55
|
-
}>;
|
|
56
|
-
subscribeFiatRates(_currency?: string): Promise<{
|
|
57
|
-
subscribed: boolean;
|
|
58
|
-
}>;
|
|
59
|
-
unsubscribe(accounts?: SubscriptionAccountInfo[]): Promise<{
|
|
60
|
-
subscribed: boolean;
|
|
61
|
-
}>;
|
|
62
|
-
unsubscribeFiatRates(): Promise<{
|
|
63
|
-
subscribed: boolean;
|
|
64
|
-
}>;
|
|
65
|
-
pushTransaction(tx: string): Promise<string>;
|
|
66
|
-
disconnect(): void;
|
|
67
|
-
}
|
|
68
|
-
export declare const findBackend: (name: string) => Blockchain | null;
|
|
1
|
+
import type { BlockchainOptions as Options } from './Blockchain';
|
|
2
|
+
import type { CoinInfo } from '../types';
|
|
3
|
+
export { Blockchain } from './Blockchain';
|
|
4
|
+
export declare const findBackend: (coin: string) => import("./Blockchain").Blockchain | null;
|
|
69
5
|
export declare const setCustomBackend: (coinInfo: CoinInfo, blockchainLink: CoinInfo['blockchainLink']) => void;
|
|
70
6
|
export declare const isBackendSupported: (coinInfo: CoinInfo) => void;
|
|
71
|
-
export declare const initBlockchain: (coinInfo: CoinInfo, postMessage: Options['postMessage']) => Promise<Blockchain>;
|
|
72
|
-
export declare const reconnectAllBackends: () => Promise<Blockchain[]>;
|
|
7
|
+
export declare const initBlockchain: (coinInfo: CoinInfo, postMessage: Options['postMessage']) => Promise<import("./Blockchain").Blockchain>;
|
|
8
|
+
export declare const reconnectAllBackends: () => Promise<import("./Blockchain").Blockchain[]>;
|
|
73
9
|
export declare const dispose: () => void;
|
|
74
|
-
export {};
|
|
75
10
|
//# sourceMappingURL=BlockchainLink.d.ts.map
|
|
@@ -1,298 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dispose = exports.reconnectAllBackends = exports.initBlockchain = exports.isBackendSupported = exports.setCustomBackend = exports.findBackend = exports.Blockchain = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const constants_1 = require("../constants");
|
|
10
|
-
const urlUtils_1 = require("../utils/urlUtils");
|
|
11
|
-
const workers_1 = require("../workers/workers");
|
|
12
|
-
const getWorker = (type) => {
|
|
13
|
-
switch (type) {
|
|
14
|
-
case 'blockbook':
|
|
15
|
-
return workers_1.BlockbookWorker;
|
|
16
|
-
case 'ripple':
|
|
17
|
-
return workers_1.RippleWorker;
|
|
18
|
-
case 'blockfrost':
|
|
19
|
-
return workers_1.BlockfrostWorker;
|
|
20
|
-
case 'electrum':
|
|
21
|
-
return workers_1.ElectrumWorker;
|
|
22
|
-
default:
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
class Blockchain {
|
|
27
|
-
constructor(options) {
|
|
28
|
-
this.feeForBlock = [];
|
|
29
|
-
this.feeTimestamp = 0;
|
|
30
|
-
this.coinInfo = options.coinInfo;
|
|
31
|
-
this.postMessage = options.postMessage;
|
|
32
|
-
const { blockchainLink } = options.coinInfo;
|
|
33
|
-
if (!blockchainLink) {
|
|
34
|
-
throw constants_1.ERRORS.TypedError('Backend_NotSupported');
|
|
35
|
-
}
|
|
36
|
-
const worker = getWorker(blockchainLink.type);
|
|
37
|
-
if (!worker) {
|
|
38
|
-
throw constants_1.ERRORS.TypedError('Backend_WorkerMissing', `BlockchainLink worker not found ${blockchainLink.type}`);
|
|
39
|
-
}
|
|
40
|
-
const { onionDomains } = options;
|
|
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;
|
|
53
|
-
this.link = new blockchain_link_1.default({
|
|
54
|
-
name: this.coinInfo.shortcut,
|
|
55
|
-
worker,
|
|
56
|
-
server,
|
|
57
|
-
debug: options.debug,
|
|
58
|
-
proxy: options.proxy,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
onError(error) {
|
|
62
|
-
this.link.dispose();
|
|
63
|
-
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.ERROR, {
|
|
64
|
-
coin: this.coinInfo,
|
|
65
|
-
error: error.message,
|
|
66
|
-
code: error.code,
|
|
67
|
-
}));
|
|
68
|
-
removeBackend(this);
|
|
69
|
-
}
|
|
70
|
-
async init() {
|
|
71
|
-
this.link.on('connected', async () => {
|
|
72
|
-
const info = await this.link.getInfo();
|
|
73
|
-
this.serverInfo = info;
|
|
74
|
-
const shortcut = this.coinInfo.shortcut === 'tXRP' ? 'XRP' : this.coinInfo.shortcut;
|
|
75
|
-
if (info.shortcut.toLowerCase() !== shortcut.toLowerCase()) {
|
|
76
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Invalid'));
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const cleanUrl = this.onionDomains[info.url];
|
|
80
|
-
setPreferredBacked(this.coinInfo, cleanUrl || info.url);
|
|
81
|
-
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
|
|
82
|
-
coin: this.coinInfo,
|
|
83
|
-
...info,
|
|
84
|
-
cleanUrl,
|
|
85
|
-
}));
|
|
86
|
-
});
|
|
87
|
-
this.link.on('disconnected', () => {
|
|
88
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Disconnected'));
|
|
89
|
-
});
|
|
90
|
-
this.link.on('error', error => {
|
|
91
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Error', error.message));
|
|
92
|
-
});
|
|
93
|
-
try {
|
|
94
|
-
await this.link.connect();
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Error', error.message));
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
getTransactions(txs) {
|
|
102
|
-
return Promise.all(txs.map(id => this.link.getTransaction(id)));
|
|
103
|
-
}
|
|
104
|
-
getCurrentFiatRates(params) {
|
|
105
|
-
return this.link.getCurrentFiatRates(params);
|
|
106
|
-
}
|
|
107
|
-
getFiatRatesForTimestamps(params) {
|
|
108
|
-
return this.link.getFiatRatesForTimestamps(params);
|
|
109
|
-
}
|
|
110
|
-
getAccountBalanceHistory(params) {
|
|
111
|
-
return this.link.getAccountBalanceHistory(params);
|
|
112
|
-
}
|
|
113
|
-
getNetworkInfo() {
|
|
114
|
-
return this.link.getInfo();
|
|
115
|
-
}
|
|
116
|
-
getAccountInfo(request) {
|
|
117
|
-
return this.link.getAccountInfo(request);
|
|
118
|
-
}
|
|
119
|
-
getAccountUtxo(descriptor) {
|
|
120
|
-
return this.link.getAccountUtxo(descriptor);
|
|
121
|
-
}
|
|
122
|
-
async estimateFee(request) {
|
|
123
|
-
const { blocks } = request;
|
|
124
|
-
if (blocks) {
|
|
125
|
-
const now = Date.now();
|
|
126
|
-
const outdated = now - this.feeTimestamp > 20 * 60 * 1000;
|
|
127
|
-
const unknownBlocks = blocks.filter(() => typeof this.feeForBlock !== 'string');
|
|
128
|
-
if (!outdated && unknownBlocks.length < 1) {
|
|
129
|
-
}
|
|
130
|
-
const fees = await this.link.estimateFee(request);
|
|
131
|
-
blocks.forEach((block, index) => {
|
|
132
|
-
this.feeForBlock[block] = fees[index];
|
|
133
|
-
});
|
|
134
|
-
this.feeTimestamp = now;
|
|
135
|
-
return fees;
|
|
136
|
-
}
|
|
137
|
-
return this.link.estimateFee(request);
|
|
138
|
-
}
|
|
139
|
-
async subscribe(accounts) {
|
|
140
|
-
if (this.link.listenerCount('block') === 0) {
|
|
141
|
-
this.link.on('block', block => {
|
|
142
|
-
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.BLOCK, {
|
|
143
|
-
coin: this.coinInfo,
|
|
144
|
-
...block,
|
|
145
|
-
}));
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if (this.link.listenerCount('notification') === 0) {
|
|
149
|
-
this.link.on('notification', notification => {
|
|
150
|
-
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.NOTIFICATION, {
|
|
151
|
-
coin: this.coinInfo,
|
|
152
|
-
notification,
|
|
153
|
-
}));
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
const blockSubscription = await this.link.subscribe({ type: 'block' });
|
|
157
|
-
if (!accounts) {
|
|
158
|
-
return blockSubscription;
|
|
159
|
-
}
|
|
160
|
-
return this.link.subscribe({
|
|
161
|
-
type: 'accounts',
|
|
162
|
-
accounts,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
subscribeFiatRates(_currency) {
|
|
166
|
-
if (this.link.listenerCount('fiatRates') === 0) {
|
|
167
|
-
this.link.on('fiatRates', ({ rates }) => {
|
|
168
|
-
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.FIAT_RATES_UPDATE, {
|
|
169
|
-
coin: this.coinInfo,
|
|
170
|
-
rates,
|
|
171
|
-
}));
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
return this.link.subscribe({
|
|
175
|
-
type: 'fiatRates',
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
async unsubscribe(accounts) {
|
|
179
|
-
if (!accounts) {
|
|
180
|
-
this.link.removeAllListeners('block');
|
|
181
|
-
this.link.removeAllListeners('fiatRates');
|
|
182
|
-
this.link.removeAllListeners('notification');
|
|
183
|
-
await this.link.unsubscribe({ type: 'fiatRates' });
|
|
184
|
-
return this.link.unsubscribe({ type: 'block' });
|
|
185
|
-
}
|
|
186
|
-
return this.link.unsubscribe({ type: 'accounts', accounts });
|
|
187
|
-
}
|
|
188
|
-
unsubscribeFiatRates() {
|
|
189
|
-
this.link.removeAllListeners('fiatRates');
|
|
190
|
-
return this.link.unsubscribe({ type: 'fiatRates' });
|
|
191
|
-
}
|
|
192
|
-
pushTransaction(tx) {
|
|
193
|
-
return this.link.pushTransaction(tx);
|
|
194
|
-
}
|
|
195
|
-
disconnect() {
|
|
196
|
-
this.link.removeAllListeners();
|
|
197
|
-
this.link.disconnect();
|
|
198
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Disconnected'));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
exports.Blockchain = Blockchain;
|
|
202
|
-
const instances = [];
|
|
203
|
-
const customBackends = {};
|
|
204
|
-
const preferredBackends = {};
|
|
205
|
-
const removeBackend = (backend) => {
|
|
206
|
-
const index = instances.indexOf(backend);
|
|
207
|
-
if (index >= 0) {
|
|
208
|
-
instances.splice(index, 1);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
const findBackend = (name) => {
|
|
212
|
-
for (let i = 0; i < instances.length; i++) {
|
|
213
|
-
if (instances[i].coinInfo.name === name) {
|
|
214
|
-
return instances[i];
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return null;
|
|
218
|
-
};
|
|
4
|
+
const BackendManager_1 = require("./BackendManager");
|
|
5
|
+
var Blockchain_1 = require("./Blockchain");
|
|
6
|
+
Object.defineProperty(exports, "Blockchain", { enumerable: true, get: function () { return Blockchain_1.Blockchain; } });
|
|
7
|
+
const backends = new BackendManager_1.BackendManager();
|
|
8
|
+
const findBackend = (coin) => backends.get(coin);
|
|
219
9
|
exports.findBackend = findBackend;
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
else if (coinInfo.blockchainLink) {
|
|
225
|
-
preferredBackends[coinInfo.shortcut] = {
|
|
226
|
-
...coinInfo,
|
|
227
|
-
blockchainLink: {
|
|
228
|
-
...coinInfo.blockchainLink,
|
|
229
|
-
url: [url],
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
const setCustomBackend = (coinInfo, blockchainLink) => {
|
|
235
|
-
setPreferredBacked(coinInfo);
|
|
236
|
-
if (!blockchainLink || blockchainLink.url.length === 0) {
|
|
237
|
-
delete customBackends[coinInfo.shortcut];
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
customBackends[coinInfo.shortcut] = {
|
|
241
|
-
...coinInfo,
|
|
242
|
-
blockchainLink,
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
};
|
|
10
|
+
const setCustomBackend = (coinInfo, blockchainLink) => (blockchainLink === null || blockchainLink === void 0 ? void 0 : blockchainLink.url.length)
|
|
11
|
+
? backends.setCustom(coinInfo.shortcut, blockchainLink)
|
|
12
|
+
: backends.removeCustom(coinInfo.shortcut);
|
|
246
13
|
exports.setCustomBackend = setCustomBackend;
|
|
247
|
-
const isBackendSupported = (coinInfo) =>
|
|
248
|
-
const info = customBackends[coinInfo.shortcut] || coinInfo;
|
|
249
|
-
if (!info.blockchainLink) {
|
|
250
|
-
throw constants_1.ERRORS.TypedError('Backend_NotSupported');
|
|
251
|
-
}
|
|
252
|
-
};
|
|
14
|
+
const isBackendSupported = (coinInfo) => backends.isSupported(coinInfo);
|
|
253
15
|
exports.isBackendSupported = isBackendSupported;
|
|
254
|
-
const initBlockchain =
|
|
255
|
-
let backend = (0, exports.findBackend)(coinInfo.name);
|
|
256
|
-
if (!backend) {
|
|
257
|
-
backend = new Blockchain({
|
|
258
|
-
coinInfo: preferredBackends[coinInfo.shortcut] ||
|
|
259
|
-
customBackends[coinInfo.shortcut] ||
|
|
260
|
-
coinInfo,
|
|
261
|
-
postMessage,
|
|
262
|
-
debug: DataManager_1.DataManager.getSettings('debug'),
|
|
263
|
-
proxy: DataManager_1.DataManager.getSettings('proxy'),
|
|
264
|
-
onionDomains: DataManager_1.DataManager.getSettings('useOnionLinks') && !customBackends[coinInfo.shortcut]
|
|
265
|
-
? config_1.config.onionDomains
|
|
266
|
-
: undefined,
|
|
267
|
-
});
|
|
268
|
-
instances.push(backend);
|
|
269
|
-
try {
|
|
270
|
-
await backend.init();
|
|
271
|
-
}
|
|
272
|
-
catch (error) {
|
|
273
|
-
removeBackend(backend);
|
|
274
|
-
setPreferredBacked(coinInfo);
|
|
275
|
-
throw error;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return backend;
|
|
279
|
-
};
|
|
16
|
+
const initBlockchain = (coinInfo, postMessage) => backends.getOrConnect(coinInfo, postMessage);
|
|
280
17
|
exports.initBlockchain = initBlockchain;
|
|
281
|
-
const reconnectAllBackends = () =>
|
|
282
|
-
const params = instances.map(i => [
|
|
283
|
-
i.coinInfo,
|
|
284
|
-
i.postMessage,
|
|
285
|
-
]);
|
|
286
|
-
while (instances.length > 0) {
|
|
287
|
-
instances[0].disconnect();
|
|
288
|
-
}
|
|
289
|
-
return Promise.all(params.map(p => (0, exports.initBlockchain)(...p)));
|
|
290
|
-
};
|
|
18
|
+
const reconnectAllBackends = () => backends.reconnectAll();
|
|
291
19
|
exports.reconnectAllBackends = reconnectAllBackends;
|
|
292
|
-
const dispose = () =>
|
|
293
|
-
while (instances.length > 0) {
|
|
294
|
-
instances[0].disconnect();
|
|
295
|
-
}
|
|
296
|
-
};
|
|
20
|
+
const dispose = () => backends.dispose();
|
|
297
21
|
exports.dispose = dispose;
|
|
298
22
|
//# sourceMappingURL=BlockchainLink.js.map
|
package/lib/constants/cardano.js
CHANGED
|
@@ -4,7 +4,9 @@ exports.NETWORK_IDS = exports.PROTOCOL_MAGICS = void 0;
|
|
|
4
4
|
var PROTOCOL_MAGICS;
|
|
5
5
|
(function (PROTOCOL_MAGICS) {
|
|
6
6
|
PROTOCOL_MAGICS[PROTOCOL_MAGICS["mainnet"] = 764824073] = "mainnet";
|
|
7
|
-
PROTOCOL_MAGICS[PROTOCOL_MAGICS["
|
|
7
|
+
PROTOCOL_MAGICS[PROTOCOL_MAGICS["testnet_preprod"] = 1] = "testnet_preprod";
|
|
8
|
+
PROTOCOL_MAGICS[PROTOCOL_MAGICS["testnet_preview"] = 2] = "testnet_preview";
|
|
9
|
+
PROTOCOL_MAGICS[PROTOCOL_MAGICS["testnet_legacy"] = 1097911063] = "testnet_legacy";
|
|
8
10
|
})(PROTOCOL_MAGICS = exports.PROTOCOL_MAGICS || (exports.PROTOCOL_MAGICS = {}));
|
|
9
11
|
var NETWORK_IDS;
|
|
10
12
|
(function (NETWORK_IDS) {
|
|
@@ -27,6 +27,7 @@ export declare abstract class AbstractMethod<Name extends CallMethodPayload['met
|
|
|
27
27
|
useUi: boolean;
|
|
28
28
|
useDevice: boolean;
|
|
29
29
|
useDeviceState: boolean;
|
|
30
|
+
preauthorized?: boolean;
|
|
30
31
|
useEmptyPassphrase: boolean;
|
|
31
32
|
allowSeedlessDevice: boolean;
|
|
32
33
|
firmwareRange: FirmwareRange;
|
package/lib/core/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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
9
|
dispose(): void;
|
|
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").setProxy | import("../api").signMessage | import("../api").signTransaction | import("../api").stellarGetAddress | import("../api").stellarSignTransaction | import("../api").tezosGetAddress | import("../api").tezosGetPublicKey | import("../api").tezosSignTransaction | import("../api").verifyMessage | import("../api").wipeDevice | import("../api").checkFirmwareAuthenticity)[];
|
|
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
|
}
|
|
13
13
|
export declare const initCore: () => Core;
|
package/lib/core/index.js
CHANGED
|
@@ -308,7 +308,7 @@ const onCall = async (message) => {
|
|
|
308
308
|
}
|
|
309
309
|
try {
|
|
310
310
|
const invalidDeviceState = method.useDeviceState
|
|
311
|
-
? await device.validateState(method.network)
|
|
311
|
+
? await device.validateState(method.network, method.preauthorized)
|
|
312
312
|
: undefined;
|
|
313
313
|
if (invalidDeviceState) {
|
|
314
314
|
if (isUsingPopup) {
|
package/lib/core/method.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import * as Methods from '../api';
|
|
|
2
2
|
import type { IFrameCallMessage } from '../events';
|
|
3
3
|
export declare const getMethod: (message: IFrameCallMessage & {
|
|
4
4
|
id?: number;
|
|
5
|
-
}) => Methods.applyFlags | Methods.applySettings | Methods.authorizeCoinJoin | Methods.backupDevice | Methods.binanceGetAddress | Methods.binanceGetPublicKey | Methods.binanceSignTransaction | Methods.blockchainDisconnect | Methods.blockchainEstimateFee | Methods.blockchainGetAccountBalanceHistory | Methods.blockchainGetCurrentFiatRates | Methods.blockchainGetFiatRatesForTimestamps | Methods.blockchainGetTransactions | Methods.blockchainSetCustomBackend | Methods.blockchainSubscribe | Methods.blockchainSubscribeFiatRates | Methods.blockchainUnsubscribe | Methods.blockchainUnsubscribeFiatRates | Methods.cardanoGetAddress | Methods.cardanoGetNativeScriptHash | Methods.cardanoGetPublicKey | Methods.cardanoSignTransaction | Methods.changePin | Methods.cipherKeyValue | Methods.composeTransaction | Methods.eosGetPublicKey | Methods.eosSignTransaction | Methods.ethereumGetAddress | Methods.ethereumGetPublicKey | Methods.ethereumSignMessage | Methods.ethereumSignTransaction | Methods.ethereumSignTypedData | Methods.ethereumVerifyMessage | Methods.firmwareUpdate | Methods.getAccountInfo | Methods.getAddress | Methods.getCoinInfo | Methods.getDeviceState | Methods.getFeatures | Methods.getFirmwareHash | Methods.getOwnershipId | Methods.getOwnershipProof | Methods.getPublicKey | Methods.getSettings | Methods.nemGetAddress | Methods.nemSignTransaction | Methods.pushTransaction | Methods.rebootToBootloader | Methods.recoveryDevice | Methods.requestLogin | Methods.resetDevice | Methods.rippleGetAddress | Methods.rippleSignTransaction | Methods.setProxy | Methods.signMessage | Methods.signTransaction | Methods.stellarGetAddress | Methods.stellarSignTransaction | Methods.tezosGetAddress | Methods.tezosGetPublicKey | Methods.tezosSignTransaction | Methods.verifyMessage | Methods.wipeDevice | Methods.checkFirmwareAuthenticity;
|
|
5
|
+
}) => Methods.applyFlags | Methods.applySettings | Methods.authorizeCoinJoin | Methods.backupDevice | Methods.binanceGetAddress | Methods.binanceGetPublicKey | Methods.binanceSignTransaction | Methods.blockchainDisconnect | Methods.blockchainEstimateFee | Methods.blockchainGetAccountBalanceHistory | Methods.blockchainGetCurrentFiatRates | Methods.blockchainGetFiatRatesForTimestamps | Methods.blockchainGetTransactions | Methods.blockchainSetCustomBackend | Methods.blockchainSubscribe | Methods.blockchainSubscribeFiatRates | Methods.blockchainUnsubscribe | Methods.blockchainUnsubscribeFiatRates | Methods.cardanoGetAddress | Methods.cardanoGetNativeScriptHash | Methods.cardanoGetPublicKey | Methods.cardanoSignTransaction | Methods.changePin | Methods.cipherKeyValue | Methods.composeTransaction | Methods.eosGetPublicKey | Methods.eosSignTransaction | Methods.ethereumGetAddress | Methods.ethereumGetPublicKey | Methods.ethereumSignMessage | Methods.ethereumSignTransaction | Methods.ethereumSignTypedData | Methods.ethereumVerifyMessage | Methods.firmwareUpdate | Methods.getAccountInfo | Methods.getAddress | Methods.getCoinInfo | Methods.getDeviceState | Methods.getFeatures | Methods.getFirmwareHash | Methods.getOwnershipId | Methods.getOwnershipProof | Methods.getPublicKey | Methods.getSettings | Methods.nemGetAddress | Methods.nemSignTransaction | Methods.pushTransaction | Methods.rebootToBootloader | Methods.recoveryDevice | Methods.requestLogin | Methods.resetDevice | Methods.rippleGetAddress | Methods.rippleSignTransaction | Methods.setBusy | Methods.setProxy | Methods.signMessage | Methods.signTransaction | Methods.stellarGetAddress | Methods.stellarSignTransaction | Methods.tezosGetAddress | Methods.tezosGetPublicKey | Methods.tezosSignTransaction | Methods.unlockPath | Methods.verifyMessage | Methods.wipeDevice | Methods.checkFirmwareAuthenticity;
|
|
6
6
|
//# sourceMappingURL=method.d.ts.map
|
package/lib/data/config.js
CHANGED
|
@@ -104,7 +104,7 @@ exports.config = {
|
|
|
104
104
|
],
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
|
-
coin: ['eth', 'trop'],
|
|
107
|
+
coin: ['eth', 'trop', 'tgor'],
|
|
108
108
|
min: ['1.8.0', '2.1.0'],
|
|
109
109
|
comment: ['There were protobuf backwards incompatible changes.'],
|
|
110
110
|
},
|
|
@@ -186,7 +186,7 @@ exports.config = {
|
|
|
186
186
|
{
|
|
187
187
|
capabilities: ['coinjoin'],
|
|
188
188
|
methods: ['authorizeCoinJoin', 'getOwnershipId', 'getOwnershipProof'],
|
|
189
|
-
min: ['0', '2.
|
|
189
|
+
min: ['0', '2.5.3'],
|
|
190
190
|
},
|
|
191
191
|
],
|
|
192
192
|
};
|
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.4';
|
|
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
|
package/lib/device/Device.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export declare class Device extends EventEmitter {
|
|
|
70
70
|
getInternalState(): string;
|
|
71
71
|
setExternalState(state?: string): void;
|
|
72
72
|
getExternalState(): string;
|
|
73
|
-
validateState(networkType?: NETWORK.NetworkType): Promise<string | undefined>;
|
|
73
|
+
validateState(networkType?: NETWORK.NetworkType, preauthorized?: boolean): Promise<string | undefined>;
|
|
74
74
|
useLegacyPassphrase(): boolean;
|
|
75
75
|
initialize(useEmptyPassphrase: boolean, useCardanoDerivation: boolean): Promise<void>;
|
|
76
76
|
getFeatures(): Promise<void>;
|
package/lib/device/Device.js
CHANGED
|
@@ -241,9 +241,14 @@ class Device extends events_1.default {
|
|
|
241
241
|
getExternalState() {
|
|
242
242
|
return this.externalState[this.instance];
|
|
243
243
|
}
|
|
244
|
-
async validateState(networkType) {
|
|
244
|
+
async validateState(networkType, preauthorized = false) {
|
|
245
245
|
if (!this.features)
|
|
246
246
|
return;
|
|
247
|
+
if (!this.features.unlocked && preauthorized) {
|
|
248
|
+
if (await this.commands.preauthorize(false)) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
247
252
|
const altMode = this._altModeChange(networkType);
|
|
248
253
|
const expectedState = altMode ? undefined : this.getExternalState();
|
|
249
254
|
const state = await this.commands.getDeviceState(networkType);
|
|
@@ -287,6 +292,7 @@ class Device extends events_1.default {
|
|
|
287
292
|
this._updateFeatures(message);
|
|
288
293
|
}
|
|
289
294
|
_updateFeatures(feat) {
|
|
295
|
+
var _a;
|
|
290
296
|
const capabilities = (0, deviceFeaturesUtils_1.parseCapabilities)(feat);
|
|
291
297
|
feat.capabilities = capabilities;
|
|
292
298
|
const version = [feat.major_version, feat.minor_version, feat.patch_version];
|
|
@@ -301,7 +307,7 @@ class Device extends events_1.default {
|
|
|
301
307
|
if (this.features && this.features.session_id && !feat.session_id) {
|
|
302
308
|
feat.session_id = this.features.session_id;
|
|
303
309
|
}
|
|
304
|
-
feat.unlocked = feat.unlocked
|
|
310
|
+
feat.unlocked = (_a = feat.unlocked) !== null && _a !== void 0 ? _a : true;
|
|
305
311
|
const revision = (0, deviceFeaturesUtils_1.parseRevision)(feat);
|
|
306
312
|
feat.revision = revision;
|
|
307
313
|
this.features = feat;
|
|
@@ -27,8 +27,13 @@ export declare class DeviceCommands {
|
|
|
27
27
|
constructor(device: Device, transport: Transport, sessionId: string);
|
|
28
28
|
dispose(): void;
|
|
29
29
|
isDisposed(): boolean;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
unlockPath(params?: Messages.UnlockPath): Promise<TypedResponseMessage<"UnlockedPathRequest">>;
|
|
31
|
+
getPublicKey(params: Messages.GetPublicKey, unlockPath?: Messages.UnlockPath): Promise<Messages.PublicKey>;
|
|
32
|
+
getHDNode(params: Messages.GetPublicKey, options?: {
|
|
33
|
+
coinInfo?: BitcoinNetworkInfo;
|
|
34
|
+
validation?: boolean;
|
|
35
|
+
unlockPath?: Messages.UnlockPath;
|
|
36
|
+
}): Promise<HDNodeResponse>;
|
|
32
37
|
getBitcoinHDNode(path: number[], coinInfo?: BitcoinNetworkInfo, validation?: boolean): Promise<HDNodeResponse>;
|
|
33
38
|
getAddress({ address_n, show_display, multisig, script_type }: Messages.GetAddress, coinInfo: BitcoinNetworkInfo): Promise<{
|
|
34
39
|
path: number[];
|
|
@@ -41,6 +46,7 @@ export declare class DeviceCommands {
|
|
|
41
46
|
address: string;
|
|
42
47
|
}>;
|
|
43
48
|
ethereumGetPublicKey({ address_n, show_display, }: Messages.EthereumGetPublicKey): Promise<HDNodeResponse>;
|
|
49
|
+
preauthorize(throwError: boolean): Promise<boolean>;
|
|
44
50
|
getDeviceState(networkType?: string): Promise<string>;
|
|
45
51
|
call(type: MessageKey, msg?: DefaultMessageResponse['message']): Promise<DefaultMessageResponse>;
|
|
46
52
|
typedCall<T extends MessageKey, R extends MessageKey[]>(type: T, resType: R, msg?: MessageType[T]): Promise<TypedCallResponseMap[R[number]]>;
|