@trezor/connect 9.4.7-beta.1 → 9.4.8-beta.1
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 +56 -9
- package/README.md +1 -1
- package/lib/api/applyFlags.d.ts +1 -1
- package/lib/api/applyFlags.js +1 -1
- package/lib/api/applySettings.d.ts +1 -1
- package/lib/api/authenticateDevice.js +1 -1
- package/lib/api/authorizeCoinjoin.d.ts +1 -1
- package/lib/api/authorizeCoinjoin.js +1 -1
- package/lib/api/backupDevice.d.ts +1 -1
- package/lib/api/backupDevice.js +1 -1
- package/lib/api/binance/api/binanceGetAddress.d.ts +1 -1
- package/lib/api/binance/api/binanceGetAddress.js +3 -3
- package/lib/api/binance/api/binanceGetPublicKey.d.ts +1 -1
- package/lib/api/binance/api/binanceGetPublicKey.js +2 -2
- package/lib/api/binance/api/binanceSignTransaction.js +2 -2
- package/lib/api/binance/binanceSignTx.d.ts +1 -1
- package/lib/api/bitcoin/TransactionComposer.d.ts +1 -1
- package/lib/api/bitcoin/inputs.d.ts +1 -1
- package/lib/api/bitcoin/inputs.js +1 -1
- package/lib/api/bitcoin/outputs.js +2 -2
- package/lib/api/bitcoin/refTx.d.ts +2 -2
- package/lib/api/bitcoin/refTx.js +4 -4
- package/lib/api/bitcoin/signtx.d.ts +2 -2
- package/lib/api/bitcoin/signtxLegacy.d.ts +1 -1
- package/lib/api/bitcoin/signtxVerify.d.ts +1 -1
- package/lib/api/blockchainDisconnect.js +2 -2
- package/lib/api/blockchainEstimateFee.d.ts +1 -1
- package/lib/api/blockchainEstimateFee.js +3 -2
- package/lib/api/blockchainEvmRpcCall.js +2 -2
- package/lib/api/blockchainGetAccountBalanceHistory.d.ts +1 -1
- package/lib/api/blockchainGetAccountBalanceHistory.js +1 -1
- package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -1
- package/lib/api/blockchainGetCurrentFiatRates.js +1 -1
- package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -1
- package/lib/api/blockchainGetFiatRatesForTimestamps.js +1 -1
- package/lib/api/blockchainGetInfo.js +1 -1
- package/lib/api/blockchainGetTransactions.js +1 -1
- package/lib/api/blockchainSetCustomBackend.js +1 -1
- package/lib/api/blockchainSubscribe.d.ts +1 -1
- package/lib/api/blockchainSubscribe.js +1 -1
- package/lib/api/blockchainSubscribeFiatRates.d.ts +1 -1
- package/lib/api/blockchainSubscribeFiatRates.js +1 -1
- package/lib/api/blockchainUnsubscribe.d.ts +1 -1
- package/lib/api/blockchainUnsubscribe.js +1 -1
- package/lib/api/blockchainUnsubscribeFiatRates.js +1 -1
- package/lib/api/cancelCoinjoinAuthorization.d.ts +1 -1
- package/lib/api/cardano/api/cardanoComposeTransaction.d.ts +1 -1
- package/lib/api/cardano/api/cardanoComposeTransaction.js +3 -11
- package/lib/api/cardano/api/cardanoGetAddress.d.ts +1 -1
- package/lib/api/cardano/api/cardanoGetAddress.js +4 -4
- package/lib/api/cardano/api/cardanoGetNativeScriptHash.js +2 -2
- package/lib/api/cardano/api/cardanoGetPublicKey.js +2 -2
- package/lib/api/cardano/api/cardanoSignTransaction.d.ts +3 -3
- package/lib/api/cardano/api/cardanoSignTransaction.js +4 -4
- package/lib/api/cardano/cardanoAddressParameters.js +1 -1
- package/lib/api/cardano/cardanoAuxiliaryData.js +1 -1
- package/lib/api/cardano/cardanoCertificate.js +1 -1
- package/lib/api/cardano/cardanoInputs.js +1 -1
- package/lib/api/cardano/cardanoUtils.js +30 -0
- package/lib/api/changePin.d.ts +1 -1
- package/lib/api/changePin.js +1 -1
- package/lib/api/changeWipeCode.d.ts +1 -1
- package/lib/api/cipherKeyValue.d.ts +1 -1
- package/lib/api/cipherKeyValue.js +3 -3
- package/lib/api/common/Discovery.d.ts +2 -2
- package/lib/api/common/paramsValidator.js +1 -1
- package/lib/api/composeTransaction.d.ts +3 -3
- package/lib/api/composeTransaction.js +9 -9
- package/lib/api/eos/api/eosGetPublicKey.d.ts +1 -1
- package/lib/api/eos/api/eosGetPublicKey.js +2 -2
- package/lib/api/eos/api/eosSignTransaction.d.ts +1 -1
- package/lib/api/eos/api/eosSignTransaction.js +2 -2
- package/lib/api/eos/eosSignTx.d.ts +3 -3
- package/lib/api/ethereum/api/ethereumGetAddress.d.ts +3 -3
- package/lib/api/ethereum/api/ethereumGetAddress.js +6 -6
- package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +1 -1
- package/lib/api/ethereum/api/ethereumGetPublicKey.js +3 -3
- package/lib/api/ethereum/api/ethereumSignMessage.d.ts +1 -1
- package/lib/api/ethereum/api/ethereumSignMessage.js +3 -3
- package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +2 -2
- package/lib/api/ethereum/api/ethereumSignTransaction.js +4 -4
- package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +2 -1
- package/lib/api/ethereum/api/ethereumSignTypedData.js +6 -6
- package/lib/api/ethereum/api/ethereumVerifyMessage.d.ts +1 -1
- package/lib/api/ethereum/api/ethereumVerifyMessage.js +2 -2
- package/lib/api/ethereum/ethereumDefinitions.d.ts +2 -2
- package/lib/api/ethereum/ethereumDefinitions.js +1 -0
- package/lib/api/firmware/getBinaryForFirmwareUpgrade.js +2 -2
- package/lib/api/firmware/parseFirmwareHeaders.d.ts +2 -1
- package/lib/api/firmware/uploadFirmware.d.ts +1 -1
- package/lib/api/firmware/uploadFirmware.js +1 -1
- package/lib/api/firmware/verifyAuthenticityProof.d.ts +1 -1
- package/lib/api/firmware/verifyEntropy.d.ts +19 -0
- package/lib/api/firmware/verifyEntropy.js +112 -0
- package/lib/api/getAccountDescriptor.js +4 -4
- package/lib/api/getAccountInfo.d.ts +21 -1
- package/lib/api/getAccountInfo.js +7 -7
- package/lib/api/getAddress.d.ts +1 -1
- package/lib/api/getAddress.js +3 -3
- package/lib/api/getCoinInfo.d.ts +3 -0
- package/lib/api/getCoinInfo.js +1 -1
- package/lib/api/getDeviceState.js +1 -1
- package/lib/api/getFirmwareHash.d.ts +1 -1
- package/lib/api/getFirmwareHash.js +1 -1
- package/lib/api/getOwnershipId.d.ts +1 -1
- package/lib/api/getOwnershipId.js +2 -2
- package/lib/api/getOwnershipProof.d.ts +1 -1
- package/lib/api/getOwnershipProof.js +2 -2
- package/lib/api/getPublicKey.d.ts +1 -1
- package/lib/api/getPublicKey.js +4 -4
- package/lib/api/loadDevice.d.ts +1 -1
- package/lib/api/loadDevice.js +1 -1
- package/lib/api/nem/api/nemGetAddress.d.ts +1 -1
- package/lib/api/nem/api/nemGetAddress.js +3 -3
- package/lib/api/nem/api/nemSignTransaction.d.ts +1 -1
- package/lib/api/nem/api/nemSignTransaction.js +2 -2
- package/lib/api/pushTransaction.js +2 -2
- package/lib/api/recoveryDevice.d.ts +1 -1
- package/lib/api/requestLogin.d.ts +1 -1
- package/lib/api/requestLogin.js +2 -2
- package/lib/api/resetDevice.d.ts +3 -1
- package/lib/api/resetDevice.js +58 -3
- package/lib/api/ripple/api/rippleGetAddress.d.ts +1 -1
- package/lib/api/ripple/api/rippleGetAddress.js +3 -3
- package/lib/api/ripple/api/rippleSignTransaction.d.ts +1 -1
- package/lib/api/ripple/api/rippleSignTransaction.js +2 -2
- package/lib/api/setBrightness.d.ts +1 -1
- package/lib/api/setBrightness.js +1 -1
- package/lib/api/setBusy.d.ts +1 -1
- package/lib/api/setBusy.js +1 -1
- package/lib/api/setProxy.js +1 -1
- package/lib/api/showDeviceTutorial.d.ts +1 -1
- package/lib/api/showDeviceTutorial.js +1 -1
- package/lib/api/signMessage.d.ts +1 -1
- package/lib/api/signMessage.js +2 -2
- package/lib/api/signTransaction.d.ts +2 -2
- package/lib/api/signTransaction.js +3 -3
- package/lib/api/solana/api/index.d.ts +1 -0
- package/lib/api/solana/api/index.js +3 -1
- package/lib/api/solana/api/solanaComposeTransaction.d.ts +25 -0
- package/lib/api/solana/api/solanaComposeTransaction.js +61 -0
- package/lib/api/solana/api/solanaGetAddress.js +2 -2
- package/lib/api/solana/api/solanaGetPublicKey.js +2 -2
- package/lib/api/solana/api/solanaSignTransaction.d.ts +9 -1
- package/lib/api/solana/api/solanaSignTransaction.js +20 -2
- package/lib/api/solana/solanaUtils.d.ts +48 -0
- package/lib/api/solana/solanaUtils.js +213 -0
- package/lib/api/stellar/api/stellarGetAddress.d.ts +1 -1
- package/lib/api/stellar/api/stellarGetAddress.js +3 -3
- package/lib/api/stellar/api/stellarSignTransaction.js +3 -3
- package/lib/api/tezos/api/tezosGetAddress.d.ts +1 -1
- package/lib/api/tezos/api/tezosGetAddress.js +3 -3
- package/lib/api/tezos/api/tezosGetPublicKey.d.ts +1 -1
- package/lib/api/tezos/api/tezosGetPublicKey.js +2 -2
- package/lib/api/tezos/api/tezosSignTransaction.d.ts +1 -1
- package/lib/api/tezos/api/tezosSignTransaction.js +2 -2
- package/lib/api/tezos/tezosSignTx.d.ts +17 -17
- package/lib/api/unlockPath.d.ts +1 -1
- package/lib/api/verifyMessage.d.ts +1 -1
- package/lib/api/verifyMessage.js +3 -3
- package/lib/backend/BackendManager.d.ts +1 -1
- package/lib/backend/BackendManager.js +1 -1
- package/lib/backend/Blockchain.d.ts +2 -2
- package/lib/backend/Blockchain.js +4 -7
- package/lib/constants/errors.d.ts +2 -0
- package/lib/constants/errors.js +4 -0
- package/lib/core/AbstractMethod.d.ts +2 -2
- package/lib/core/AbstractMethod.js +2 -1
- package/lib/core/index.d.ts +3 -3
- package/lib/core/index.js +44 -48
- package/lib/core/onCallFirmwareUpdate.d.ts +3 -8
- package/lib/core/onCallFirmwareUpdate.js +63 -21
- package/lib/data/DataManager.js +1 -5
- package/lib/data/coinInfo.d.ts +15 -131
- package/lib/data/coinInfo.js +8 -8
- package/lib/data/config.d.ts +23 -0
- package/lib/data/config.js +4 -0
- package/lib/data/connectSettings.js +1 -1
- package/lib/data/defaultFeeLevels.d.ts +2 -2
- package/lib/data/defaultFeeLevels.js +34 -14
- package/lib/data/deviceAuthenticityConfigTypes.d.ts +1 -0
- package/lib/data/deviceAuthenticityConfigTypes.js +2 -2
- package/lib/data/firmwareInfo.js +1 -1
- package/lib/data/models.js +5 -1
- package/lib/data/transportInfo.d.ts +0 -1
- package/lib/data/transportInfo.js +41 -28
- package/lib/data/udevInfo.d.ts +0 -1
- package/lib/data/udevInfo.js +2 -5
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +11 -10
- package/lib/device/Device.js +39 -17
- package/lib/device/DeviceCommands.d.ts +2 -2
- package/lib/device/DeviceCommands.js +42 -27
- package/lib/device/DeviceList.d.ts +27 -22
- package/lib/device/DeviceList.js +222 -133
- package/lib/device/StateStorage.js +11 -13
- package/lib/device/prompts.js +28 -36
- package/lib/device/resolveDescriptorForTaproot.d.ts +2 -2
- package/lib/device/resolveDescriptorForTaproot.js +5 -13
- package/lib/events/blockchain.d.ts +1 -1
- package/lib/events/call.d.ts +1 -1
- package/lib/events/core.d.ts +3 -3
- package/lib/events/device.d.ts +11 -1
- package/lib/events/device.js +1 -0
- package/lib/events/popup.d.ts +2 -2
- package/lib/events/transport.d.ts +15 -9
- package/lib/events/transport.js +10 -1
- package/lib/events/ui-promise.d.ts +1 -1
- package/lib/events/ui-request.d.ts +3 -3
- package/lib/factory.d.ts +3 -2
- package/lib/factory.js +3 -1
- package/lib/impl/core-in-module.d.ts +4 -2
- package/lib/impl/core-in-module.js +9 -1
- package/lib/impl/dynamic.d.ts +4 -2
- package/lib/impl/dynamic.js +5 -4
- package/lib/index-browser.js +1 -0
- package/lib/index.js +11 -3
- package/lib/types/account.d.ts +1 -1
- package/lib/types/api/authenticateDevice.d.ts +1 -0
- package/lib/types/api/authorizeCoinjoin.d.ts +1 -1
- package/lib/types/api/authorizeCoinjoin.js +1 -1
- package/lib/types/api/binanceGetAddress.d.ts +1 -1
- package/lib/types/api/binanceGetPublicKey.d.ts +1 -1
- package/lib/types/api/blockchainEstimateFee.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/cardanoComposeTransaction.d.ts +112 -6
- package/lib/types/api/cardanoComposeTransaction.js +77 -0
- package/lib/types/api/cardanoGetAddress.d.ts +1 -1
- package/lib/types/api/cardanoGetPublicKey.d.ts +1 -1
- package/lib/types/api/changeLanguage.d.ts +1 -1
- package/lib/types/api/cipherKeyValue.d.ts +1 -1
- package/lib/types/api/composeTransaction.d.ts +1 -1
- package/lib/types/api/eosGetPublicKey.d.ts +1 -1
- package/lib/types/api/ethereumGetAddress.d.ts +1 -1
- package/lib/types/api/ethereumGetPublicKey.d.ts +1 -1
- package/lib/types/api/ethereumSignTypedData.d.ts +1 -1
- package/lib/types/api/firmwareUpdate.d.ts +11 -2
- package/lib/types/api/getAccountDescriptor.d.ts +1 -1
- package/lib/types/api/getAccountInfo.d.ts +1 -1
- package/lib/types/api/getAddress.d.ts +2 -1
- package/lib/types/api/getCoinInfo.d.ts +1 -1
- package/lib/types/api/getDeviceState.d.ts +1 -1
- package/lib/types/api/getFeatures.d.ts +1 -1
- package/lib/types/api/getOwnershipId.d.ts +2 -1
- package/lib/types/api/getOwnershipProof.d.ts +2 -1
- package/lib/types/api/getPublicKey.d.ts +1 -1
- package/lib/types/api/index.d.ts +7 -3
- package/lib/types/api/nem/index.d.ts +1 -1
- package/lib/types/api/nemGetAddress.d.ts +1 -1
- package/lib/types/api/on.d.ts +1 -1
- package/lib/types/api/recoveryDevice.d.ts +1 -1
- package/lib/types/api/rippleGetAddress.d.ts +1 -1
- package/lib/types/api/setTransports.d.ts +4 -0
- package/lib/types/api/setTransports.js +3 -0
- package/lib/types/api/solana/index.d.ts +41 -0
- package/lib/types/api/solana/index.js +31 -1
- package/lib/types/api/solanaComposeTransaction.d.ts +4 -0
- package/lib/types/api/solanaComposeTransaction.js +3 -0
- package/lib/types/api/solanaGetAddress.d.ts +1 -1
- package/lib/types/api/solanaGetPublicKey.d.ts +1 -1
- package/lib/types/api/stellarGetAddress.d.ts +1 -1
- package/lib/types/api/tezosGetAddress.d.ts +1 -1
- package/lib/types/api/tezosGetPublicKey.d.ts +1 -1
- package/lib/types/api/unlockPath.d.ts +1 -1
- package/lib/types/coinInfo.d.ts +33 -0
- package/lib/types/coinInfo.js +8 -2
- package/lib/types/params.d.ts +1 -1
- package/lib/utils/abortablePromise.d.ts +5 -0
- package/lib/utils/abortablePromise.js +17 -0
- package/lib/utils/accountUtils.d.ts +1 -1
- package/lib/utils/accountUtils.js +1 -1
- package/lib/utils/assetUtils.js +1 -2
- package/lib/utils/assets-browser.d.ts +1 -1
- package/lib/utils/assets.js +1 -1
- package/lib/utils/assets.native.d.ts +1 -1
- package/lib/utils/deviceFeaturesUtils.d.ts +1 -1
- package/lib/utils/deviceFeaturesUtils.js +6 -12
- package/lib/utils/ethereumUtils.d.ts +3 -2
- package/lib/utils/firmwareUtils.d.ts +1 -1
- package/lib/utils/firmwareUtils.js +11 -4
- package/lib/utils/pathUtils.d.ts +1 -1
- package/lib/utils/urlUtils.js +2 -0
- package/lib/workers/workers-browser.d.ts +2 -2
- package/lib/workers/workers-browser.js +2 -2
- package/lib/workers/workers.native.d.ts +1 -1
- package/lib/workers/workers.native.js +2 -2
- package/package.json +22 -12
- package/lib/utils/promiseUtils.d.ts +0 -5
- package/lib/utils/promiseUtils.js +0 -14
package/lib/device/DeviceList.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DeviceList = exports.assertDeviceListConnected = void 0;
|
|
4
|
-
const utils_1 = require("@trezor/utils");
|
|
5
4
|
const transport_1 = require("@trezor/transport");
|
|
5
|
+
const utils_1 = require("@trezor/utils");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
7
|
const events_1 = require("../events");
|
|
8
8
|
const Device_1 = require("./Device");
|
|
9
|
-
const types_1 = require("../types");
|
|
10
9
|
const transportInfo_1 = require("../data/transportInfo");
|
|
11
|
-
const
|
|
12
|
-
const promiseUtils_1 = require("../utils/promiseUtils");
|
|
10
|
+
const types_1 = require("../types");
|
|
13
11
|
const utils_2 = require("../types/utils");
|
|
14
|
-
const
|
|
12
|
+
const abortablePromise_1 = require("../utils/abortablePromise");
|
|
13
|
+
const debug_1 = require("../utils/debug");
|
|
15
14
|
const createAuthPenaltyManager = (priority) => {
|
|
16
15
|
const penalizedDevices = {};
|
|
17
16
|
const get = () => 100 * priority +
|
|
@@ -32,22 +31,81 @@ const createAuthPenaltyManager = (priority) => {
|
|
|
32
31
|
const clear = () => Object.keys(penalizedDevices).forEach(key => delete penalizedDevices[key]);
|
|
33
32
|
return { get, add, remove, clear };
|
|
34
33
|
};
|
|
34
|
+
const createDeviceCollection = () => {
|
|
35
|
+
let devices = [];
|
|
36
|
+
const isEqual = (a) => (b) => a.transport === b.transport && a.transportPath === b.transportPath;
|
|
37
|
+
const get = (transportPath, transport) => devices.find(isEqual({ transport, transportPath }));
|
|
38
|
+
const all = () => devices;
|
|
39
|
+
const add = (device) => {
|
|
40
|
+
const index = devices.findIndex(isEqual(device));
|
|
41
|
+
if (index >= 0)
|
|
42
|
+
devices[index] = device;
|
|
43
|
+
else
|
|
44
|
+
devices.push(device);
|
|
45
|
+
};
|
|
46
|
+
const remove = (transportPath, transport) => {
|
|
47
|
+
const index = devices.findIndex(isEqual({ transport, transportPath }));
|
|
48
|
+
const [removed] = index >= 0 ? devices.splice(index, 1) : [undefined];
|
|
49
|
+
return removed;
|
|
50
|
+
};
|
|
51
|
+
const clear = (transport) => {
|
|
52
|
+
let removed;
|
|
53
|
+
[removed, devices] = (0, utils_1.arrayPartition)(devices, d => !transport || d.transport === transport);
|
|
54
|
+
return removed;
|
|
55
|
+
};
|
|
56
|
+
return { get, all, add, remove, clear };
|
|
57
|
+
};
|
|
58
|
+
const getTransportInfo = (transport) => ({
|
|
59
|
+
apiType: transport.apiType,
|
|
60
|
+
type: transport.name,
|
|
61
|
+
version: transport.version,
|
|
62
|
+
outdated: transport.isOutdated,
|
|
63
|
+
});
|
|
35
64
|
const assertDeviceListConnected = deviceList => {
|
|
36
|
-
if (!deviceList.isConnected())
|
|
65
|
+
if (!deviceList.isConnected()) {
|
|
37
66
|
throw constants_1.ERRORS.TypedError('Transport_Missing');
|
|
67
|
+
}
|
|
38
68
|
};
|
|
39
69
|
exports.assertDeviceListConnected = assertDeviceListConnected;
|
|
40
70
|
class DeviceList extends utils_1.TypedEmitter {
|
|
41
71
|
isConnected() {
|
|
42
|
-
return !!this.transport;
|
|
72
|
+
return !!Object.keys(this.transport).length;
|
|
43
73
|
}
|
|
44
74
|
pendingConnection() {
|
|
45
|
-
|
|
75
|
+
const pending = Object.values(this.locks)
|
|
76
|
+
.map(({ promise }) => promise)
|
|
77
|
+
.filter(utils_1.isNotUndefined);
|
|
78
|
+
if (pending.length)
|
|
79
|
+
return Promise.all(pending).then(() => { });
|
|
80
|
+
}
|
|
81
|
+
getActiveTransports() {
|
|
82
|
+
return Object.values(this.transport).map(getTransportInfo);
|
|
83
|
+
}
|
|
84
|
+
async transportLock(apiType, abortMessage, action) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const lock = (_a = this.locks[apiType]) !== null && _a !== void 0 ? _a : (this.locks[apiType] = { sequence: 0 });
|
|
87
|
+
lock.abortMessage = abortMessage;
|
|
88
|
+
const sequence = ++lock.sequence;
|
|
89
|
+
while (lock.promise) {
|
|
90
|
+
(_b = lock.abort) === null || _b === void 0 ? void 0 : _b.abort(new Error(abortMessage));
|
|
91
|
+
await lock.promise.catch(() => { });
|
|
92
|
+
}
|
|
93
|
+
if (sequence !== lock.sequence)
|
|
94
|
+
return Promise.reject(new Error(lock.abortMessage));
|
|
95
|
+
lock.abort = new AbortController();
|
|
96
|
+
lock.promise = action(lock.abort.signal).finally(() => {
|
|
97
|
+
delete lock.abort;
|
|
98
|
+
delete lock.promise;
|
|
99
|
+
});
|
|
100
|
+
return lock.promise;
|
|
46
101
|
}
|
|
47
102
|
constructor({ messages, priority, debug, _sessionsBackgroundUrl, manifest, }) {
|
|
48
103
|
super();
|
|
49
|
-
this.
|
|
104
|
+
this.transport = {};
|
|
105
|
+
this.transports = [];
|
|
106
|
+
this.devices = createDeviceCollection();
|
|
50
107
|
this.deviceCounter = Date.now();
|
|
108
|
+
this.locks = {};
|
|
51
109
|
const transportLogger = (0, debug_1.initLog)('@trezor/transport', debug);
|
|
52
110
|
this.handshakeLock = (0, utils_1.getSynchronize)();
|
|
53
111
|
this.authPenaltyManager = createAuthPenaltyManager(priority);
|
|
@@ -57,16 +115,17 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
57
115
|
sessionsBackgroundUrl: _sessionsBackgroundUrl,
|
|
58
116
|
id: (manifest === null || manifest === void 0 ? void 0 : manifest.appUrl) || 'unknown app',
|
|
59
117
|
};
|
|
60
|
-
this.transports = [
|
|
61
|
-
new transport_1.BridgeTransport({
|
|
62
|
-
latestVersion: (0, transportInfo_1.getBridgeInfo)().version.join('.'),
|
|
63
|
-
...this.transportCommonArgs,
|
|
64
|
-
}),
|
|
65
|
-
];
|
|
66
118
|
}
|
|
67
|
-
|
|
119
|
+
tryGetTransport(name) {
|
|
120
|
+
return this.transports.find(t => t.name === name);
|
|
121
|
+
}
|
|
122
|
+
getOrCreateTransport(transportType) {
|
|
123
|
+
var _a;
|
|
68
124
|
const { transportCommonArgs } = this;
|
|
69
125
|
if (typeof transportType === 'string') {
|
|
126
|
+
const existing = this.tryGetTransport(transportType);
|
|
127
|
+
if (existing)
|
|
128
|
+
return existing;
|
|
70
129
|
switch (transportType) {
|
|
71
130
|
case 'WebUsbTransport':
|
|
72
131
|
return new transport_1.WebUsbTransport(transportCommonArgs);
|
|
@@ -84,10 +143,13 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
84
143
|
else if (typeof transportType === 'function' && 'prototype' in transportType) {
|
|
85
144
|
const transportInstance = new transportType(transportCommonArgs);
|
|
86
145
|
if ((0, transport_1.isTransportInstance)(transportInstance)) {
|
|
87
|
-
return transportInstance;
|
|
146
|
+
return (_a = this.tryGetTransport(transportInstance.name)) !== null && _a !== void 0 ? _a : transportInstance;
|
|
88
147
|
}
|
|
89
148
|
}
|
|
90
149
|
else if ((0, transport_1.isTransportInstance)(transportType)) {
|
|
150
|
+
if (this.tryGetTransport(transportType.name)) {
|
|
151
|
+
return transportType;
|
|
152
|
+
}
|
|
91
153
|
if (!transportType.getMessage()) {
|
|
92
154
|
transportType.updateMessages(transportCommonArgs.messages);
|
|
93
155
|
}
|
|
@@ -95,185 +157,212 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
95
157
|
}
|
|
96
158
|
throw constants_1.ERRORS.TypedError('Runtime', `DeviceList.init: transports[] of unexpected type: ${transportType}`);
|
|
97
159
|
}
|
|
98
|
-
|
|
160
|
+
createTransports(transports) {
|
|
99
161
|
const transportTypes = (transports === null || transports === void 0 ? void 0 : transports.length) ? transports : ['BridgeTransport'];
|
|
100
|
-
|
|
162
|
+
return transportTypes.map(this.getOrCreateTransport.bind(this));
|
|
101
163
|
}
|
|
102
164
|
onDeviceConnected(descriptor, transport) {
|
|
103
|
-
const { path } = descriptor;
|
|
104
165
|
const id = (this.deviceCounter++).toString(16).slice(-8);
|
|
105
166
|
const device = new Device_1.Device({
|
|
106
167
|
id: (0, types_1.DeviceUniquePath)(id),
|
|
107
168
|
transport,
|
|
108
169
|
descriptor,
|
|
109
|
-
listener: lifecycle => this.emit(lifecycle, device
|
|
170
|
+
listener: lifecycle => this.emit(lifecycle, device),
|
|
110
171
|
});
|
|
111
|
-
this.devices
|
|
172
|
+
this.devices.add(device);
|
|
112
173
|
const penalty = this.authPenaltyManager.get();
|
|
113
174
|
this.handshakeLock(async () => {
|
|
114
|
-
if (this.devices
|
|
175
|
+
if (this.devices.get(descriptor.path, transport)) {
|
|
115
176
|
await device.handshake(penalty);
|
|
116
177
|
}
|
|
117
178
|
});
|
|
118
179
|
}
|
|
119
|
-
onDeviceDisconnected(descriptor) {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
if (device) {
|
|
123
|
-
device.disconnect();
|
|
124
|
-
delete this.devices[path];
|
|
125
|
-
}
|
|
180
|
+
onDeviceDisconnected(descriptor, transport) {
|
|
181
|
+
const device = this.devices.remove(descriptor.path, transport);
|
|
182
|
+
device === null || device === void 0 ? void 0 : device.disconnect();
|
|
126
183
|
}
|
|
127
|
-
onDeviceSessionChanged(descriptor) {
|
|
128
|
-
const device = this.devices
|
|
129
|
-
|
|
130
|
-
device.updateDescriptor(descriptor);
|
|
131
|
-
}
|
|
184
|
+
onDeviceSessionChanged(descriptor, transport) {
|
|
185
|
+
const device = this.devices.get(descriptor.path, transport);
|
|
186
|
+
device === null || device === void 0 ? void 0 : device.updateDescriptor(descriptor);
|
|
132
187
|
}
|
|
133
|
-
onDeviceRequestRelease(descriptor) {
|
|
134
|
-
|
|
135
|
-
|
|
188
|
+
onDeviceRequestRelease(descriptor, transport) {
|
|
189
|
+
const device = this.devices.get(descriptor.path, transport);
|
|
190
|
+
device === null || device === void 0 ? void 0 : device.usedElsewhere();
|
|
136
191
|
}
|
|
137
|
-
init(initParams = {}) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
192
|
+
async init(initParams = {}) {
|
|
193
|
+
this.transports = this.createTransports(initParams.transports);
|
|
194
|
+
const promises = this.transports
|
|
195
|
+
.map(t => t.apiType)
|
|
196
|
+
.concat((0, utils_2.typedObjectKeys)(this.transport))
|
|
197
|
+
.concat((0, utils_2.typedObjectKeys)(this.locks))
|
|
198
|
+
.filter(utils_1.arrayDistinct)
|
|
199
|
+
.map(apiType => this.transportLock(apiType, 'New init', signal => this.createInitPromise(apiType, initParams, signal)));
|
|
200
|
+
await Promise.all(promises);
|
|
143
201
|
}
|
|
144
|
-
createInitPromise(initParams) {
|
|
145
|
-
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
this.emit(transport_1.TRANSPORT.START, this.getTransportInfo());
|
|
150
|
-
this.initPromise = undefined;
|
|
151
|
-
})
|
|
152
|
-
.catch(error => {
|
|
153
|
-
this.cleanup();
|
|
154
|
-
this.emit(transport_1.TRANSPORT.ERROR, error);
|
|
155
|
-
this.initPromise = initParams.transportReconnect
|
|
156
|
-
? this.createReconnectPromise(initParams)
|
|
202
|
+
async createInitPromise(apiType, initParams, abortSignal) {
|
|
203
|
+
try {
|
|
204
|
+
const transports = this.transports.filter(t => t.apiType === apiType);
|
|
205
|
+
const transport = transports.length
|
|
206
|
+
? await this.selectTransport(transports, abortSignal)
|
|
157
207
|
: undefined;
|
|
158
|
-
|
|
208
|
+
const oldTransport = this.transport[apiType];
|
|
209
|
+
if (oldTransport !== transport) {
|
|
210
|
+
if (oldTransport) {
|
|
211
|
+
delete this.transport[apiType];
|
|
212
|
+
await this.stopTransport(oldTransport);
|
|
213
|
+
if (!transport) {
|
|
214
|
+
this.emit(transport_1.TRANSPORT.ERROR, { apiType, error: 'Transport disabled' });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (transport) {
|
|
218
|
+
try {
|
|
219
|
+
await this.initializeTransport(transport, initParams, abortSignal);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
await this.stopTransport(transport);
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
transport.on(transport_1.TRANSPORT.ERROR, error => {
|
|
226
|
+
this.emit(transport_1.TRANSPORT.ERROR, { apiType, error });
|
|
227
|
+
this.transportLock(apiType, 'Transport error', async (signal) => {
|
|
228
|
+
delete this.transport[apiType];
|
|
229
|
+
await this.stopTransport(transport);
|
|
230
|
+
if (initParams.transportReconnect) {
|
|
231
|
+
await this.createReconnectDelay(signal);
|
|
232
|
+
await this.createInitPromise(apiType, initParams, signal);
|
|
233
|
+
}
|
|
234
|
+
}).catch(() => { });
|
|
235
|
+
});
|
|
236
|
+
this.transport[apiType] = transport;
|
|
237
|
+
this.emit(transport_1.TRANSPORT.START, getTransportInfo(transport));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
this.emit(transport_1.TRANSPORT.ERROR, { apiType, error: error === null || error === void 0 ? void 0 : error.message });
|
|
243
|
+
if (initParams.transportReconnect && !abortSignal.aborted) {
|
|
244
|
+
this.transportLock(apiType, 'Reconnecting', async (signal) => {
|
|
245
|
+
await this.createReconnectDelay(signal);
|
|
246
|
+
await this.createInitPromise(apiType, initParams, signal);
|
|
247
|
+
}).catch(() => { });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
159
250
|
}
|
|
160
|
-
|
|
161
|
-
const { promise,
|
|
162
|
-
|
|
163
|
-
return promise
|
|
164
|
-
.then(this.createInitPromise.bind(this))
|
|
165
|
-
.catch(() => { })
|
|
166
|
-
.finally(() => {
|
|
167
|
-
this.rejectPending = undefined;
|
|
168
|
-
});
|
|
251
|
+
createReconnectDelay(signal) {
|
|
252
|
+
const { promise, resolve } = (0, abortablePromise_1.abortablePromise)(signal);
|
|
253
|
+
const timeout = setTimeout(resolve, 1000);
|
|
254
|
+
return promise.finally(() => clearTimeout(timeout));
|
|
169
255
|
}
|
|
170
|
-
async selectTransport([transport, ...rest]) {
|
|
171
|
-
|
|
256
|
+
async selectTransport([transport, ...rest], signal) {
|
|
257
|
+
if (signal.aborted)
|
|
258
|
+
throw new Error(signal.reason);
|
|
259
|
+
if (transport === this.transport[transport.apiType])
|
|
260
|
+
return transport;
|
|
261
|
+
const result = await transport.init({ signal });
|
|
172
262
|
if (result.success)
|
|
173
263
|
return transport;
|
|
174
264
|
else if (rest.length)
|
|
175
|
-
return this.selectTransport(rest);
|
|
265
|
+
return this.selectTransport(rest, signal);
|
|
176
266
|
else
|
|
177
267
|
throw new Error(result.error);
|
|
178
268
|
}
|
|
179
|
-
async initializeTransport(transport, initParams) {
|
|
269
|
+
async initializeTransport(transport, initParams, signal) {
|
|
180
270
|
transport.on(transport_1.TRANSPORT.DEVICE_CONNECTED, d => this.onDeviceConnected(d, transport));
|
|
181
|
-
transport.on(transport_1.TRANSPORT.DEVICE_DISCONNECTED, this.onDeviceDisconnected
|
|
182
|
-
transport.on(transport_1.TRANSPORT.DEVICE_SESSION_CHANGED, this.onDeviceSessionChanged
|
|
183
|
-
transport.on(transport_1.TRANSPORT.DEVICE_REQUEST_RELEASE, this.onDeviceRequestRelease
|
|
184
|
-
transport.
|
|
185
|
-
this.cleanup();
|
|
186
|
-
this.emit(transport_1.TRANSPORT.ERROR, error);
|
|
187
|
-
if (initParams.transportReconnect) {
|
|
188
|
-
this.initPromise = this.createReconnectPromise(initParams);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
const enumerateResult = await transport.enumerate();
|
|
271
|
+
transport.on(transport_1.TRANSPORT.DEVICE_DISCONNECTED, d => this.onDeviceDisconnected(d, transport));
|
|
272
|
+
transport.on(transport_1.TRANSPORT.DEVICE_SESSION_CHANGED, d => this.onDeviceSessionChanged(d, transport));
|
|
273
|
+
transport.on(transport_1.TRANSPORT.DEVICE_REQUEST_RELEASE, d => this.onDeviceRequestRelease(d, transport));
|
|
274
|
+
const enumerateResult = await transport.enumerate({ signal });
|
|
192
275
|
if (!enumerateResult.success) {
|
|
193
276
|
throw new Error(enumerateResult.error);
|
|
194
277
|
}
|
|
195
278
|
const descriptors = enumerateResult.payload;
|
|
196
279
|
const waitForDevicesPromise = initParams.pendingTransportEvent && descriptors.length
|
|
197
|
-
? this.waitForDevices(descriptors
|
|
280
|
+
? this.waitForDevices(transport, descriptors, signal)
|
|
198
281
|
: Promise.resolve();
|
|
199
282
|
transport.handleDescriptorsChange(descriptors);
|
|
200
283
|
transport.listen();
|
|
201
284
|
await waitForDevicesPromise;
|
|
202
|
-
return transport;
|
|
203
285
|
}
|
|
204
|
-
waitForDevices(
|
|
205
|
-
const { promise,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
286
|
+
waitForDevices(transport, descriptors, signal) {
|
|
287
|
+
const { promise, reject, resolve } = (0, utils_1.createDeferred)();
|
|
288
|
+
const onAbort = () => reject(signal.reason);
|
|
289
|
+
signal.addEventListener('abort', onAbort);
|
|
290
|
+
const onError = (error) => reject(new Error(error));
|
|
291
|
+
transport.once(transport_1.TRANSPORT.ERROR, onError);
|
|
292
|
+
const autoResolveTransportEventTimeout = setTimeout(resolve, 10000);
|
|
293
|
+
const remaining = descriptors.slice();
|
|
294
|
+
const onDeviceEvent = (device) => {
|
|
295
|
+
const index = remaining.findIndex(d => d.path === device.transportPath && transport === device.transport);
|
|
296
|
+
if (index >= 0)
|
|
297
|
+
remaining.splice(index, 1);
|
|
298
|
+
if (!remaining.length)
|
|
212
299
|
resolve();
|
|
213
|
-
}
|
|
214
300
|
};
|
|
215
|
-
this.on(events_1.DEVICE.CONNECT,
|
|
216
|
-
this.on(events_1.DEVICE.CONNECT_UNACQUIRED,
|
|
301
|
+
this.on(events_1.DEVICE.CONNECT, onDeviceEvent);
|
|
302
|
+
this.on(events_1.DEVICE.CONNECT_UNACQUIRED, onDeviceEvent);
|
|
303
|
+
this.on(events_1.DEVICE.DISCONNECT, onDeviceEvent);
|
|
217
304
|
return promise.finally(() => {
|
|
218
|
-
|
|
305
|
+
transport.off(transport_1.TRANSPORT.ERROR, onError);
|
|
306
|
+
signal.removeEventListener('abort', onAbort);
|
|
219
307
|
clearTimeout(autoResolveTransportEventTimeout);
|
|
220
|
-
this.off(events_1.DEVICE.CONNECT,
|
|
221
|
-
this.off(events_1.DEVICE.CONNECT_UNACQUIRED,
|
|
308
|
+
this.off(events_1.DEVICE.CONNECT, onDeviceEvent);
|
|
309
|
+
this.off(events_1.DEVICE.CONNECT_UNACQUIRED, onDeviceEvent);
|
|
310
|
+
this.off(events_1.DEVICE.DISCONNECT, onDeviceEvent);
|
|
222
311
|
});
|
|
223
312
|
}
|
|
224
313
|
getDeviceCount() {
|
|
225
|
-
return
|
|
314
|
+
return this.devices.all().length;
|
|
226
315
|
}
|
|
227
316
|
getAllDevices() {
|
|
228
|
-
return
|
|
317
|
+
return this.devices.all();
|
|
229
318
|
}
|
|
230
319
|
getOnlyDevice() {
|
|
231
|
-
return this.getDeviceCount() === 1 ?
|
|
320
|
+
return this.getDeviceCount() === 1 ? this.devices.all()[0] : undefined;
|
|
232
321
|
}
|
|
233
322
|
getDeviceByPath(path) {
|
|
234
|
-
return this.
|
|
323
|
+
return this.devices.all().find(d => d.getUniquePath() === path);
|
|
235
324
|
}
|
|
236
325
|
getDeviceByStaticState(state) {
|
|
237
326
|
const deviceId = state.split('@')[1].split(':')[0];
|
|
238
|
-
return this.
|
|
239
|
-
}
|
|
240
|
-
transportType() {
|
|
241
|
-
return this.transport.name;
|
|
242
|
-
}
|
|
243
|
-
getTransportInfo() {
|
|
244
|
-
return {
|
|
245
|
-
type: this.transportType(),
|
|
246
|
-
version: this.transport.version,
|
|
247
|
-
outdated: this.transport.isOutdated,
|
|
248
|
-
};
|
|
327
|
+
return this.devices.all().find(d => { var _a; return ((_a = d.features) === null || _a === void 0 ? void 0 : _a.device_id) === deviceId; });
|
|
249
328
|
}
|
|
250
|
-
dispose() {
|
|
329
|
+
async dispose() {
|
|
251
330
|
this.removeAllListeners();
|
|
252
|
-
|
|
331
|
+
const promises = (0, utils_2.typedObjectKeys)(this.transport)
|
|
332
|
+
.concat((0, utils_2.typedObjectKeys)(this.locks))
|
|
333
|
+
.filter(utils_1.arrayDistinct)
|
|
334
|
+
.map(apiType => this.transportLock(apiType, 'Disposing', async () => {
|
|
335
|
+
const transport = this.transport[apiType];
|
|
336
|
+
if (transport) {
|
|
337
|
+
delete this.transport[apiType];
|
|
338
|
+
await this.stopTransport(transport);
|
|
339
|
+
}
|
|
340
|
+
}));
|
|
341
|
+
await Promise.all(promises);
|
|
253
342
|
}
|
|
254
|
-
async
|
|
255
|
-
|
|
256
|
-
const { transport } = this;
|
|
257
|
-
const devices = this.getAllDevices();
|
|
258
|
-
this.transport = undefined;
|
|
259
|
-
this.authPenaltyManager.clear();
|
|
260
|
-
(0, utils_2.typedObjectKeys)(this.devices).forEach(key => delete this.devices[key]);
|
|
261
|
-
(_a = this.rejectPending) === null || _a === void 0 ? void 0 : _a.call(this, new Error('Disposed'));
|
|
343
|
+
async stopTransport(transport) {
|
|
344
|
+
const devices = this.devices.clear(transport);
|
|
262
345
|
devices.forEach(device => {
|
|
263
|
-
this.emit(events_1.DEVICE.DISCONNECT, device
|
|
346
|
+
this.emit(events_1.DEVICE.DISCONNECT, device);
|
|
264
347
|
});
|
|
265
|
-
await Promise.all(devices.map(device =>
|
|
348
|
+
await Promise.all(devices.map(async (device) => {
|
|
349
|
+
this.authPenaltyManager.remove(device);
|
|
350
|
+
await device.dispose();
|
|
351
|
+
}));
|
|
266
352
|
transport === null || transport === void 0 ? void 0 : transport.stop();
|
|
267
353
|
}
|
|
268
|
-
async enumerate(
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
354
|
+
async enumerate() {
|
|
355
|
+
const promises = Object.values(this.transport).map(async (transport) => {
|
|
356
|
+
const res = await transport.enumerate();
|
|
357
|
+
if (!res.success) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
res.payload.forEach(d => {
|
|
361
|
+
var _a;
|
|
362
|
+
(_a = this.devices.get(d.path, transport)) === null || _a === void 0 ? void 0 : _a.updateDescriptor(d);
|
|
363
|
+
});
|
|
276
364
|
});
|
|
365
|
+
await Promise.all(promises);
|
|
277
366
|
}
|
|
278
367
|
addAuthPenalty(device) {
|
|
279
368
|
return this.authPenaltyManager.add(device);
|
|
@@ -21,19 +21,17 @@ class WebextensionStateStorage {
|
|
|
21
21
|
saveState(device, state) {
|
|
22
22
|
var _a;
|
|
23
23
|
const expirationDelay = Math.max(1000 * 60 * 15, (_a = device.features.auto_lock_delay_ms) !== null && _a !== void 0 ? _a : 0);
|
|
24
|
-
connect_common_1.storage.saveForOrigin(store => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
}, this.origin);
|
|
24
|
+
connect_common_1.storage.saveForOrigin(store => ({
|
|
25
|
+
...store,
|
|
26
|
+
preferredDevice: store.preferredDevice
|
|
27
|
+
? {
|
|
28
|
+
...store.preferredDevice,
|
|
29
|
+
state: state.staticSessionId,
|
|
30
|
+
internalState: state.sessionId,
|
|
31
|
+
internalStateExpiration: Date.now() + expirationDelay,
|
|
32
|
+
}
|
|
33
|
+
: undefined,
|
|
34
|
+
}), this.origin);
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
exports.WebextensionStateStorage = WebextensionStateStorage;
|
package/lib/device/prompts.js
CHANGED
|
@@ -21,44 +21,36 @@ const cancelPrompt = (device, expectResponse = true) => {
|
|
|
21
21
|
return expectResponse ? device.transport.call(cancelArgs) : device.transport.send(cancelArgs);
|
|
22
22
|
};
|
|
23
23
|
exports.cancelPrompt = cancelPrompt;
|
|
24
|
-
const prompt = (event, ...[device, ...args]) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
: onCancel.error));
|
|
32
|
-
});
|
|
33
|
-
if (device.listenerCount(event) > 0) {
|
|
34
|
-
device.setCancelableAction(cancelAndReject);
|
|
35
|
-
const callback = (...[response, error]) => {
|
|
36
|
-
device.clearCancelableAction();
|
|
37
|
-
if (error || response == null) {
|
|
38
|
-
cancelAndReject(error);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
resolve(response);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const emitArgs = [event, device, ...args, callback];
|
|
45
|
-
device.emit(...emitArgs);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
cancelAndReject(constants_1.ERRORS.TypedError('Runtime', `${event} callback not configured`));
|
|
49
|
-
}
|
|
24
|
+
const prompt = (event, ...[device, ...args]) => 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));
|
|
50
31
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
const promptPassphrase = (device) => prompt(events_1.DEVICE.PASSPHRASE, device);
|
|
55
51
|
exports.promptPassphrase = promptPassphrase;
|
|
56
|
-
const promptPin = (device, type) =>
|
|
57
|
-
return prompt(events_1.DEVICE.PIN, device, type);
|
|
58
|
-
};
|
|
52
|
+
const promptPin = (device, type) => prompt(events_1.DEVICE.PIN, device, type);
|
|
59
53
|
exports.promptPin = promptPin;
|
|
60
|
-
const promptWord = (device, type) =>
|
|
61
|
-
return prompt(events_1.DEVICE.WORD, device, type);
|
|
62
|
-
};
|
|
54
|
+
const promptWord = (device, type) => prompt(events_1.DEVICE.WORD, device, type);
|
|
63
55
|
exports.promptWord = promptWord;
|
|
64
56
|
//# sourceMappingURL=prompts.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MessagesSchema as Messages } from '@trezor/protobuf';
|
|
2
2
|
import { HDNodeResponse } from '../types/api/getPublicKey';
|
|
3
|
-
interface
|
|
3
|
+
interface ResolveDescriptorForTaprootParams {
|
|
4
4
|
response: HDNodeResponse;
|
|
5
5
|
publicKey: Messages.PublicKey;
|
|
6
6
|
}
|
|
7
|
-
export declare const resolveDescriptorForTaproot: ({ response, publicKey }:
|
|
7
|
+
export declare const resolveDescriptorForTaproot: ({ response, publicKey, }: ResolveDescriptorForTaprootParams) => {
|
|
8
8
|
xpub: string;
|
|
9
9
|
checksum: string;
|
|
10
10
|
} | {
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveDescriptorForTaproot = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("@trezor/utils");
|
|
5
|
+
const resolveDescriptorForTaproot = ({ response, publicKey, }) => {
|
|
5
6
|
if (publicKey.descriptor !== null && publicKey.descriptor !== undefined) {
|
|
6
7
|
const [xpub, checksum] = publicKey.descriptor.split('#');
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
const closingSquareBracketSplit = afterOpeningBracket.split(']');
|
|
11
|
-
if (closingSquareBracketSplit.length === 2) {
|
|
12
|
-
const [path, afterClosingBracket] = closingSquareBracketSplit;
|
|
13
|
-
const correctedPath = path.replace(/h/g, "'");
|
|
14
|
-
return {
|
|
15
|
-
xpub: `${beforeOpeningBracket}[${correctedPath}]${afterClosingBracket}`,
|
|
16
|
-
checksum,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
8
|
+
const correctedXpub = (0, utils_1.convertTaprootXpub)({ xpub, direction: 'h-to-apostrophe' });
|
|
9
|
+
if (correctedXpub !== null) {
|
|
10
|
+
return { xpub: correctedXpub, checksum };
|
|
19
11
|
}
|
|
20
12
|
}
|
|
21
13
|
const fingerprint = Number(publicKey.root_fingerprint || 0)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockEvent, FiatRatesBySymbol, NotificationEvent, ServerInfo } from '@trezor/blockchain-link';
|
|
2
2
|
import type { CoinInfo } from '../types/coinInfo';
|
|
3
3
|
import type { MessageFactoryFn } from '../types/utils';
|
|
4
4
|
export declare const BLOCKCHAIN_EVENT = "BLOCKCHAIN_EVENT";
|
package/lib/events/call.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IFRAME } from './iframe';
|
|
2
|
+
import { Device } from '../device/Device';
|
|
2
3
|
import type { TrezorConnect } from '../types/api';
|
|
3
4
|
import type { CommonParams, DeviceIdentity } from '../types/params';
|
|
4
|
-
import { Device } from '../device/Device';
|
|
5
5
|
type UnwrappedResponse<Response> = Response extends Promise<infer R> ? R extends {
|
|
6
6
|
success: true;
|
|
7
7
|
payload: infer P;
|