@trezor/connect 9.5.3 → 9.5.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +38 -4
  2. package/README.md +1 -1
  3. package/lib/api/binance/api/binanceSignTransaction.js +1 -1
  4. package/lib/api/bitcoin/BitcoinFees.d.ts +4 -6
  5. package/lib/api/bitcoin/BitcoinFees.js +8 -2
  6. package/lib/api/bitcoin/signtxVerify.d.ts +1 -1
  7. package/lib/api/bitcoin/signtxVerify.js +3 -3
  8. package/lib/api/blockchainEstimateFee.js +13 -13
  9. package/lib/api/cardano/api/cardanoSignTransaction.js +1 -1
  10. package/lib/api/common/Discovery.d.ts +4 -4
  11. package/lib/api/common/Discovery.js +3 -4
  12. package/lib/api/common/MiscFees.d.ts +5 -9
  13. package/lib/api/common/MiscFees.js +6 -21
  14. package/lib/api/composeTransaction.js +4 -3
  15. package/lib/api/eos/api/eosSignTransaction.js +1 -1
  16. package/lib/api/eos/eosSignTx.d.ts +2 -2
  17. package/lib/api/ethereum/EthereumFees.d.ts +5 -8
  18. package/lib/api/ethereum/EthereumFees.js +24 -38
  19. package/lib/api/ethereum/api/ethereumGetAddress.d.ts +1 -5
  20. package/lib/api/ethereum/api/ethereumGetAddress.js +7 -8
  21. package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +11 -7
  22. package/lib/api/ethereum/api/ethereumGetPublicKey.js +12 -5
  23. package/lib/api/ethereum/api/ethereumSignTransaction.js +2 -2
  24. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +2 -4
  25. package/lib/api/ethereum/api/ethereumSignTypedData.js +1 -1
  26. package/lib/api/firmware/uploadFirmware.d.ts +2 -2
  27. package/lib/api/getAccountDescriptor.js +1 -3
  28. package/lib/api/getAccountInfo.js +4 -9
  29. package/lib/api/getAddress.js +6 -7
  30. package/lib/api/getCoinInfo.d.ts +12 -18
  31. package/lib/api/getPublicKey.d.ts +11 -7
  32. package/lib/api/resetDevice.js +1 -3
  33. package/lib/api/signTransaction.js +3 -3
  34. package/lib/api/stellar/api/stellarSignTransaction.js +1 -1
  35. package/lib/constants/errors.d.ts +1 -2
  36. package/lib/constants/errors.js +8 -3
  37. package/lib/core/index.js +36 -15
  38. package/lib/core/onCallFirmwareUpdate.js +6 -3
  39. package/lib/data/coinInfo.d.ts +44 -66
  40. package/lib/data/config.d.ts +10 -0
  41. package/lib/data/config.js +10 -0
  42. package/lib/data/deviceAuthenticityConfig.js +4 -1
  43. package/lib/data/version.d.ts +1 -1
  44. package/lib/data/version.js +1 -1
  45. package/lib/device/Device.d.ts +82 -16
  46. package/lib/device/Device.js +51 -61
  47. package/lib/device/DeviceCommands.d.ts +37 -4549
  48. package/lib/device/DeviceCommands.js +55 -264
  49. package/lib/device/DeviceCurrentSession.d.ts +4531 -0
  50. package/lib/device/DeviceCurrentSession.js +209 -0
  51. package/lib/device/DeviceList.js +4 -6
  52. package/lib/device/TransportManager.d.ts +1 -1
  53. package/lib/device/TransportManager.js +5 -4
  54. package/lib/events/ui-response.d.ts +3 -3
  55. package/lib/impl/dynamic.d.ts +4 -1
  56. package/lib/impl/dynamic.js +17 -4
  57. package/lib/tsconfig.lib.tsbuildinfo +1 -1
  58. package/lib/types/api/getPublicKey.d.ts +5 -3
  59. package/lib/types/api/getPublicKey.js +13 -12
  60. package/lib/types/coinInfo.d.ts +12 -24
  61. package/lib/types/fees.d.ts +2 -11
  62. package/lib/types/fees.js +3 -11
  63. package/lib/utils/versionCheck.js +1 -1
  64. package/package.json +9 -9
  65. package/lib/device/prompts.d.ts +0 -866
  66. package/lib/device/prompts.js +0 -60
@@ -2,80 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeviceCommands = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const protobuf_1 = require("@trezor/protobuf");
6
- const schema_utils_1 = require("@trezor/schema-utils");
7
- const utils_1 = require("@trezor/utils");
8
5
  const constants_1 = require("../constants");
