@trezor/connect 9.4.2-beta.1 → 9.4.2
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 +27 -11
- package/README.md +1 -1
- package/lib/api/cardano/cardanoInputs.d.ts +7 -7
- package/lib/api/cardano/cardanoOutputs.d.ts +22 -22
- package/lib/api/cardano/cardanoTokenBundle.d.ts +5 -5
- package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +56 -56
- package/lib/api/ethereum/ethereumDefinitions.d.ts +20 -20
- package/lib/backend/Blockchain.js +10 -3
- package/lib/constants/nem.d.ts +3 -3
- package/lib/core/index.js +24 -13
- package/lib/data/connectSettings.js +3 -0
- package/lib/data/deviceAuthenticityConfigTypes.d.ts +23 -23
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +15 -11
- package/lib/device/Device.js +19 -15
- package/lib/device/DeviceCommands.d.ts +40 -10
- package/lib/device/DeviceCommands.js +25 -90
- package/lib/device/DeviceList.d.ts +2 -2
- package/lib/device/DeviceList.js +2 -3
- package/lib/device/prompts.d.ts +15 -0
- package/lib/device/prompts.js +63 -0
- package/lib/events/ui-response.d.ts +3 -3
- package/lib/types/api/applySettings.d.ts +13 -13
- package/lib/types/api/authenticateDevice.d.ts +24 -24
- package/lib/types/api/authorizeCoinjoin.d.ts +9 -9
- package/lib/types/api/binance/index.d.ts +142 -142
- package/lib/types/api/bitcoin/index.d.ts +10 -10
- package/lib/types/api/cancelCoinjoinAuthorization.d.ts +1 -1
- package/lib/types/api/cardano/index.d.ts +507 -507
- package/lib/types/api/changeLanguage.d.ts +6 -6
- package/lib/types/api/cipherKeyValue.d.ts +7 -7
- package/lib/types/api/eos/index.d.ts +525 -525
- package/lib/types/api/ethereum/index.d.ts +100 -100
- package/lib/types/api/firmwareUpdate.d.ts +5 -5
- package/lib/types/api/getAccountDescriptor.d.ts +4 -4
- package/lib/types/api/getAddress.d.ts +32 -32
- package/lib/types/api/getOwnershipId.d.ts +24 -24
- package/lib/types/api/getOwnershipProof.d.ts +28 -28
- package/lib/types/api/getPublicKey.d.ts +23 -23
- package/lib/types/api/nem/index.d.ts +611 -611
- package/lib/types/api/nemGetAddress.d.ts +6 -6
- package/lib/types/api/pushTransaction.d.ts +3 -3
- package/lib/types/api/recoveryDevice.d.ts +9 -9
- package/lib/types/api/requestLogin.d.ts +25 -25
- package/lib/types/api/ripple/index.d.ts +21 -21
- package/lib/types/api/solana/index.d.ts +23 -23
- package/lib/types/api/stellar/index.d.ts +581 -581
- package/lib/types/api/tezos/index.d.ts +120 -120
- package/lib/types/api/unlockPath.d.ts +2 -2
- package/lib/types/coinInfo.d.ts +224 -224
- package/lib/types/fees.d.ts +19 -19
- package/lib/types/firmware.d.ts +1 -1
- package/lib/types/params.d.ts +14 -14
- package/lib/types/settings.d.ts +4 -0
- package/package.json +4 -4
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.CONTENT_SCRIPT_VERSION = exports.DEFAULT_DOMAIN = exports.VERSION = void 0;
|
|
4
|
-
exports.VERSION = '9.4.2
|
|
4
|
+
exports.VERSION = '9.4.2';
|
|
5
5
|
const versionN = exports.VERSION.split('.').map(s => parseInt(s, 10));
|
|
6
6
|
const isBeta = exports.VERSION.includes('beta');
|
|
7
7
|
exports.DEFAULT_DOMAIN = isBeta
|
package/lib/device/Device.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Deferred, TypedEmitter } from '@trezor/utils';
|
|
2
|
+
import { Session } from '@trezor/transport';
|
|
2
3
|
import { TransportProtocol } from '@trezor/protocol';
|
|
3
|
-
import { DeviceCommands
|
|
4
|
+
import { DeviceCommands } from './DeviceCommands';
|
|
4
5
|
import { PROTO, NETWORK } from '../constants';
|
|
5
|
-
import { DEVICE, DeviceButtonRequestPayload } from '../events';
|
|
6
|
+
import { DEVICE, DeviceButtonRequestPayload, UiResponsePin, UiResponsePassphrase, UiResponseWord } from '../events';
|
|
6
7
|
import { type Transport, type Descriptor } from '@trezor/transport';
|
|
7
8
|
import { Device as DeviceTyped, DeviceFirmwareStatus, DeviceState, Features, ReleaseInfo, UnavailableCapabilities, FirmwareType, VersionArray, KnownDevice } from '../types';
|
|
8
9
|
import { IStateStorage } from './StateStorage';
|
|
10
|
+
import type { PromptCallback } from './prompts';
|
|
9
11
|
export type RunOptions = {
|
|
10
12
|
skipFinalReload?: boolean;
|
|
11
13
|
waiting?: boolean;
|
|
@@ -17,9 +19,9 @@ export type RunOptions = {
|
|
|
17
19
|
export declare const GET_FEATURES_TIMEOUT = 3000;
|
|
18
20
|
export declare const GET_FEATURES_TIMEOUT_REACT_NATIVE = 20000;
|
|
19
21
|
export interface DeviceEvents {
|
|
20
|
-
[DEVICE.PIN]: (device: Device,
|
|
21
|
-
[DEVICE.WORD]: (device: Device,
|
|
22
|
-
[DEVICE.PASSPHRASE]: (device: Device, callback:
|
|
22
|
+
[DEVICE.PIN]: (device: Device, type: PROTO.PinMatrixRequestType | undefined, callback: PromptCallback<UiResponsePin['payload']>) => void;
|
|
23
|
+
[DEVICE.WORD]: (device: Device, type: PROTO.WordRequestType, callback: PromptCallback<UiResponseWord['payload']>) => void;
|
|
24
|
+
[DEVICE.PASSPHRASE]: (device: Device, callback: PromptCallback<UiResponsePassphrase['payload']>) => void;
|
|
23
25
|
[DEVICE.PASSPHRASE_ON_DEVICE]: () => void;
|
|
24
26
|
[DEVICE.BUTTON]: (device: Device, payload: DeviceButtonRequestPayload) => void;
|
|
25
27
|
[DEVICE.ACQUIRED]: () => void;
|
|
@@ -36,9 +38,10 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
36
38
|
private acquirePromise?;
|
|
37
39
|
private releasePromise?;
|
|
38
40
|
private runPromise?;
|
|
39
|
-
|
|
41
|
+
transportSession?: Session | null;
|
|
40
42
|
keepTransportSession: boolean;
|
|
41
43
|
commands?: DeviceCommands;
|
|
44
|
+
private cancelableAction?;
|
|
42
45
|
loaded: boolean;
|
|
43
46
|
inconsistent: boolean;
|
|
44
47
|
firstRunPromise: Deferred<boolean>;
|
|
@@ -61,6 +64,8 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
61
64
|
cleanup(): Promise<void>;
|
|
62
65
|
run(fn?: () => Promise<void>, options?: RunOptions): Promise<void>;
|
|
63
66
|
override(error: Error): Promise<void>;
|
|
67
|
+
setCancelableAction(callback: NonNullable<typeof this.cancelableAction>): void;
|
|
68
|
+
clearCancelableAction(): void;
|
|
64
69
|
interruptionFromUser(error: Error): Promise<void>;
|
|
65
70
|
interruptionFromOutside(): void;
|
|
66
71
|
_runInner<X>(fn: (() => Promise<X>) | undefined, options: RunOptions): Promise<void>;
|
|
@@ -86,7 +91,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
86
91
|
private _uploadTranslationData;
|
|
87
92
|
private _updateFeatures;
|
|
88
93
|
isUnacquired(): boolean;
|
|
89
|
-
disconnect(): void
|
|
94
|
+
disconnect(): Promise<void>;
|
|
90
95
|
isBootloader(): boolean;
|
|
91
96
|
isInitialized(): boolean;
|
|
92
97
|
isSeedless(): boolean;
|
|
@@ -104,6 +109,9 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
104
109
|
hasUnexpectedMode(allow: string[], require: string[]): "ui-device_bootloader_mode" | "ui-device_not_in_bootloader_mode" | "ui-device_not_initialized" | "ui-device_seedless" | null;
|
|
105
110
|
updateDescriptor(descriptor: Descriptor): void;
|
|
106
111
|
dispose(): Promise<{
|
|
112
|
+
success: false;
|
|
113
|
+
error: "session not found";
|
|
114
|
+
} | {
|
|
107
115
|
success: false;
|
|
108
116
|
error: "Network request failed";
|
|
109
117
|
} | {
|
|
@@ -115,9 +123,6 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
115
123
|
} | {
|
|
116
124
|
success: false;
|
|
117
125
|
error: "unexpected error";
|
|
118
|
-
} | {
|
|
119
|
-
success: false;
|
|
120
|
-
error: "session not found";
|
|
121
126
|
} | {
|
|
122
127
|
success: false;
|
|
123
128
|
error: "Aborted by timeout";
|
|
@@ -139,6 +144,5 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
139
144
|
} | import("@trezor/transport/lib/types").Success<void> | undefined>;
|
|
140
145
|
getMode(): "normal" | "bootloader" | "initialize" | "seedless";
|
|
141
146
|
toMessageObject(): DeviceTyped;
|
|
142
|
-
legacyForceRelease(): Promise<void>;
|
|
143
147
|
}
|
|
144
148
|
//# sourceMappingURL=Device.d.ts.map
|
package/lib/device/Device.js
CHANGED
|
@@ -142,15 +142,27 @@ class Device extends utils_1.TypedEmitter {
|
|
|
142
142
|
await this.releasePromise;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
+
setCancelableAction(callback) {
|
|
146
|
+
this.cancelableAction = (e) => callback(e)
|
|
147
|
+
.catch(e => {
|
|
148
|
+
_log.debug('cancelableAction error', e);
|
|
149
|
+
})
|
|
150
|
+
.finally(() => {
|
|
151
|
+
this.clearCancelableAction();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
clearCancelableAction() {
|
|
155
|
+
this.cancelableAction = undefined;
|
|
156
|
+
}
|
|
145
157
|
async interruptionFromUser(error) {
|
|
158
|
+
var _a, _b;
|
|
146
159
|
_log.debug('interruptionFromUser');
|
|
160
|
+
await ((_a = this.cancelableAction) === null || _a === void 0 ? void 0 : _a.call(this, error));
|
|
161
|
+
await ((_b = this.commands) === null || _b === void 0 ? void 0 : _b.cancel());
|
|
147
162
|
if (this.runPromise) {
|
|
148
163
|
this.runPromise.reject(error);
|
|
149
164
|
delete this.runPromise;
|
|
150
165
|
}
|
|
151
|
-
if (this.commands) {
|
|
152
|
-
await this.commands.cancel();
|
|
153
|
-
}
|
|
154
166
|
}
|
|
155
167
|
interruptionFromOutside() {
|
|
156
168
|
_log.debug('interruptionFromOutside');
|
|
@@ -448,8 +460,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
448
460
|
disconnect() {
|
|
449
461
|
_log.debug('Disconnect cleanup');
|
|
450
462
|
this.transportSession = null;
|
|
451
|
-
this.interruptionFromUser(constants_1.ERRORS.TypedError('Device_Disconnected'));
|
|
452
|
-
delete this.runPromise;
|
|
463
|
+
return this.interruptionFromUser(constants_1.ERRORS.TypedError('Device_Disconnected'));
|
|
453
464
|
}
|
|
454
465
|
isBootloader() {
|
|
455
466
|
return this.features && !!this.features.bootloader_mode;
|
|
@@ -529,12 +540,12 @@ class Device extends utils_1.TypedEmitter {
|
|
|
529
540
|
};
|
|
530
541
|
}
|
|
531
542
|
async dispose() {
|
|
543
|
+
var _a, _b;
|
|
532
544
|
this.removeAllListeners();
|
|
533
545
|
if (this.isUsedHere() && this.transportSession) {
|
|
534
546
|
try {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
547
|
+
await ((_a = this.cancelableAction) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
548
|
+
await ((_b = this.commands) === null || _b === void 0 ? void 0 : _b.cancel());
|
|
538
549
|
return this.transport.release({
|
|
539
550
|
session: this.transportSession,
|
|
540
551
|
path: this.originalDescriptor.path,
|
|
@@ -598,13 +609,6 @@ class Device extends utils_1.TypedEmitter {
|
|
|
598
609
|
authenticityChecks: this.authenticityChecks,
|
|
599
610
|
};
|
|
600
611
|
}
|
|
601
|
-
async legacyForceRelease() {
|
|
602
|
-
if (this.isUsedHere()) {
|
|
603
|
-
await this.acquire();
|
|
604
|
-
await this.getFeatures();
|
|
605
|
-
await this.release();
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
612
|
}
|
|
609
613
|
exports.Device = Device;
|
|
610
614
|
//# sourceMappingURL=Device.js.map
|
|
@@ -13,19 +13,12 @@ type TypedCallResponseMap = {
|
|
|
13
13
|
[K in keyof MessageType]: TypedPayload<K>;
|
|
14
14
|
};
|
|
15
15
|
type DefaultPayloadMessage = TypedCallResponseMap[keyof MessageType];
|
|
16
|
-
export type PassphrasePromptResponse = {
|
|
17
|
-
passphrase?: string;
|
|
18
|
-
passphraseOnDevice?: boolean;
|
|
19
|
-
cache?: boolean;
|
|
20
|
-
};
|
|
21
16
|
export declare class DeviceCommands {
|
|
22
17
|
device: Device;
|
|
23
18
|
transport: Transport;
|
|
24
19
|
transportSession: Session;
|
|
25
20
|
disposed: boolean;
|
|
26
21
|
callPromise?: ReturnType<Transport['call']>;
|
|
27
|
-
_cancelableRequest?: (error?: any) => void;
|
|
28
|
-
_cancelableRequestBySend?: boolean;
|
|
29
22
|
constructor(device: Device, transport: Transport, transportSession: Session);
|
|
30
23
|
dispose(): void;
|
|
31
24
|
isDisposed(): boolean;
|
|
@@ -78,15 +71,52 @@ export declare class DeviceCommands {
|
|
|
78
71
|
_commonCall(type: MessageKey, msg?: DefaultPayloadMessage['message']): Promise<DefaultPayloadMessage>;
|
|
79
72
|
_filterCommonTypes(res: DefaultPayloadMessage): Promise<DefaultPayloadMessage>;
|
|
80
73
|
private _getAddress;
|
|
81
|
-
_promptPin(type?: Messages.PinMatrixRequestType): Promise<string>;
|
|
82
|
-
_promptPassphrase(): Promise<PassphrasePromptResponse>;
|
|
83
|
-
_promptWord(type: Messages.WordRequestType): Promise<string>;
|
|
84
74
|
getAccountDescriptor(coinInfo: CoinInfo, indexOrPath: number | number[], derivationType?: Messages.CardanoDerivationType): Promise<{
|
|
85
75
|
descriptor: string;
|
|
86
76
|
legacyXpub?: string;
|
|
87
77
|
address_n: number[];
|
|
88
78
|
descriptorChecksum?: string;
|
|
89
79
|
}>;
|
|
80
|
+
cancelWithFallback(): Promise<{
|
|
81
|
+
readonly success: false;
|
|
82
|
+
readonly error: "session not found";
|
|
83
|
+
} | import("@trezor/transport/lib/types").Success<import("@trezor/protobuf").MessageFromTrezor> | {
|
|
84
|
+
success: false;
|
|
85
|
+
error: "Network request failed";
|
|
86
|
+
} | {
|
|
87
|
+
success: false;
|
|
88
|
+
error: "Wrong result type.";
|
|
89
|
+
} | {
|
|
90
|
+
success: false;
|
|
91
|
+
error: "other call in progress";
|
|
92
|
+
} | {
|
|
93
|
+
success: false;
|
|
94
|
+
error: "Malformed protocol format";
|
|
95
|
+
} | {
|
|
96
|
+
success: false;
|
|
97
|
+
error: "device disconnected during action";
|
|
98
|
+
} | {
|
|
99
|
+
success: false;
|
|
100
|
+
error: "unexpected error";
|
|
101
|
+
} | {
|
|
102
|
+
success: false;
|
|
103
|
+
error: "Aborted by timeout";
|
|
104
|
+
} | {
|
|
105
|
+
success: false;
|
|
106
|
+
error: "Aborted by signal";
|
|
107
|
+
} | {
|
|
108
|
+
success: false;
|
|
109
|
+
error: "This transport can not be used in this environment";
|
|
110
|
+
} | {
|
|
111
|
+
success: false;
|
|
112
|
+
error: "device not found";
|
|
113
|
+
} | {
|
|
114
|
+
success: false;
|
|
115
|
+
error: "Unable to open device";
|
|
116
|
+
} | {
|
|
117
|
+
success: false;
|
|
118
|
+
error: "A transfer error has occurred.";
|
|
119
|
+
} | import("@trezor/transport/lib/types").Success<undefined> | undefined>;
|
|
90
120
|
cancel(): Promise<void>;
|
|
91
121
|
}
|
|
92
122
|
export type TypedCall = DeviceCommands['typedCall'];
|
|
@@ -14,6 +14,7 @@ const coinInfo_1 = require("../data/coinInfo");
|
|
|
14
14
|
const debug_1 = require("../utils/debug");
|
|
15
15
|
const schema_utils_1 = require("@trezor/schema-utils");
|
|
16
16
|
const resolveDescriptorForTaproot_1 = require("./resolveDescriptorForTaproot");
|
|
17
|
+
const prompts_1 = require("./prompts");
|
|
17
18
|
const logger = (0, debug_1.initLog)('DeviceCommands');
|
|
18
19
|
const assertType = (res, resType) => {
|
|
19
20
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
@@ -45,7 +46,6 @@ class DeviceCommands {
|
|
|
45
46
|
}
|
|
46
47
|
dispose() {
|
|
47
48
|
this.disposed = true;
|
|
48
|
-
this._cancelableRequest = undefined;
|
|
49
49
|
}
|
|
50
50
|
isDisposed() {
|
|
51
51
|
return this.disposed;
|
|
@@ -243,7 +243,7 @@ class DeviceCommands {
|
|
|
243
243
|
return this._filterCommonTypes(resp);
|
|
244
244
|
}
|
|
245
245
|
_filterCommonTypes(res) {
|
|
246
|
-
this.
|
|
246
|
+
this.device.clearCancelableAction();
|
|
247
247
|
if (res.type === 'Failure') {
|
|
248
248
|
const { code } = res.message;
|
|
249
249
|
let { message } = res.message;
|
|
@@ -259,7 +259,7 @@ class DeviceCommands {
|
|
|
259
259
|
return Promise.resolve(res);
|
|
260
260
|
}
|
|
261
261
|
if (res.type === 'ButtonRequest') {
|
|
262
|
-
this.
|
|
262
|
+
this.device.setCancelableAction(() => this.cancelWithFallback());
|
|
263
263
|
if (res.message.code === 'ButtonRequest_PassphraseEntry') {
|
|
264
264
|
this.device.emit(events_1.DEVICE.PASSPHRASE_ON_DEVICE);
|
|
265
265
|
}
|
|
@@ -274,25 +274,22 @@ class DeviceCommands {
|
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
276
|
if (res.type === 'PinMatrixRequest') {
|
|
277
|
-
return this.
|
|
277
|
+
return (0, prompts_1.promptPin)(this.device, res.message.type).then(pin => this._commonCall('PinMatrixAck', { pin }).then(response => {
|
|
278
278
|
if (!this.device.features.unlocked) {
|
|
279
279
|
return this.device.getFeatures().then(() => response);
|
|
280
280
|
}
|
|
281
281
|
return response;
|
|
282
|
-
}),
|
|
282
|
+
}), error => Promise.reject(error));
|
|
283
283
|
}
|
|
284
284
|
if (res.type === 'PassphraseRequest') {
|
|
285
|
-
return this.
|
|
286
|
-
const { passphrase, passphraseOnDevice } = response;
|
|
285
|
+
return (0, prompts_1.promptPassphrase)(this.device).then(({ value, passphraseOnDevice }) => {
|
|
287
286
|
return !passphraseOnDevice
|
|
288
|
-
? this._commonCall('PassphraseAck', { passphrase })
|
|
287
|
+
? this._commonCall('PassphraseAck', { passphrase: value.normalize('NFKD') })
|
|
289
288
|
: this._commonCall('PassphraseAck', { on_device: true });
|
|
290
|
-
},
|
|
291
|
-
throw err || e;
|
|
292
|
-
}));
|
|
289
|
+
}, error => Promise.reject(error));
|
|
293
290
|
}
|
|
294
291
|
if (res.type === 'WordRequest') {
|
|
295
|
-
return this.
|
|
292
|
+
return (0, prompts_1.promptWord)(this.device, res.message.type).then(word => this._commonCall('WordAck', { word }), error => Promise.reject(error));
|
|
296
293
|
}
|
|
297
294
|
return Promise.resolve(res);
|
|
298
295
|
}
|
|
@@ -304,60 +301,6 @@ class DeviceCommands {
|
|
|
304
301
|
});
|
|
305
302
|
return message.address;
|
|
306
303
|
}
|
|
307
|
-
_promptPin(type) {
|
|
308
|
-
return new Promise((resolve, reject) => {
|
|
309
|
-
if (this.device.listenerCount(events_1.DEVICE.PIN) > 0) {
|
|
310
|
-
this._cancelableRequest = reject;
|
|
311
|
-
this.device.emit(events_1.DEVICE.PIN, this.device, type, (err, pin) => {
|
|
312
|
-
this._cancelableRequest = undefined;
|
|
313
|
-
if (err || pin == null) {
|
|
314
|
-
reject(err);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
resolve(pin);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
console.warn('[DeviceCommands] [call] PIN callback not configured, cancelling request');
|
|
323
|
-
reject(constants_1.ERRORS.TypedError('Runtime', '_promptPin: PIN callback not configured'));
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
_promptPassphrase() {
|
|
328
|
-
return new Promise((resolve, reject) => {
|
|
329
|
-
if (this.device.listenerCount(events_1.DEVICE.PASSPHRASE) > 0) {
|
|
330
|
-
this._cancelableRequest = reject;
|
|
331
|
-
this.device.emit(events_1.DEVICE.PASSPHRASE, this.device, (response, error) => {
|
|
332
|
-
this._cancelableRequest = undefined;
|
|
333
|
-
if (error) {
|
|
334
|
-
reject(error);
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
resolve(response);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
console.warn('[DeviceCommands] [call] Passphrase callback not configured, cancelling request');
|
|
343
|
-
reject(constants_1.ERRORS.TypedError('Runtime', '_promptPassphrase: Passphrase callback not configured'));
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
_promptWord(type) {
|
|
348
|
-
return new Promise((resolve, reject) => {
|
|
349
|
-
this._cancelableRequest = reject;
|
|
350
|
-
this.device.emit(events_1.DEVICE.WORD, this.device, type, (err, word) => {
|
|
351
|
-
this._cancelableRequest = undefined;
|
|
352
|
-
if (err || word == null) {
|
|
353
|
-
reject(err);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
resolve(word.toLocaleLowerCase());
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
304
|
async getAccountDescriptor(coinInfo, indexOrPath, derivationType) {
|
|
362
305
|
const address_n = Array.isArray(indexOrPath)
|
|
363
306
|
? indexOrPath
|
|
@@ -410,40 +353,32 @@ class DeviceCommands {
|
|
|
410
353
|
}
|
|
411
354
|
throw constants_1.ERRORS.TypedError('Runtime', 'DeviceCommands.getAccountDescriptor: unsupported coinInfo.type');
|
|
412
355
|
}
|
|
413
|
-
async
|
|
414
|
-
if (this._cancelableRequest) {
|
|
415
|
-
this._cancelableRequest();
|
|
416
|
-
this._cancelableRequest = undefined;
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
if (this.disposed) {
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
this.dispose();
|
|
423
|
-
if (!this._cancelableRequestBySend) {
|
|
424
|
-
if (this.callPromise) {
|
|
425
|
-
await this.callPromise;
|
|
426
|
-
}
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
356
|
+
async cancelWithFallback() {
|
|
429
357
|
const { name, version } = this.transport;
|
|
430
358
|
if (name === 'BridgeTransport' && !utils_1.versionUtils.isNewer(version, '2.0.28')) {
|
|
431
359
|
try {
|
|
432
|
-
await
|
|
360
|
+
await (0, utils_1.createTimeoutPromise)(1);
|
|
361
|
+
await this.device.acquire();
|
|
362
|
+
await (0, prompts_1.cancelPrompt)(this.device, false);
|
|
433
363
|
}
|
|
434
364
|
catch (err) {
|
|
435
365
|
}
|
|
436
366
|
}
|
|
437
367
|
else {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
368
|
+
return (0, prompts_1.cancelPrompt)(this.device, false);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async cancel() {
|
|
372
|
+
if (this.disposed) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.dispose();
|
|
376
|
+
if (this.callPromise) {
|
|
377
|
+
try {
|
|
445
378
|
await this.callPromise;
|
|
446
379
|
}
|
|
380
|
+
catch {
|
|
381
|
+
}
|
|
447
382
|
}
|
|
448
383
|
}
|
|
449
384
|
}
|
|
@@ -25,7 +25,7 @@ export interface IDeviceList {
|
|
|
25
25
|
dispose: DeviceList['dispose'];
|
|
26
26
|
}
|
|
27
27
|
export declare const assertDeviceListConnected: (deviceList: IDeviceList) => asserts deviceList is DeviceList;
|
|
28
|
-
type ConstructorParams = Pick<ConnectSettings, 'priority' | 'debug'> & {
|
|
28
|
+
type ConstructorParams = Pick<ConnectSettings, 'priority' | 'debug' | '_sessionsBackgroundUrl'> & {
|
|
29
29
|
messages: Record<string, any>;
|
|
30
30
|
};
|
|
31
31
|
type InitParams = Pick<ConnectSettings, 'pendingTransportEvent' | 'transportReconnect'>;
|
|
@@ -41,7 +41,7 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> implement
|
|
|
41
41
|
private transportCommonArgs;
|
|
42
42
|
isConnected(): this is DeviceList;
|
|
43
43
|
pendingConnection(): Promise<void> | undefined;
|
|
44
|
-
constructor({ messages, priority, debug }: ConstructorParams);
|
|
44
|
+
constructor({ messages, priority, debug, _sessionsBackgroundUrl }: ConstructorParams);
|
|
45
45
|
private createTransport;
|
|
46
46
|
setTransports(transports: ConnectSettings['transports']): void;
|
|
47
47
|
private onTransportUpdate;
|
package/lib/device/DeviceList.js
CHANGED
|
@@ -42,18 +42,17 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
42
42
|
pendingConnection() {
|
|
43
43
|
return this.initPromise;
|
|
44
44
|
}
|
|
45
|
-
constructor({ messages, priority, debug }) {
|
|
45
|
+
constructor({ messages, priority, debug, _sessionsBackgroundUrl }) {
|
|
46
46
|
super();
|
|
47
47
|
this.devices = {};
|
|
48
48
|
this.creatingDevicesDescriptors = {};
|
|
49
49
|
this.createDevicesQueue = [];
|
|
50
50
|
const transportLogger = (0, debug_1.initLog)('@trezor/transport', debug);
|
|
51
|
-
const abortController = new AbortController();
|
|
52
51
|
this.authPenaltyManager = createAuthPenaltyManager(priority);
|
|
53
52
|
this.transportCommonArgs = {
|
|
54
53
|
messages,
|
|
55
54
|
logger: transportLogger,
|
|
56
|
-
|
|
55
|
+
sessionsBackgroundUrl: _sessionsBackgroundUrl,
|
|
57
56
|
};
|
|
58
57
|
this.transports = [
|
|
59
58
|
new transport_1.BridgeTransport({
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Messages } from '@trezor/transport';
|
|
2
|
+
import type { Device } from './Device';
|
|
3
|
+
export type PromptCallback<T> = (response: T | null, error?: Error) => void;
|
|
4
|
+
export declare const cancelPrompt: (device: Device, expectResponse?: boolean) => Promise<{
|
|
5
|
+
readonly success: false;
|
|
6
|
+
readonly error: "session not found";
|
|
7
|
+
}> | import("@trezor/transport/lib/types").AsyncResultWithTypedError<import("@trezor/protobuf").MessageFromTrezor, "session not found" | "Network request failed" | "Wrong result type." | "other call in progress" | "Malformed protocol format" | "device disconnected during action" | "unexpected error" | "Aborted by timeout" | "Aborted by signal" | "This transport can not be used in this environment" | "device not found" | "Unable to open device" | "A transfer error has occurred."> | import("@trezor/transport/lib/types").AsyncResultWithTypedError<undefined, "session not found" | "Network request failed" | "Wrong result type." | "other call in progress" | "Malformed protocol format" | "device disconnected during action" | "unexpected error" | "Aborted by timeout" | "Aborted by signal" | "This transport can not be used in this environment" | "device not found" | "Unable to open device" | "A transfer error has occurred.">;
|
|
8
|
+
export declare const promptPassphrase: (device: Device) => Promise<{
|
|
9
|
+
value: string;
|
|
10
|
+
passphraseOnDevice?: boolean;
|
|
11
|
+
save?: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const promptPin: (device: Device, type?: Messages.PinMatrixRequestType) => Promise<string>;
|
|
14
|
+
export declare const promptWord: (device: Device, type: Messages.WordRequestType) => Promise<string>;
|
|
15
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptWord = exports.promptPin = exports.promptPassphrase = exports.cancelPrompt = void 0;
|
|
4
|
+
const transport_1 = require("@trezor/transport");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const events_1 = require("../events");
|
|
7
|
+
const cancelPrompt = (device, expectResponse = true) => {
|
|
8
|
+
if (!device.transportSession) {
|
|
9
|
+
return Promise.resolve({
|
|
10
|
+
success: false,
|
|
11
|
+
error: transport_1.TRANSPORT_ERROR.SESSION_NOT_FOUND,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const cancelArgs = {
|
|
15
|
+
session: device.transportSession,
|
|
16
|
+
name: 'Cancel',
|
|
17
|
+
data: {},
|
|
18
|
+
protocol: device.protocol,
|
|
19
|
+
};
|
|
20
|
+
return expectResponse ? device.transport.call(cancelArgs) : device.transport.send(cancelArgs);
|
|
21
|
+
};
|
|
22
|
+
exports.cancelPrompt = cancelPrompt;
|
|
23
|
+
const prompt = (event, ...[device, ...args]) => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const cancelAndReject = (error) => (0, exports.cancelPrompt)(device).then(onCancel => {
|
|
26
|
+
var _a;
|
|
27
|
+
return reject(error ||
|
|
28
|
+
new Error(onCancel.success
|
|
29
|
+
? (_a = onCancel.payload) === null || _a === void 0 ? void 0 : _a.message.message
|
|
30
|
+
: onCancel.error));
|
|
31
|
+
});
|
|
32
|
+
if (device.listenerCount(event) > 0) {
|
|
33
|
+
device.setCancelableAction(cancelAndReject);
|
|
34
|
+
const callback = (...[response, error]) => {
|
|
35
|
+
device.clearCancelableAction();
|
|
36
|
+
if (error || response == null) {
|
|
37
|
+
cancelAndReject(error);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
resolve(response);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const emitArgs = [event, device, ...args, callback];
|
|
44
|
+
device.emit(...emitArgs);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
cancelAndReject(constants_1.ERRORS.TypedError('Runtime', `${event} callback not configured`));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const promptPassphrase = (device) => {
|
|
52
|
+
return prompt(events_1.DEVICE.PASSPHRASE, device);
|
|
53
|
+
};
|
|
54
|
+
exports.promptPassphrase = promptPassphrase;
|
|
55
|
+
const promptPin = (device, type) => {
|
|
56
|
+
return prompt(events_1.DEVICE.PIN, device, type);
|
|
57
|
+
};
|
|
58
|
+
exports.promptPin = promptPin;
|
|
59
|
+
const promptWord = (device, type) => {
|
|
60
|
+
return prompt(events_1.DEVICE.WORD, device, type);
|
|
61
|
+
};
|
|
62
|
+
exports.promptWord = promptWord;
|
|
63
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -39,11 +39,11 @@ export interface UiResponseDevice {
|
|
|
39
39
|
}
|
|
40
40
|
export interface UiResponsePin {
|
|
41
41
|
type: typeof UI_RESPONSE.RECEIVE_PIN;
|
|
42
|
-
payload: string;
|
|
42
|
+
payload: string | undefined;
|
|
43
43
|
}
|
|
44
44
|
export interface UiResponseWord {
|
|
45
45
|
type: typeof UI_RESPONSE.RECEIVE_WORD;
|
|
46
|
-
payload: string;
|
|
46
|
+
payload: string | undefined;
|
|
47
47
|
}
|
|
48
48
|
export interface UiResponsePassphrase {
|
|
49
49
|
type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;
|
|
@@ -51,7 +51,7 @@ export interface UiResponsePassphrase {
|
|
|
51
51
|
value: string;
|
|
52
52
|
passphraseOnDevice?: boolean;
|
|
53
53
|
save?: boolean;
|
|
54
|
-
};
|
|
54
|
+
} | undefined;
|
|
55
55
|
}
|
|
56
56
|
export interface UiResponsePassphraseAction {
|
|
57
57
|
type: typeof UI_RESPONSE.INVALID_PASSPHRASE_ACTION;
|
|
@@ -3,19 +3,19 @@ import { PROTO } from '../../constants';
|
|
|
3
3
|
import type { Params, Response } from '../params';
|
|
4
4
|
export type ApplySettings = Static<typeof ApplySettings>;
|
|
5
5
|
export declare const ApplySettings: import("@trezor/schema-utils").TObject<{
|
|
6
|
-
language: import("@sinclair/typebox
|
|
7
|
-
label: import("@sinclair/typebox
|
|
8
|
-
passphrase_always_on_device: import("@sinclair/typebox
|
|
9
|
-
safety_checks: import("@sinclair/typebox
|
|
10
|
-
auto_lock_delay_ms: import("@sinclair/typebox
|
|
11
|
-
display_rotation: import("@sinclair/typebox
|
|
12
|
-
experimental_features: import("@sinclair/typebox
|
|
13
|
-
hide_passphrase_from_host: import("@sinclair/typebox
|
|
14
|
-
haptic_feedback: import("@sinclair/typebox
|
|
15
|
-
use_passphrase: import("@sinclair/typebox
|
|
16
|
-
homescreen: import("@sinclair/typebox
|
|
17
|
-
_passphrase_source: import("@sinclair/typebox
|
|
18
|
-
passphrase_source: import("@sinclair/typebox
|
|
6
|
+
language: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
|
+
label: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
8
|
+
passphrase_always_on_device: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
9
|
+
safety_checks: import("@sinclair/typebox").TOptional<import("@trezor/schema-utils/lib/custom-types/keyof-enum").TKeyOfEnum<typeof PROTO.Enum_SafetyCheckLevel>>;
|
|
10
|
+
auto_lock_delay_ms: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
11
|
+
display_rotation: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
12
|
+
experimental_features: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
13
|
+
hide_passphrase_from_host: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
14
|
+
haptic_feedback: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
15
|
+
use_passphrase: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
16
|
+
homescreen: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
17
|
+
_passphrase_source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
18
|
+
passphrase_source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
19
19
|
}>;
|
|
20
20
|
export declare function applySettings(params: Params<ApplySettings>): Response<PROTO.Success>;
|
|
21
21
|
//# sourceMappingURL=applySettings.d.ts.map
|