9
- const resolveDescriptorForTaproot_1 = require("./resolveDescriptorForTaproot");
10
6
  const coinInfo_1 = require("../data/coinInfo");
11
- const events_1 = require("../events");
12
- const prompts_1 = require("./prompts");
7
+ const resolveDescriptorForTaproot_1 = require("../device/resolveDescriptorForTaproot");
13
8
  const accountUtils_1 = require("../utils/accountUtils");
14
- const debug_1 = require("../utils/debug");
15
9
  const hdnodeUtils = tslib_1.__importStar(require("../utils/hdnodeUtils"));
16
10
  const pathUtils_1 = require("../utils/pathUtils");
17
- const logger = (0, debug_1.initLog)('DeviceCommands');
18
- const assertType = (res, resType) => {
19
- const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
20
- if (!splitResTypes.includes(res.type)) {
21
- throw constants_1.ERRORS.TypedError('Runtime', `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
22
- }
23
- };
24
- const filterForLog = (type, msg) => {
25
- const blacklist = {
26
- PassphraseAck: {
27
- passphrase: '(redacted...)',
28
- },
29
- CipheredKeyValue: {
30
- value: '(redacted...)',
31
- },
32
- GetPublicKey: {
33
- address_n: '(redacted...)',
34
- },
35
- PublicKey: {
36
- node: '(redacted...)',
37
- xpub: '(redacted...)',
38
- },
39
- DecryptedMessage: {
40
- message: '(redacted...)',
41
- address: '(redacted...)',
42
- },
43
- Features: '(redacted...)',
44
- };
45
- if (type in blacklist) {
46
- if (typeof blacklist[type] === 'string') {
47
- return blacklist[type];
48
- }
49
- return { ...msg, ...blacklist[type] };
50
- }
51
- return msg;
52
- };
53
- class DeviceCommands {
54
- device;
55
- transport;
56
- transportSession;
57
- disposed;
58
- callPromise;
59
- constructor(device, transport, transportSession) {
60
- this.device = device;
61
- this.transport = transport;
62
- this.transportSession = transportSession;
63
- this.disposed = false;
64
- }
65
- dispose() {
66
- this.disposed = true;
67
- }
68
- isDisposed() {
69
- return this.disposed;
70
- }
71
- unlockPath(params) {
72
- return this.typedCall('UnlockPath', 'UnlockedPathRequest', params);
73
- }
74
- async getPublicKey(params, unlockPath) {
75
- if (unlockPath) {
76
- await this.unlockPath(unlockPath);
77
- }
78
- const response = await this.typedCall('GetPublicKey', 'PublicKey', {
11
+ const DeviceCommands = (deviceTypedCall) => {
12
+ const typedCall = deviceTypedCall.typedCall.bind(deviceTypedCall);
13
+ const unlockPath = (params) => typedCall('UnlockPath', 'UnlockedPathRequest', params);
14
+ const getPublicKey = async (params, unlock) => {
15
+ if (unlock) {
16
+ await unlockPath(unlock);
17
+ }
18
+ const response = await typedCall('GetPublicKey', 'PublicKey', {
79
19
  address_n: params.address_n,
80
20
  coin_name: params.coin_name || 'Bitcoin',
81
21
  script_type: params.script_type,
@@ -84,10 +24,10 @@ class DeviceCommands {
84
24
  ecdsa_curve_name: params.ecdsa_curve_name,
85
25
  });
86
26
  return response.message;
87
- }
88
- async getHDNode(params, options) {
27
+ };
28
+ const getHDNode = async (params, options) => {
89
29
  const path = params.address_n;
90
- const { coinInfo, unlockPath } = options;
30
+ const { coinInfo, unlockPath: unlock } = options;
91
31
  const validation = typeof options.validation === 'boolean' ? options.validation : true;
92
32
  let network = null;
93
33
  if (!params.script_type) {
@@ -107,13 +47,13 @@ class DeviceCommands {
107
47
  }
108
48
  let publicKey;
109
49
  if (params.show_display || !validation) {
110
- publicKey = await this.getPublicKey(params, unlockPath);
50
+ publicKey = await getPublicKey(params, unlock);
111
51
  }
112
52
  else {
113
53
  const suffix = 0;
114
54
  const childPath = path.concat([suffix]);
115
- const resKey = await this.getPublicKey(params, unlockPath);
116
- const childKey = await this.getPublicKey({ ...params, address_n: childPath }, unlockPath);
55
+ const resKey = await getPublicKey(params, unlock);
56
+ const childKey = await getPublicKey({ ...params, address_n: childPath }, unlock);
117
57
  publicKey = hdnodeUtils.xpubDerive(resKey, childKey, suffix, network, coinInfo.network);
118
58
  }
119
59
  const response = {
@@ -125,6 +65,7 @@ class DeviceCommands {
125
65
  publicKey: publicKey.node.public_key,
126
66
  fingerprint: publicKey.node.fingerprint,
127
67
  depth: publicKey.node.depth,
68
+ descriptor: publicKey.descriptor,
128
69
  };
129
70
  if (network !== coinInfo.network) {
130
71
  response.xpubSegwit = response.xpub;
@@ -139,8 +80,8 @@ class DeviceCommands {
139
80
  response.descriptorChecksum = checksum;
140
81
  }
141
82
  return response;
142
- }
143
- async getAddress({ address_n, show_display, multisig, script_type, chunkify }, coinInfo) {
83
+ };
84
+ const getAddress = async ({ address_n, show_display, multisig, script_type, chunkify }, coinInfo) => {
144
85
  if (!script_type) {
145
86
  script_type = (0, pathUtils_1.getScriptType)(address_n);
146
87
  if (script_type === 'SPENDMULTISIG' && !multisig) {
@@ -154,7 +95,7 @@ class DeviceCommands {
154
95
  }
155
96
  });
156
97
  }
157
- const response = await this.typedCall('GetAddress', 'Address', {
98
+ const response = await typedCall('GetAddress', 'Address', {
158
99
  address_n,
159
100
  coin_name: coinInfo.name,
160
101
  show_display,
@@ -162,51 +103,28 @@ class DeviceCommands {
162
103
  script_type: script_type || 'SPENDADDRESS',
163
104
  chunkify,
164
105
  });
165
- return {
166
- path: address_n,
167
- serializedPath: (0, pathUtils_1.getSerializedPath)(address_n),
168
- address: response.message.address,
169
- };
170
- }
171
- async ethereumGetAddress({ address_n, show_display, encoded_network, chunkify, }) {
172
- const response = await this.typedCall('EthereumGetAddress', 'EthereumAddress', {
173
- address_n,
174
- show_display,
175
- encoded_network,
176
- chunkify,
177
- });
178
- return {
179
- path: address_n,
180
- serializedPath: (0, pathUtils_1.getSerializedPath)(address_n),
181
- address: response.message.address,
182
- };
183
- }
184
- async ethereumGetPublicKey({ address_n, show_display, }) {
106
+ return response.message;
107
+ };
108
+ const ethereumGetAddress = async (params) => {
109
+ const response = await typedCall('EthereumGetAddress', 'EthereumAddress', params);
110
+ return response.message;
111
+ };
112
+ const ethereumGetPublicKey = async ({ address_n, show_display, }) => {
185
113
  const suffix = 0;
186
114
  const childPath = address_n.concat([suffix]);
187
- const resKey = await this.typedCall('EthereumGetPublicKey', 'EthereumPublicKey', {
115
+ const resKey = await typedCall('EthereumGetPublicKey', 'EthereumPublicKey', {
188
116
  address_n,
189
117
  show_display,
190
118
  });
191
- const childKey = await this.typedCall('EthereumGetPublicKey', 'EthereumPublicKey', {
119
+ const childKey = await typedCall('EthereumGetPublicKey', 'EthereumPublicKey', {
192
120
  address_n: childPath,
193
121
  show_display: false,
194
122
  });
195
- const publicKey = hdnodeUtils.xpubDerive(resKey.message, childKey.message, suffix);
196
- return {
197
- path: address_n,
198
- serializedPath: (0, pathUtils_1.getSerializedPath)(address_n),
199
- childNum: publicKey.node.child_num,
200
- xpub: publicKey.xpub,
201
- chainCode: publicKey.node.chain_code,
202
- publicKey: publicKey.node.public_key,
203
- fingerprint: publicKey.node.fingerprint,
204
- depth: publicKey.node.depth,
205
- };
206
- }
207
- async preauthorize(throwError) {
123
+ return hdnodeUtils.xpubDerive(resKey.message, childKey.message, suffix);
124
+ };
125
+ const preauthorize = async (throwError) => {
208
126
  try {
209
- await this.typedCall('DoPreauthorized', 'PreauthorizedRequest', {});
127
+ await typedCall('DoPreauthorized', 'PreauthorizedRequest', {});
210
128
  return true;
211
129
  }
212
130
  catch (error) {
@@ -214,123 +132,13 @@ class DeviceCommands {
214
132
  throw error;
215
133
  return false;
216
134
  }
217
- }
218
- getDeviceState() {
219
- return this._getAddress();
220
- }
221
- async call(type, msg) {
222
- logger.debug('Sending', type, filterForLog(type, msg));
223
- this.callPromise = this.transport.call({
224
- session: this.transportSession,
225
- name: type,
226
- data: msg,
227
- protocol: this.device.protocol,
228
- });
229
- const res = await this.callPromise;
230
- this.callPromise = undefined;
231
- if (!res.success) {
232
- logger.warn('Received transport error', res.error, res.message);
233
- throw new Error(res.error, { cause: 'transport-error' });
234
- }
235
- logger.debug('Received', res.payload.type, filterForLog(res.payload.type, res.payload.message));
236
- return res.payload;
237
- }
238
- async typedCall(type, resType, msg = {}) {
239
- if (this.disposed) {
240
- throw constants_1.ERRORS.TypedError('Runtime', 'typedCall: DeviceCommands already disposed');
241
- }
242
- (0, schema_utils_1.Assert)(protobuf_1.MessagesSchema.MessageType.properties[type], msg);
243
- const response = await this._commonCall(type, msg);
244
- try {
245
- assertType(response, resType);
246
- }
247
- catch (error) {
248
- const abortController = new AbortController();
249
- const timeout = setTimeout(() => {
250
- abortController.abort();
251
- }, 500);
252
- await this.transport
253
- .receive({
254
- session: this.transportSession,
255
- protocol: this.device.protocol,
256
- signal: abortController.signal,
257
- })
258
- .finally(() => {
259
- clearTimeout(timeout);
260
- });
261
- throw error;
262
- }
263
- return response;
264
- }
265
- async _commonCall(type, msg) {
266
- if (this.disposed) {
267
- throw constants_1.ERRORS.TypedError('Runtime', 'typedCall: DeviceCommands already disposed');
268
- }
269
- const resp = await this.call(type, msg);
270
- return this._filterCommonTypes(resp);
271
- }
272
- _filterCommonTypes(res) {
273
- this.device.clearCancelableAction();
274
- if (res.type === 'Failure') {
275
- const { code } = res.message;
276
- let { message } = res.message;
277
- if (code === 'Failure_FirmwareError' && !message) {
278
- message = 'Firmware installation failed';
279
- }
280
- if (code === 'Failure_ActionCancelled' && !message) {
281
- message = 'Action cancelled by user';
282
- }
283
- return Promise.reject(new constants_1.ERRORS.TrezorError(code || 'Failure_UnknownCode', message || 'Failure_UnknownMessage'));
284
- }
285
- if (res.type === 'Features') {
286
- return Promise.resolve(res);
287
- }
288
- if (res.type === 'ButtonRequest') {
289
- this.device.setCancelableAction(() => this.cancelWithFallback());
290
- if (res.message.code === 'ButtonRequest_PassphraseEntry') {
291
- this.device.emit(events_1.DEVICE.PASSPHRASE_ON_DEVICE);
292
- }
293
- else {
294
- this.device.emit(events_1.DEVICE.BUTTON, { device: this.device, payload: res.message });
295
- }
296
- return this._commonCall('ButtonAck', {});
297
- }
298
- if (res.type === 'PinMatrixRequest') {
299
- return (0, prompts_1.promptPin)(this.device, res.message.type).then(promptRes => !promptRes.success
300
- ? Promise.reject(promptRes.error)
301
- : this._commonCall('PinMatrixAck', { pin: promptRes.payload }).then(response => (this.device.features.unlocked
302
- ? Promise.resolve()
303
- :
304
- this.device.getFeatures()).then(() => response)));
305
- }
306
- if (res.type === 'PassphraseRequest') {
307
- return (0, prompts_1.promptPassphrase)(this.device).then(promptRes => !promptRes.success
308
- ? Promise.reject(promptRes.error)
309
- : this._commonCall('PassphraseAck', promptRes.payload.passphraseOnDevice
310
- ? { on_device: true }
311
- : { passphrase: promptRes.payload.value.normalize('NFKD') }));
312
- }
313
- if (res.type === 'WordRequest') {
314
- return (0, prompts_1.promptWord)(this.device, res.message.type).then(promptRes => !promptRes.success
315
- ? Promise.reject(promptRes.error)
316
- : this._commonCall('WordAck', { word: promptRes.payload }));
317
- }
318
- return Promise.resolve(res);
319
- }
320
- async _getAddress() {
321
- const { message } = await this.typedCall('GetAddress', 'Address', {
322
- address_n: [(0, pathUtils_1.toHardened)(44), (0, pathUtils_1.toHardened)(1), (0, pathUtils_1.toHardened)(0), 0, 0],
323
- coin_name: 'Testnet',
324
- script_type: 'SPENDADDRESS',
325
- });
326
- return message.address;
327
- }
328
- async getAccountDescriptor(coinInfo, indexOrPath, derivationType) {
135
+ };
136
+ const getAccountDescriptor = async (coinInfo, indexOrPath, derivationType = constants_1.PROTO.CardanoDerivationType.ICARUS_TREZOR) => {
329
137
  const address_n = Array.isArray(indexOrPath)
330
138
  ? indexOrPath
331
139
  : (0, accountUtils_1.getAccountAddressN)(coinInfo, indexOrPath);
332
140
  if (coinInfo.type === 'bitcoin') {
333
- const resp = await this.getHDNode({ address_n }, { coinInfo, validation: false });
141
+ const resp = await getHDNode({ address_n }, { coinInfo, validation: false });
334
142
  return {
335
143
  descriptor: resp.xpubSegwit || resp.xpub,
336
144
  legacyXpub: resp.xpub,
@@ -339,16 +147,16 @@ class DeviceCommands {
339
147
  };
340
148
  }
341
149
  if (coinInfo.type === 'ethereum') {
342
- const resp = await this.ethereumGetAddress({ address_n });
150
+ const { message } = await typedCall('EthereumGetAddress', 'EthereumAddress', {
151
+ address_n,
152
+ });
343
153
  return {
344
- descriptor: resp.address,
154
+ descriptor: message.address,
345
155
  address_n,
346
156
  };
347
157
  }
348
158
  if (coinInfo.shortcut === 'ADA' || coinInfo.shortcut === 'tADA') {
349
- if (typeof derivationType === 'undefined')
350
- throw new Error('Derivation type is not specified');
351
- const { message } = await this.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
159
+ const { message } = await typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
352
160
  address_n,
353
161
  derivation_type: derivationType,
354
162
  });
@@ -358,7 +166,7 @@ class DeviceCommands {
358
166
  };
359
167
  }
360
168
  if (coinInfo.shortcut === 'XRP' || coinInfo.shortcut === 'tXRP') {
361
- const { message } = await this.typedCall('RippleGetAddress', 'RippleAddress', {
169
+ const { message } = await typedCall('RippleGetAddress', 'RippleAddress', {
362
170
  address_n,
363
171
  });
364
172
  return {
@@ -367,7 +175,7 @@ class DeviceCommands {
367
175
  };
368
176
  }
369
177
  if (coinInfo.shortcut === 'SOL' || coinInfo.shortcut === 'DSOL') {
370
- const { message } = await this.typedCall('SolanaGetAddress', 'SolanaAddress', {
178
+ const { message } = await typedCall('SolanaGetAddress', 'SolanaAddress', {
371
179
  address_n,
372
180
  });
373
181
  return {
@@ -376,35 +184,18 @@ class DeviceCommands {
376
184
  };
377
185
  }
378
186
  throw constants_1.ERRORS.TypedError('Runtime', 'DeviceCommands.getAccountDescriptor: unsupported coinInfo.type');
379
- }
380
- async cancelWithFallback() {
381
- const { name, version } = this.transport;
382
- if (name === 'BridgeTransport' && !utils_1.versionUtils.isNewer(version, '2.0.28')) {
383
- try {
384
- await (0, utils_1.resolveAfter)(1);
385
- await this.device.acquire();
386
- await (0, prompts_1.cancelPrompt)(this.device, false);
387
- }
388
- catch {
389
- }
390
- }
391
- else {
392
- return (0, prompts_1.cancelPrompt)(this.device, false);
393
- }
394
- }
395
- async cancel() {
396
- if (this.disposed) {
397
- return;
398
- }
399
- this.dispose();
400
- if (this.callPromise) {
401
- try {
402
- await this.callPromise;
403
- }
404
- catch {
405
- }
406
- }
407
- }
408
- }
187
+ };
188
+ return {
189
+ unlockPath,
190
+ getPublicKey,
191
+ getAddress,
192
+ ethereumGetPublicKey,
193
+ ethereumGetAddress,
194
+ getHDNode,
195
+ preauthorize,
196
+ getAccountDescriptor,
197
+ typedCall,
198
+ };
199
+ };
409
200
  exports.DeviceCommands = DeviceCommands;
410
201
  //# sourceMappingURL=DeviceCommands.js.map