@trezor/connect 10.0.0-beta.1 → 10.0.0-beta.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 +56 -9
- package/README.md +4 -2
- package/lib/exports.d.ts +1 -3
- package/lib/exports.js +1 -3
- package/lib/impl/core-in-module-native.d.ts +7 -0
- package/lib/impl/core-in-module-native.js +11 -0
- package/lib/impl/core-in-module-node.d.ts +8 -0
- package/lib/impl/core-in-module-node.js +12 -0
- package/lib/impl/core-in-module-web.d.ts +9 -0
- package/lib/impl/core-in-module-web.js +26 -0
- package/lib/index.browser.js +2 -26
- package/lib/index.js +1 -11
- package/lib/index.native.d.ts +4 -0
- package/lib/index.native.js +5 -0
- package/package.json +16 -67
- package/lib/api/applyFlags.d.ts +0 -20
- package/lib/api/applyFlags.js +0 -38
- package/lib/api/applySettings.d.ts +0 -20
- package/lib/api/applySettings.js +0 -57
- package/lib/api/authenticateDevice.d.ts +0 -25
- package/lib/api/authenticateDevice.js +0 -195
- package/lib/api/authorizeCoinjoin.d.ts +0 -11
- package/lib/api/authorizeCoinjoin.js +0 -44
- package/lib/api/backupDevice.d.ts +0 -19
- package/lib/api/backupDevice.js +0 -39
- package/lib/api/bitcoin/TransactionComposer.d.ts +0 -46
- package/lib/api/bitcoin/TransactionComposer.js +0 -147
- package/lib/api/bitcoin/createPendingTx.d.ts +0 -37
- package/lib/api/bitcoin/createPendingTx.js +0 -55
- package/lib/api/bitcoin/enhanceSignTx.d.ts +0 -2
- package/lib/api/bitcoin/enhanceSignTx.js +0 -23
- package/lib/api/bitcoin/index.d.ts +0 -9
- package/lib/api/bitcoin/index.js +0 -9
- package/lib/api/bitcoin/inputs.d.ts +0 -4
- package/lib/api/bitcoin/inputs.js +0 -63
- package/lib/api/bitcoin/outputs.d.ts +0 -5
- package/lib/api/bitcoin/outputs.js +0 -128
- package/lib/api/bitcoin/refTx.d.ts +0 -23
- package/lib/api/bitcoin/refTx.js +0 -249
- package/lib/api/bitcoin/signtx.d.ts +0 -30
- package/lib/api/bitcoin/signtx.js +0 -229
- package/lib/api/bitcoin/signtxLegacy.d.ts +0 -10
- package/lib/api/bitcoin/signtxLegacy.js +0 -186
- package/lib/api/bitcoin/signtxVerify.d.ts +0 -12
- package/lib/api/bitcoin/signtxVerify.js +0 -95
- package/lib/api/bitcoin/transactionBytes.d.ts +0 -3
- package/lib/api/bitcoin/transactionBytes.js +0 -65
- package/lib/api/bleUnpair.d.ts +0 -11
- package/lib/api/bleUnpair.js +0 -37
- package/lib/api/blockchainDisconnect.d.ts +0 -16
- package/lib/api/blockchainDisconnect.js +0 -37
- package/lib/api/blockchainEstimateFee.d.ts +0 -16
- package/lib/api/blockchainEstimateFee.js +0 -102
- package/lib/api/blockchainEvmRpcCall.d.ts +0 -19
- package/lib/api/blockchainEvmRpcCall.js +0 -57
- package/lib/api/blockchainGetAccountBalanceHistory.d.ts +0 -16
- package/lib/api/blockchainGetAccountBalanceHistory.js +0 -60
- package/lib/api/blockchainGetContractInfo.d.ts +0 -16
- package/lib/api/blockchainGetContractInfo.js +0 -46
- package/lib/api/blockchainGetCurrentFiatRates.d.ts +0 -20
- package/lib/api/blockchainGetCurrentFiatRates.js +0 -49
- package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +0 -23
- package/lib/api/blockchainGetFiatRatesForTimestamps.js +0 -55
- package/lib/api/blockchainGetInfo.d.ts +0 -15
- package/lib/api/blockchainGetInfo.js +0 -37
- package/lib/api/blockchainGetTransactions.d.ts +0 -18
- package/lib/api/blockchainGetTransactions.js +0 -47
- package/lib/api/blockchainSetCustomBackend.d.ts +0 -17
- package/lib/api/blockchainSetCustomBackend.js +0 -43
- package/lib/api/blockchainSubscribe.d.ts +0 -19
- package/lib/api/blockchainSubscribe.js +0 -66
- package/lib/api/blockchainSubscribeFiatRates.d.ts +0 -19
- package/lib/api/blockchainSubscribeFiatRates.js +0 -43
- package/lib/api/blockchainUnsubscribe.d.ts +0 -19
- package/lib/api/blockchainUnsubscribe.js +0 -66
- package/lib/api/blockchainUnsubscribeFiatRates.d.ts +0 -17
- package/lib/api/blockchainUnsubscribeFiatRates.js +0 -37
- package/lib/api/blockchainValidateEvmRpcUrl.d.ts +0 -17
- package/lib/api/blockchainValidateEvmRpcUrl.js +0 -54
- package/lib/api/cancelCoinjoinAuthorization.d.ts +0 -11
- package/lib/api/cancelCoinjoinAuthorization.js +0 -33
- package/lib/api/cardano/api/cardanoComposeTransaction.d.ts +0 -10
- package/lib/api/cardano/api/cardanoComposeTransaction.js +0 -84
- package/lib/api/cardano/api/cardanoGetAddress.d.ts +0 -34
- package/lib/api/cardano/api/cardanoGetAddress.js +0 -130
- package/lib/api/cardano/api/cardanoGetNativeScriptHash.d.ts +0 -12
- package/lib/api/cardano/api/cardanoGetNativeScriptHash.js +0 -66
- package/lib/api/cardano/api/cardanoGetPublicKey.d.ts +0 -22
- package/lib/api/cardano/api/cardanoGetPublicKey.js +0 -92
- package/lib/api/cardano/api/cardanoSignMessage.d.ts +0 -22
- package/lib/api/cardano/api/cardanoSignMessage.js +0 -90
- package/lib/api/cardano/api/cardanoSignTransaction.d.ts +0 -81
- package/lib/api/cardano/api/cardanoSignTransaction.js +0 -301
- package/lib/api/cardano/api/index.d.ts +0 -6
- package/lib/api/cardano/api/index.js +0 -6
- package/lib/api/cardano/cardanoAddressParameters.d.ts +0 -6
- package/lib/api/cardano/cardanoAddressParameters.js +0 -79
- package/lib/api/cardano/cardanoAuxiliaryData.d.ts +0 -4
- package/lib/api/cardano/cardanoAuxiliaryData.js +0 -74
- package/lib/api/cardano/cardanoCertificate.d.ts +0 -13
- package/lib/api/cardano/cardanoCertificate.js +0 -142
- package/lib/api/cardano/cardanoInputs.d.ts +0 -25
- package/lib/api/cardano/cardanoInputs.js +0 -39
- package/lib/api/cardano/cardanoOutputs.d.ts +0 -40
- package/lib/api/cardano/cardanoOutputs.js +0 -70
- package/lib/api/cardano/cardanoTokenBundle.d.ts +0 -12
- package/lib/api/cardano/cardanoTokenBundle.js +0 -21
- package/lib/api/cardano/cardanoUtils.d.ts +0 -17
- package/lib/api/cardano/cardanoUtils.js +0 -100
- package/lib/api/cardano/cardanoWitnesses.d.ts +0 -4
- package/lib/api/cardano/cardanoWitnesses.js +0 -47
- package/lib/api/changeLanguage.d.ts +0 -18
- package/lib/api/changeLanguage.js +0 -49
- package/lib/api/changePin.d.ts +0 -11
- package/lib/api/changePin.js +0 -27
- package/lib/api/changeWipeCode.d.ts +0 -11
- package/lib/api/changeWipeCode.js +0 -29
- package/lib/api/cipherKeyValue.d.ts +0 -17
- package/lib/api/cipherKeyValue.js +0 -58
- package/lib/api/common/AbstractMiscGetAddress.d.ts +0 -37
- package/lib/api/common/AbstractMiscGetAddress.js +0 -126
- package/lib/api/common/Discovery.d.ts +0 -33
- package/lib/api/common/Discovery.js +0 -119
- package/lib/api/common/paramsValidator.d.ts +0 -24
- package/lib/api/common/paramsValidator.js +0 -136
- package/lib/api/common/requestExistingAccounts.d.ts +0 -14
- package/lib/api/common/requestExistingAccounts.js +0 -20
- package/lib/api/composeTransaction.d.ts +0 -36
- package/lib/api/composeTransaction.js +0 -404
- package/lib/api/discoverAccounts.d.ts +0 -40
- package/lib/api/discoverAccounts.js +0 -360
- package/lib/api/ethereum/api/ethereumGetAddress.d.ts +0 -30
- package/lib/api/ethereum/api/ethereumGetAddress.js +0 -150
- package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +0 -52
- package/lib/api/ethereum/api/ethereumGetPublicKey.js +0 -100
- package/lib/api/ethereum/api/ethereumSignMessage.d.ts +0 -27
- package/lib/api/ethereum/api/ethereumSignMessage.js +0 -64
- package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +0 -83
- package/lib/api/ethereum/api/ethereumSignTransaction.js +0 -148
- package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +0 -117
- package/lib/api/ethereum/api/ethereumSignTypedData.js +0 -203
- package/lib/api/ethereum/api/ethereumVerifyMessage.d.ts +0 -12
- package/lib/api/ethereum/api/ethereumVerifyMessage.js +0 -35
- package/lib/api/ethereum/api/index.d.ts +0 -6
- package/lib/api/ethereum/api/index.js +0 -6
- package/lib/api/ethereum/ethereumDefinitions.d.ts +0 -53
- package/lib/api/ethereum/ethereumDefinitions.js +0 -135
- package/lib/api/ethereum/ethereumSignTx.d.ts +0 -16
- package/lib/api/ethereum/ethereumSignTx.js +0 -144
- package/lib/api/ethereum/ethereumSignTypedData.d.ts +0 -32
- package/lib/api/ethereum/ethereumSignTypedData.js +0 -175
- package/lib/api/evoluGetDelegatedIdentityKey.d.ts +0 -14
- package/lib/api/evoluGetDelegatedIdentityKey.js +0 -29
- package/lib/api/evoluGetNode.d.ts +0 -13
- package/lib/api/evoluGetNode.js +0 -29
- package/lib/api/evoluSignRegistrationRequest.d.ts +0 -16
- package/lib/api/evoluSignRegistrationRequest.js +0 -33
- package/lib/api/firmware/calculateFirmwareHash.d.ts +0 -18
- package/lib/api/firmware/calculateFirmwareHash.js +0 -56
- package/lib/api/firmware/calculateXPubHash.d.ts +0 -14
- package/lib/api/firmware/calculateXPubHash.js +0 -16
- package/lib/api/firmware/getBinary.d.ts +0 -14
- package/lib/api/firmware/getBinary.js +0 -33
- package/lib/api/firmware/index.d.ts +0 -6
- package/lib/api/firmware/index.js +0 -6
- package/lib/api/firmware/modifyFirmware.d.ts +0 -3
- package/lib/api/firmware/modifyFirmware.js +0 -13
- package/lib/api/firmware/parseFirmwareHeaders.d.ts +0 -4
- package/lib/api/firmware/parseFirmwareHeaders.js +0 -26
- package/lib/api/firmware/uploadFirmware.d.ts +0 -27
- package/lib/api/firmware/uploadFirmware.js +0 -99
- package/lib/api/firmware/verifyEntropy.d.ts +0 -25
- package/lib/api/firmware/verifyEntropy.js +0 -110
- package/lib/api/getAccountInfo.d.ts +0 -21
- package/lib/api/getAccountInfo.js +0 -253
- package/lib/api/getAddress.d.ts +0 -45
- package/lib/api/getAddress.js +0 -153
- package/lib/api/getCoinInfo.d.ts +0 -148
- package/lib/api/getCoinInfo.js +0 -25
- package/lib/api/getDeviceState.d.ts +0 -8
- package/lib/api/getDeviceState.js +0 -18
- package/lib/api/getFeatures.d.ts +0 -71
- package/lib/api/getFeatures.js +0 -22
- package/lib/api/getFirmwareHash.d.ts +0 -11
- package/lib/api/getFirmwareHash.js +0 -29
- package/lib/api/getNonce.d.ts +0 -10
- package/lib/api/getNonce.js +0 -18
- package/lib/api/getOwnershipId.d.ts +0 -17
- package/lib/api/getOwnershipId.js +0 -88
- package/lib/api/getOwnershipProof.d.ts +0 -17
- package/lib/api/getOwnershipProof.js +0 -95
- package/lib/api/getPublicKey.d.ts +0 -54
- package/lib/api/getPublicKey.js +0 -106
- package/lib/api/getSettings.d.ts +0 -24
- package/lib/api/getSettings.js +0 -21
- package/lib/api/index.d.ts +0 -62
- package/lib/api/index.js +0 -62
- package/lib/api/loadDevice.d.ts +0 -16
- package/lib/api/loadDevice.js +0 -46
- package/lib/api/monero/api/index.d.ts +0 -4
- package/lib/api/monero/api/index.js +0 -4
- package/lib/api/monero/api/moneroGetAddress.d.ts +0 -32
- package/lib/api/monero/api/moneroGetAddress.js +0 -117
- package/lib/api/monero/api/moneroGetWatchKey.d.ts +0 -14
- package/lib/api/monero/api/moneroGetWatchKey.js +0 -45
- package/lib/api/monero/api/moneroKeyImageSync.d.ts +0 -17
- package/lib/api/monero/api/moneroKeyImageSync.js +0 -128
- package/lib/api/monero/api/moneroSignTransaction.d.ts +0 -17
- package/lib/api/monero/api/moneroSignTransaction.js +0 -218
- package/lib/api/nostr/nostrGetPublicKey.d.ts +0 -15
- package/lib/api/nostr/nostrGetPublicKey.js +0 -38
- package/lib/api/nostr/nostrSignEvent.d.ts +0 -13
- package/lib/api/nostr/nostrSignEvent.js +0 -36
- package/lib/api/pingDevice.d.ts +0 -11
- package/lib/api/pingDevice.js +0 -29
- package/lib/api/pushTransaction.d.ts +0 -19
- package/lib/api/pushTransaction.js +0 -39
- package/lib/api/recoveryDevice.d.ts +0 -20
- package/lib/api/recoveryDevice.js +0 -52
- package/lib/api/requestLogin.d.ts +0 -14
- package/lib/api/requestLogin.js +0 -53
- package/lib/api/resetDevice.d.ts +0 -22
- package/lib/api/resetDevice.js +0 -133
- package/lib/api/ripple/api/index.d.ts +0 -2
- package/lib/api/ripple/api/index.js +0 -2
- package/lib/api/ripple/api/rippleGetAddress.d.ts +0 -17
- package/lib/api/ripple/api/rippleGetAddress.js +0 -22
- package/lib/api/ripple/api/rippleSignTransaction.d.ts +0 -13
- package/lib/api/ripple/api/rippleSignTransaction.js +0 -52
- package/lib/api/selectAccount.d.ts +0 -15
- package/lib/api/selectAccount.js +0 -42
- package/lib/api/setBrightness.d.ts +0 -12
- package/lib/api/setBrightness.js +0 -28
- package/lib/api/setBusy.d.ts +0 -11
- package/lib/api/setBusy.js +0 -31
- package/lib/api/showDeviceTutorial.d.ts +0 -11
- package/lib/api/showDeviceTutorial.js +0 -21
- package/lib/api/signMessage.d.ts +0 -25
- package/lib/api/signMessage.js +0 -75
- package/lib/api/signTransaction.d.ts +0 -199
- package/lib/api/signTransaction.js +0 -331
- package/lib/api/solana/api/index.d.ts +0 -4
- package/lib/api/solana/api/index.js +0 -4
- package/lib/api/solana/api/solanaComposeTransaction.d.ts +0 -33
- package/lib/api/solana/api/solanaComposeTransaction.js +0 -73
- package/lib/api/solana/api/solanaGetAddress.d.ts +0 -17
- package/lib/api/solana/api/solanaGetAddress.js +0 -22
- package/lib/api/solana/api/solanaGetPublicKey.d.ts +0 -32
- package/lib/api/solana/api/solanaGetPublicKey.js +0 -86
- package/lib/api/solana/api/solanaSignTransaction.d.ts +0 -41
- package/lib/api/solana/api/solanaSignTransaction.js +0 -204
- package/lib/api/solana/solanaDefinitions.d.ts +0 -9
- package/lib/api/solana/solanaDefinitions.js +0 -33
- package/lib/api/stellar/api/index.d.ts +0 -2
- package/lib/api/stellar/api/index.js +0 -2
- package/lib/api/stellar/api/stellarGetAddress.d.ts +0 -17
- package/lib/api/stellar/api/stellarGetAddress.js +0 -22
- package/lib/api/stellar/api/stellarSignTransaction.d.ts +0 -20
- package/lib/api/stellar/api/stellarSignTransaction.js +0 -65
- package/lib/api/stellar/stellarSignTx.d.ts +0 -7
- package/lib/api/stellar/stellarSignTx.js +0 -183
- package/lib/api/telemetryGet.d.ts +0 -14
- package/lib/api/telemetryGet.js +0 -26
- package/lib/api/tezos/api/index.d.ts +0 -3
- package/lib/api/tezos/api/index.js +0 -3
- package/lib/api/tezos/api/tezosGetAddress.d.ts +0 -17
- package/lib/api/tezos/api/tezosGetAddress.js +0 -22
- package/lib/api/tezos/api/tezosGetPublicKey.d.ts +0 -28
- package/lib/api/tezos/api/tezosGetPublicKey.js +0 -84
- package/lib/api/tezos/api/tezosSignTransaction.d.ts +0 -14
- package/lib/api/tezos/api/tezosSignTransaction.js +0 -30
- package/lib/api/tezos/tezosSignTx.d.ts +0 -71
- package/lib/api/tezos/tezosSignTx.js +0 -204
- package/lib/api/thpGetCredentials.d.ts +0 -13
- package/lib/api/thpGetCredentials.js +0 -30
- package/lib/api/thpRemoveCredentials.d.ts +0 -15
- package/lib/api/thpRemoveCredentials.js +0 -44
- package/lib/api/tron/api/index.d.ts +0 -3
- package/lib/api/tron/api/index.js +0 -3
- package/lib/api/tron/api/tronComposeTransaction.d.ts +0 -17
- package/lib/api/tron/api/tronComposeTransaction.js +0 -52
- package/lib/api/tron/api/tronGetAddress.d.ts +0 -17
- package/lib/api/tron/api/tronGetAddress.js +0 -22
- package/lib/api/tron/api/tronSignTransaction.d.ts +0 -20
- package/lib/api/tron/api/tronSignTransaction.js +0 -137
- package/lib/api/tron/tronEncode.d.ts +0 -11
- package/lib/api/tron/tronEncode.js +0 -157
- package/lib/api/tron/tronProtobuf.d.ts +0 -5
- package/lib/api/tron/tronProtobuf.js +0 -28
- package/lib/api/unlockPath.d.ts +0 -12
- package/lib/api/unlockPath.js +0 -33
- package/lib/api/verifyMessage.d.ts +0 -16
- package/lib/api/verifyMessage.js +0 -46
- package/lib/api/wipeDevice.d.ts +0 -21
- package/lib/api/wipeDevice.js +0 -49
- package/lib/backend/BackendManager.d.ts +0 -30
- package/lib/backend/BackendManager.js +0 -145
- package/lib/backend/Blockchain.d.ts +0 -81
- package/lib/backend/Blockchain.js +0 -235
- package/lib/backend/BlockchainLink.d.ts +0 -10
- package/lib/backend/BlockchainLink.js +0 -19
- package/lib/backend/fees/BitcoinFeeLevels.d.ts +0 -19
- package/lib/backend/fees/BitcoinFeeLevels.js +0 -44
- package/lib/backend/fees/EthereumFeeLevels.d.ts +0 -17
- package/lib/backend/fees/EthereumFeeLevels.js +0 -63
- package/lib/backend/fees/MiscFeeLevels.d.ts +0 -18
- package/lib/backend/fees/MiscFeeLevels.js +0 -30
- package/lib/backend/fees/index.d.ts +0 -5
- package/lib/backend/fees/index.js +0 -31
- package/lib/core/AbstractMethod.d.ts +0 -63
- package/lib/core/AbstractMethod.js +0 -189
- package/lib/core/index.d.ts +0 -29
- package/lib/core/index.js +0 -805
- package/lib/core/method.d.ts +0 -3
- package/lib/core/method.js +0 -19
- package/lib/core/method.native.d.ts +0 -2
- package/lib/core/method.native.js +0 -29
- package/lib/core/onCallFirmwareUpdate.d.ts +0 -42
- package/lib/core/onCallFirmwareUpdate.js +0 -436
- package/lib/data/coinInfo.d.ts +0 -101
- package/lib/data/coinInfo.js +0 -195
- package/lib/data/config.d.ts +0 -8
- package/lib/data/config.js +0 -273
- package/lib/data/defaultFeeLevels.d.ts +0 -18
- package/lib/data/defaultFeeLevels.js +0 -200
- package/lib/data/enabledNetworksStore.d.ts +0 -5
- package/lib/data/enabledNetworksStore.js +0 -20
- package/lib/data/firmwareInfo.d.ts +0 -55
- package/lib/data/firmwareInfo.js +0 -413
- package/lib/data/firmwareReleaseStore.d.ts +0 -10
- package/lib/data/firmwareReleaseStore.js +0 -16
- package/lib/data/localFirmwareStore.d.ts +0 -3
- package/lib/data/localFirmwareStore.js +0 -8
- package/lib/data/protobufLoader.d.ts +0 -1
- package/lib/data/protobufLoader.js +0 -30
- package/lib/data/settingsStore.d.ts +0 -6
- package/lib/data/settingsStore.js +0 -21
- package/lib/device/Device.d.ts +0 -259
- package/lib/device/Device.js +0 -765
- package/lib/device/DeviceCommands.d.ts +0 -87
- package/lib/device/DeviceCommands.js +0 -248
- package/lib/device/DeviceCurrentSession.d.ts +0 -750
- package/lib/device/DeviceCurrentSession.js +0 -239
- package/lib/device/DeviceList.d.ts +0 -75
- package/lib/device/DeviceList.js +0 -243
- package/lib/device/TransportList.d.ts +0 -3
- package/lib/device/TransportList.js +0 -13
- package/lib/device/TransportManager.d.ts +0 -33
- package/lib/device/TransportManager.js +0 -144
- package/lib/device/calculateRevisionForDevice.d.ts +0 -10
- package/lib/device/calculateRevisionForDevice.js +0 -19
- package/lib/device/checkFirmwareRevision.d.ts +0 -22
- package/lib/device/checkFirmwareRevision.js +0 -104
- package/lib/device/resolveDescriptorForTaproot.d.ts +0 -17
- package/lib/device/resolveDescriptorForTaproot.js +0 -27
- package/lib/device/thp/handshake.d.ts +0 -3
- package/lib/device/thp/handshake.js +0 -100
- package/lib/device/thp/index.d.ts +0 -5
- package/lib/device/thp/index.js +0 -65
- package/lib/device/thp/pairing.d.ts +0 -16
- package/lib/device/thp/pairing.js +0 -242
- package/lib/device/thp/session.d.ts +0 -2
- package/lib/device/thp/session.js +0 -27
- package/lib/device/thp/thpCall.d.ts +0 -31
- package/lib/device/thp/thpCall.js +0 -58
- package/lib/device/validateMessageSize.d.ts +0 -2
- package/lib/device/validateMessageSize.js +0 -9
- package/lib/device/workflow/changeLanguage.d.ts +0 -18
- package/lib/device/workflow/changeLanguage.js +0 -62
- package/lib/device/workflow/checkFirmwareHash.d.ts +0 -12
- package/lib/device/workflow/checkFirmwareHash.js +0 -86
- package/lib/device/workflow/checkFirmwareHashWithRetries.d.ts +0 -8
- package/lib/device/workflow/checkFirmwareHashWithRetries.js +0 -36
- package/lib/device/workflow/handshake.d.ts +0 -13
- package/lib/device/workflow/handshake.js +0 -55
- package/lib/device/workflow/trezorPushNotification.d.ts +0 -5
- package/lib/device/workflow/trezorPushNotification.js +0 -73
- package/lib/device/workflow/validateState.d.ts +0 -2
- package/lib/device/workflow/validateState.js +0 -152
- package/lib/events/ui-promise.d.ts +0 -20
- package/lib/events/ui-promise.js +0 -1
- package/lib/impl/core-in-module.d.ts +0 -33
- package/lib/impl/core-in-module.js +0 -194
- package/lib/types/idevice.d.ts +0 -110
- package/lib/types/idevice.js +0 -1
- package/lib/types/typed-call-provider.d.ts +0 -29
- package/lib/types/typed-call-provider.js +0 -1
- package/lib/types/workflow.d.ts +0 -16
- package/lib/types/workflow.js +0 -1
- package/lib/utils/accountUtils.d.ts +0 -10
- package/lib/utils/accountUtils.js +0 -90
- package/lib/utils/addressUtils.d.ts +0 -2
- package/lib/utils/addressUtils.js +0 -24
- package/lib/utils/assetUtils.d.ts +0 -13
- package/lib/utils/assetUtils.js +0 -55
- package/lib/utils/assets.browser.d.ts +0 -1
- package/lib/utils/assets.browser.js +0 -1
- package/lib/utils/assets.d.ts +0 -2
- package/lib/utils/assets.js +0 -13
- package/lib/utils/assets.native.d.ts +0 -2
- package/lib/utils/assets.native.js +0 -23
- package/lib/utils/assetsTypes.d.ts +0 -5
- package/lib/utils/assetsTypes.js +0 -1
- package/lib/utils/buildOutputDescriptor.d.ts +0 -20
- package/lib/utils/buildOutputDescriptor.js +0 -67
- package/lib/utils/deviceFeaturesUtils.d.ts +0 -7
- package/lib/utils/deviceFeaturesUtils.js +0 -109
- package/lib/utils/ethereumUtils.d.ts +0 -3
- package/lib/utils/ethereumUtils.js +0 -7
- package/lib/utils/firmwareReleaseConfigUtils.d.ts +0 -19
- package/lib/utils/firmwareReleaseConfigUtils.js +0 -131
- package/lib/utils/firmwareUtils.d.ts +0 -15
- package/lib/utils/firmwareUtils.js +0 -57
- package/lib/utils/formatUtils.d.ts +0 -13
- package/lib/utils/formatUtils.js +0 -45
- package/lib/utils/hdnodeUtils.d.ts +0 -6
- package/lib/utils/hdnodeUtils.js +0 -62
- package/lib/utils/pathUtils.d.ts +0 -1
- package/lib/utils/pathUtils.js +0 -1
- package/lib/utils/paymentRequest.d.ts +0 -8
- package/lib/utils/paymentRequest.js +0 -25
- package/lib/utils/uiPromiseManager.d.ts +0 -8
- package/lib/utils/uiPromiseManager.js +0 -51
- package/lib/workers/workers.browser.d.ts +0 -10
- package/lib/workers/workers.browser.js +0 -16
- package/lib/workers/workers.d.ts +0 -10
- package/lib/workers/workers.js +0 -8
- package/lib/workers/workers.native.d.ts +0 -7
- package/lib/workers/workers.native.js +0 -7
package/lib/device/Device.js
DELETED
|
@@ -1,765 +0,0 @@
|
|
|
1
|
-
import { DEVICE, ERRORS, FIRMWARE, UI_REQUEST } from "@trezor/connect-common";
|
|
2
|
-
import { DeviceModelInternal, getFirmwareOrBootloaderVersionArray, getFirmwareVersionArray, models } from "@trezor/device-utils";
|
|
3
|
-
import { thp as protocolThp, v1 as protocolV1, v2 as protocolV2 } from "@trezor/protocol";
|
|
4
|
-
import { TRANSPORT, TRANSPORT_ERROR } from "@trezor/transport-common";
|
|
5
|
-
import { TypedEmitter, cloneObject, createDeferred, deepEqual, isArrayMember, versionUtils } from "@trezor/utils";
|
|
6
|
-
import { DeviceCommands } from "./DeviceCommands.js";
|
|
7
|
-
import { DeviceCurrentSession } from "./DeviceCurrentSession.js";
|
|
8
|
-
import { checkFirmwareRevision } from "./checkFirmwareRevision.js";
|
|
9
|
-
import { abortThpWorkflow, getThpChannel } from "./thp/index.js";
|
|
10
|
-
import { getAllNetworks } from "../data/coinInfo.js";
|
|
11
|
-
import { getFirmwareReleaseConfigInfo, getFirmwareStatus, getReleaseByVersion } from "../data/firmwareInfo.js";
|
|
12
|
-
import * as settingsStore from "../data/settingsStore.js";
|
|
13
|
-
import { getReleaseAsset } from "../utils/assetUtils.js";
|
|
14
|
-
import { ensureInternalModelFeature, getUnavailableCapabilities, parseCapabilities, parseRevision } from "../utils/deviceFeaturesUtils.js";
|
|
15
|
-
import { getFirmwareMode, getFirmwareType, isProductionFirmwareChannel } from "../utils/firmwareUtils.js";
|
|
16
|
-
import { changeLanguage } from "./workflow/changeLanguage.js";
|
|
17
|
-
import { checkFirmwareHashWithRetries } from "./workflow/checkFirmwareHashWithRetries.js";
|
|
18
|
-
import { handshakeCancel } from "./workflow/handshake.js";
|
|
19
|
-
export class Device extends TypedEmitter {
|
|
20
|
-
transport;
|
|
21
|
-
thp;
|
|
22
|
-
descriptor;
|
|
23
|
-
sessionAcquired;
|
|
24
|
-
_protocol;
|
|
25
|
-
get protocol() {
|
|
26
|
-
return this._protocol;
|
|
27
|
-
}
|
|
28
|
-
getThpState() {
|
|
29
|
-
return this.thp;
|
|
30
|
-
}
|
|
31
|
-
unreadableError;
|
|
32
|
-
_firmwareStatus;
|
|
33
|
-
get firmwareStatus() {
|
|
34
|
-
return this._firmwareStatus;
|
|
35
|
-
}
|
|
36
|
-
_currentRelease;
|
|
37
|
-
get currentRelease() {
|
|
38
|
-
return this._currentRelease;
|
|
39
|
-
}
|
|
40
|
-
_firmwareReleaseConfigInfo;
|
|
41
|
-
get firmwareReleaseConfigInfo() {
|
|
42
|
-
return this._firmwareReleaseConfigInfo;
|
|
43
|
-
}
|
|
44
|
-
_features;
|
|
45
|
-
get features() {
|
|
46
|
-
return this._features;
|
|
47
|
-
}
|
|
48
|
-
wasUsedElsewhere = false;
|
|
49
|
-
acquirePromise;
|
|
50
|
-
releasePromise;
|
|
51
|
-
runAbort;
|
|
52
|
-
runPromise;
|
|
53
|
-
keepTransportSession = false;
|
|
54
|
-
currentSession;
|
|
55
|
-
instance = 0;
|
|
56
|
-
state = [];
|
|
57
|
-
busy;
|
|
58
|
-
_unavailableCapabilities = {};
|
|
59
|
-
get unavailableCapabilities() {
|
|
60
|
-
return this._unavailableCapabilities;
|
|
61
|
-
}
|
|
62
|
-
_firmwareType;
|
|
63
|
-
get firmwareType() {
|
|
64
|
-
return this._firmwareType;
|
|
65
|
-
}
|
|
66
|
-
get possibleHIDdevice() {
|
|
67
|
-
return this.descriptor.type === 0 || this.descriptor.type === 2;
|
|
68
|
-
}
|
|
69
|
-
get possibleT1() {
|
|
70
|
-
return (this.descriptor.type ?? 0) <= 2;
|
|
71
|
-
}
|
|
72
|
-
name = 'Trezor';
|
|
73
|
-
color;
|
|
74
|
-
availableTranslations = {};
|
|
75
|
-
authenticityChecks = {
|
|
76
|
-
firmwareRevision: null,
|
|
77
|
-
firmwareHash: null
|
|
78
|
-
};
|
|
79
|
-
uniquePath;
|
|
80
|
-
createLogger;
|
|
81
|
-
logger;
|
|
82
|
-
lifecycle = new TypedEmitter();
|
|
83
|
-
lastEmittedMessage;
|
|
84
|
-
sessionDfd;
|
|
85
|
-
constructor({
|
|
86
|
-
id,
|
|
87
|
-
transport,
|
|
88
|
-
descriptor,
|
|
89
|
-
createLogger
|
|
90
|
-
}) {
|
|
91
|
-
super();
|
|
92
|
-
this._protocol = protocolV1;
|
|
93
|
-
this.createLogger = createLogger;
|
|
94
|
-
this.logger = createLogger('Device');
|
|
95
|
-
this.uniquePath = id;
|
|
96
|
-
this.transport = transport;
|
|
97
|
-
this.descriptor = {
|
|
98
|
-
id: descriptor.id,
|
|
99
|
-
apiType: descriptor.apiType,
|
|
100
|
-
type: descriptor.type,
|
|
101
|
-
path: descriptor.path,
|
|
102
|
-
model: descriptor.model
|
|
103
|
-
};
|
|
104
|
-
this.sessionAcquired = null;
|
|
105
|
-
transport.on(TRANSPORT.STOPPED, this.onTransportStopped);
|
|
106
|
-
transport.deviceEvents.on(this.descriptor.path, this.onTransportDeviceEvent);
|
|
107
|
-
}
|
|
108
|
-
get transportPath() {
|
|
109
|
-
return this.descriptor.path;
|
|
110
|
-
}
|
|
111
|
-
onTransportStopped = () => this.disconnect();
|
|
112
|
-
onTransportDeviceEvent = event => {
|
|
113
|
-
switch (event.type) {
|
|
114
|
-
case TRANSPORT.DEVICE_SESSION_CHANGED:
|
|
115
|
-
return this.updateDescriptor(event.descriptor);
|
|
116
|
-
case TRANSPORT.DEVICE_REQUEST_RELEASE:
|
|
117
|
-
return this.usedElsewhere();
|
|
118
|
-
case TRANSPORT.DEVICE_DISCONNECTED:
|
|
119
|
-
{
|
|
120
|
-
return this.disconnect();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
getSessionChangePromise() {
|
|
125
|
-
if (!this.sessionDfd) {
|
|
126
|
-
this.sessionDfd = createDeferred();
|
|
127
|
-
this.sessionDfd.promise.catch(() => {}).finally(() => {
|
|
128
|
-
this.sessionDfd = undefined;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return this.sessionDfd.promise;
|
|
132
|
-
}
|
|
133
|
-
async waitAndCompareSession(response, sessionPromise) {
|
|
134
|
-
if (response.success) {
|
|
135
|
-
try {
|
|
136
|
-
if ((await sessionPromise) !== response.payload) {
|
|
137
|
-
return {
|
|
138
|
-
success: false,
|
|
139
|
-
error: {
|
|
140
|
-
code: TRANSPORT_ERROR.SESSION_WRONG_PREVIOUS
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
} catch {
|
|
145
|
-
return {
|
|
146
|
-
success: false,
|
|
147
|
-
error: {
|
|
148
|
-
code: TRANSPORT_ERROR.DEVICE_DISCONNECTED_DURING_ACTION
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return response;
|
|
154
|
-
}
|
|
155
|
-
acquire() {
|
|
156
|
-
const sessionPromise = this.getSessionChangePromise();
|
|
157
|
-
const previous = this.transport.getDescriptor(this.descriptor.path)?.session ?? null;
|
|
158
|
-
this.acquirePromise = this.transport.acquire({
|
|
159
|
-
input: {
|
|
160
|
-
path: this.descriptor.path,
|
|
161
|
-
previous
|
|
162
|
-
}
|
|
163
|
-
}).then(result => this.waitAndCompareSession(result, sessionPromise)).then(result => {
|
|
164
|
-
if (result.success) {
|
|
165
|
-
this.wasUsedElsewhere = false;
|
|
166
|
-
this.sessionAcquired = result.payload;
|
|
167
|
-
this.currentSession = new DeviceCurrentSession(this, this.transport, this.sessionAcquired, this.createLogger('DeviceCommands'));
|
|
168
|
-
return result;
|
|
169
|
-
} else {
|
|
170
|
-
throw new Error(result.error.code);
|
|
171
|
-
}
|
|
172
|
-
}).finally(() => {
|
|
173
|
-
this.acquirePromise = undefined;
|
|
174
|
-
});
|
|
175
|
-
return this.acquirePromise;
|
|
176
|
-
}
|
|
177
|
-
reset() {
|
|
178
|
-
this.logger.info(`Resetting Features and ThpState`);
|
|
179
|
-
this._features = undefined;
|
|
180
|
-
this._protocol = protocolV1;
|
|
181
|
-
this.thp?.resetState();
|
|
182
|
-
this.thp = undefined;
|
|
183
|
-
this.lastEmittedMessage = undefined;
|
|
184
|
-
}
|
|
185
|
-
setBusy(value) {
|
|
186
|
-
this.busy = value;
|
|
187
|
-
}
|
|
188
|
-
release() {
|
|
189
|
-
if (!this.sessionAcquired || this.keepTransportSession || this.releasePromise) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const sessionPromise = this.getSessionChangePromise();
|
|
193
|
-
this.releasePromise = this.transport.release({
|
|
194
|
-
session: this.sessionAcquired,
|
|
195
|
-
path: this.descriptor.path
|
|
196
|
-
}).then(result => this.waitAndCompareSession(result, sessionPromise)).then(result => {
|
|
197
|
-
if (result.success) {
|
|
198
|
-
this.sessionAcquired = null;
|
|
199
|
-
}
|
|
200
|
-
return result;
|
|
201
|
-
}).finally(() => {
|
|
202
|
-
this.releasePromise = undefined;
|
|
203
|
-
});
|
|
204
|
-
return this.releasePromise;
|
|
205
|
-
}
|
|
206
|
-
setupThp() {
|
|
207
|
-
this.logger.info('Setup THP device');
|
|
208
|
-
this._protocol = protocolV2;
|
|
209
|
-
if (this.transport.name === 'BridgeTransport' && !versionUtils.isNewerOrEqual(this.transport.version, '3.0.0')) {
|
|
210
|
-
this.unreadableError = 'THP incompatible with bridge ' + this.transport.version;
|
|
211
|
-
} else {
|
|
212
|
-
try {
|
|
213
|
-
this.thp = new protocolThp.ThpState();
|
|
214
|
-
} catch (error) {
|
|
215
|
-
this.unreadableError = error.message;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
async handshake() {
|
|
220
|
-
if (this.isUsedElsewhere()) {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
await this.run();
|
|
225
|
-
} catch (error) {
|
|
226
|
-
this.logger.warn(`device.run error.message: ${error.message}, code: ${error.code}`);
|
|
227
|
-
if (error.code === 'Device_NotFound' || error.code === 'Device_Disconnected' || error.message === TRANSPORT_ERROR.DEVICE_NOT_FOUND || error.message === TRANSPORT_ERROR.DEVICE_DISCONNECTED_DURING_ACTION || error.message === TRANSPORT_ERROR.HTTP_ERROR) {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
if (this.possibleHIDdevice && error.message === TRANSPORT_ERROR.INTERFACE_UNABLE_TO_OPEN_DEVICE || error.message === TRANSPORT_ERROR.LIBUSB_ERROR_ACCESS) {
|
|
231
|
-
this.unreadableError = error.message;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
async updateDescriptor(descriptor) {
|
|
237
|
-
this.sessionDfd?.resolve(descriptor.session);
|
|
238
|
-
await Promise.all([this.acquirePromise, this.releasePromise]);
|
|
239
|
-
if (descriptor.session && descriptor.session !== this.sessionAcquired) {
|
|
240
|
-
this.usedElsewhere();
|
|
241
|
-
}
|
|
242
|
-
if (!descriptor.session) {
|
|
243
|
-
this.keepTransportSession = false;
|
|
244
|
-
}
|
|
245
|
-
this.emitDeviceChanged();
|
|
246
|
-
}
|
|
247
|
-
emitDeviceChanged() {
|
|
248
|
-
const message = this.toMessageObject();
|
|
249
|
-
if (this.lastEmittedMessage && deepEqual(this.lastEmittedMessage, message)) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
this.lastEmittedMessage = cloneObject(message);
|
|
253
|
-
this.lifecycle.emit(DEVICE.CHANGED);
|
|
254
|
-
}
|
|
255
|
-
startPiggybackAck() {
|
|
256
|
-
this.logger.debug('start PiggybackAck');
|
|
257
|
-
this.thp?.enablePiggybackAck(true);
|
|
258
|
-
}
|
|
259
|
-
async stopPiggybackAck() {
|
|
260
|
-
if (this.currentSession && this.thp?.isPiggybackAckEnabled) {
|
|
261
|
-
this.logger.debug('stop PiggybackAck');
|
|
262
|
-
await this.currentSession.send('ThpAck', {});
|
|
263
|
-
this.thp?.enablePiggybackAck(false);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
run(fn, options = {}) {
|
|
267
|
-
if (this.runPromise) {
|
|
268
|
-
this.logger.warn('Previous call is still running');
|
|
269
|
-
throw ERRORS.TypedError('Device_CallInProgress');
|
|
270
|
-
}
|
|
271
|
-
const wasUnacquired = this.isUnacquired();
|
|
272
|
-
this.runAbort = new AbortController();
|
|
273
|
-
const {
|
|
274
|
-
signal
|
|
275
|
-
} = this.runAbort;
|
|
276
|
-
this.runPromise = Promise.race([this._runInner(fn, options, signal), new Promise((_, reject) => {
|
|
277
|
-
signal.addEventListener('abort', () => reject(signal.reason));
|
|
278
|
-
})]).catch(async err => {
|
|
279
|
-
this.keepTransportSession = false;
|
|
280
|
-
await this.acquirePromise;
|
|
281
|
-
await this.stopPiggybackAck();
|
|
282
|
-
await this.release();
|
|
283
|
-
throw err;
|
|
284
|
-
}).finally(() => {
|
|
285
|
-
this.runAbort = undefined;
|
|
286
|
-
this.runPromise = undefined;
|
|
287
|
-
}).then(() => {
|
|
288
|
-
if (wasUnacquired && !this.isUnacquired()) {
|
|
289
|
-
this.lifecycle.emit(DEVICE.CONNECT);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
return this.runPromise;
|
|
293
|
-
}
|
|
294
|
-
async interrupt(reason) {
|
|
295
|
-
await abortThpWorkflow(this);
|
|
296
|
-
await this.currentSession?.abort(reason);
|
|
297
|
-
this.runAbort?.abort(reason);
|
|
298
|
-
await this.currentRun;
|
|
299
|
-
}
|
|
300
|
-
get currentRun() {
|
|
301
|
-
return this.runPromise?.catch(() => {});
|
|
302
|
-
}
|
|
303
|
-
usedElsewhere() {
|
|
304
|
-
this.wasUsedElsewhere = true;
|
|
305
|
-
if (!this.sessionAcquired) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
this.transport.releaseDevice(this.sessionAcquired);
|
|
309
|
-
this.sessionAcquired = null;
|
|
310
|
-
this.logger.debug('interruptionFromOutside');
|
|
311
|
-
this.runAbort?.abort(ERRORS.TypedError('Device_UsedElsewhere'));
|
|
312
|
-
}
|
|
313
|
-
async _runInner(fn, options, abortSignal) {
|
|
314
|
-
if (this.releasePromise) {
|
|
315
|
-
await this.releasePromise;
|
|
316
|
-
}
|
|
317
|
-
const acquireNeeded = !this.isUsedHere() || this.currentSession?.isDisposed();
|
|
318
|
-
if (acquireNeeded) {
|
|
319
|
-
await this.acquire();
|
|
320
|
-
}
|
|
321
|
-
if (abortSignal.aborted) throw abortSignal.reason;
|
|
322
|
-
const {
|
|
323
|
-
staticSessionId,
|
|
324
|
-
deriveCardano
|
|
325
|
-
} = this.getState() || {};
|
|
326
|
-
if (acquireNeeded || !staticSessionId || !deriveCardano && options.useCardanoDerivation) {
|
|
327
|
-
try {
|
|
328
|
-
await handshakeCancel({
|
|
329
|
-
device: this,
|
|
330
|
-
logger: this.logger,
|
|
331
|
-
signal: abortSignal
|
|
332
|
-
});
|
|
333
|
-
if (this.protocol.name === 'v2') {
|
|
334
|
-
const withInteraction = !!fn;
|
|
335
|
-
this.busy = await getThpChannel(this, withInteraction);
|
|
336
|
-
this.updateNameAndColor();
|
|
337
|
-
if (!this.busy) {
|
|
338
|
-
await this.getFeatures();
|
|
339
|
-
}
|
|
340
|
-
} else if (fn) {
|
|
341
|
-
await this.initialize(!!options.useCardanoDerivation);
|
|
342
|
-
} else {
|
|
343
|
-
await this.getFeatures();
|
|
344
|
-
}
|
|
345
|
-
} catch (error) {
|
|
346
|
-
this.logger.warn('Device._runInner error: ', error.message);
|
|
347
|
-
if (error.code === 'Failure_Busy') {
|
|
348
|
-
this.busy = 'busy';
|
|
349
|
-
}
|
|
350
|
-
if (error.code === 'ThpDeviceLocked') {
|
|
351
|
-
this.busy = 'pin-locked';
|
|
352
|
-
}
|
|
353
|
-
if (error.code === 'Device_ThpPairingTagInvalid' || error.code === 'Failure_ActionCancelled') {
|
|
354
|
-
return Promise.reject(error);
|
|
355
|
-
}
|
|
356
|
-
return Promise.reject(ERRORS.TypedError('Device_InitializeFailed', `Initialize failed: ${error.message}${error.code ? `, code: ${error.code}` : ''}`));
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
if (!options.skipFirmwareChecks) {
|
|
360
|
-
await checkFirmwareHashWithRetries({
|
|
361
|
-
device: this,
|
|
362
|
-
logger: this.logger
|
|
363
|
-
});
|
|
364
|
-
await this.checkFirmwareRevisionWithRetries();
|
|
365
|
-
}
|
|
366
|
-
if (!options.skipLanguageChecks && this.features?.language && !this.features.language_version_matches && this.atLeast('2.7.0')) {
|
|
367
|
-
this.logger.info('language version mismatch. silently updating...');
|
|
368
|
-
try {
|
|
369
|
-
await changeLanguage({
|
|
370
|
-
device: this,
|
|
371
|
-
language: this.features.language
|
|
372
|
-
});
|
|
373
|
-
} catch (err) {
|
|
374
|
-
this.logger.error('change language failed silently', err);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
if (options.keepSession) {
|
|
378
|
-
this.keepTransportSession = true;
|
|
379
|
-
}
|
|
380
|
-
if (fn) {
|
|
381
|
-
await fn();
|
|
382
|
-
if (!options.skipFinalReload) {
|
|
383
|
-
await this.getFeatures();
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (!this.keepTransportSession && typeof options.keepSession !== 'boolean' || options.keepSession === false) {
|
|
387
|
-
this.keepTransportSession = false;
|
|
388
|
-
await this.stopPiggybackAck();
|
|
389
|
-
await this.release();
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
getCurrentSession() {
|
|
393
|
-
if (!this.currentSession) {
|
|
394
|
-
throw ERRORS.TypedError('Runtime', `Device: commands not defined`);
|
|
395
|
-
}
|
|
396
|
-
return this.currentSession;
|
|
397
|
-
}
|
|
398
|
-
getCommands() {
|
|
399
|
-
return DeviceCommands(this.getCurrentSession());
|
|
400
|
-
}
|
|
401
|
-
setInstance(instance = 0) {
|
|
402
|
-
if (this.instance !== instance) {
|
|
403
|
-
if (this.keepTransportSession) {
|
|
404
|
-
this.sessionAcquired = null;
|
|
405
|
-
this.keepTransportSession = false;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
this.instance = instance;
|
|
409
|
-
}
|
|
410
|
-
getInstance() {
|
|
411
|
-
return this.instance;
|
|
412
|
-
}
|
|
413
|
-
getState() {
|
|
414
|
-
return this.state[this.instance];
|
|
415
|
-
}
|
|
416
|
-
setState(state) {
|
|
417
|
-
if (!state) {
|
|
418
|
-
delete this.state[this.instance];
|
|
419
|
-
} else {
|
|
420
|
-
const prevState = this.state[this.instance];
|
|
421
|
-
const newState = {
|
|
422
|
-
...prevState,
|
|
423
|
-
...state
|
|
424
|
-
};
|
|
425
|
-
this.state[this.instance] = newState;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
async initialize(useCardanoDerivation) {
|
|
429
|
-
let payload;
|
|
430
|
-
if (this.features) {
|
|
431
|
-
const {
|
|
432
|
-
sessionId,
|
|
433
|
-
deriveCardano
|
|
434
|
-
} = this.getState() || {};
|
|
435
|
-
payload = {
|
|
436
|
-
derive_cardano: deriveCardano || useCardanoDerivation
|
|
437
|
-
};
|
|
438
|
-
if (sessionId) {
|
|
439
|
-
payload.session_id = sessionId;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
const {
|
|
443
|
-
message
|
|
444
|
-
} = await this.getCurrentSession().typedCall('Initialize', 'Features', payload);
|
|
445
|
-
this._updateFeatures(message);
|
|
446
|
-
await this._updateCurrentRelease(message);
|
|
447
|
-
this.setState({
|
|
448
|
-
deriveCardano: payload?.derive_cardano
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
async getFeatures() {
|
|
452
|
-
const {
|
|
453
|
-
message
|
|
454
|
-
} = await this.getCurrentSession().typedCall('GetFeatures', 'Features', {});
|
|
455
|
-
this._updateFeatures(message);
|
|
456
|
-
await this._updateCurrentRelease(message);
|
|
457
|
-
}
|
|
458
|
-
getAuthenticityChecks() {
|
|
459
|
-
return this.authenticityChecks;
|
|
460
|
-
}
|
|
461
|
-
setAuthenticityChecks(firmwareHash) {
|
|
462
|
-
this.authenticityChecks.firmwareHash = firmwareHash;
|
|
463
|
-
}
|
|
464
|
-
async checkFirmwareRevisionWithRetries() {
|
|
465
|
-
const lastResult = this.authenticityChecks.firmwareRevision;
|
|
466
|
-
const notDoneYet = lastResult === null;
|
|
467
|
-
const wasError = lastResult !== null && !lastResult.success;
|
|
468
|
-
const wasErrorRetriable = wasError && isArrayMember(lastResult.error, FIRMWARE.REVISION_CHECK_RETRIABLE_ERRORS);
|
|
469
|
-
if (notDoneYet || wasErrorRetriable) {
|
|
470
|
-
await this.checkFirmwareRevision();
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
async checkFirmwareRevision() {
|
|
474
|
-
const firmwareVersion = this.getVersion();
|
|
475
|
-
if (!firmwareVersion || !this.features || !this.firmwareType) {
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
if (this.features?.bootloader_mode === true) {
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
const release = getReleaseAsset(this.features.internal_model, firmwareVersion, this.firmwareType);
|
|
482
|
-
const result = await checkFirmwareRevision({
|
|
483
|
-
internalModel: this.features.internal_model,
|
|
484
|
-
firmwareVersion,
|
|
485
|
-
deviceRevision: this.features.revision,
|
|
486
|
-
expectedRevision: release?.firmware_revision,
|
|
487
|
-
deviceBootloaderHash: this.features.bootloader_hash,
|
|
488
|
-
expectedBootloaderHash: release?.bootloader_hash,
|
|
489
|
-
firmwareType: this.firmwareType
|
|
490
|
-
});
|
|
491
|
-
this.authenticityChecks = {
|
|
492
|
-
...this.authenticityChecks,
|
|
493
|
-
firmwareRevision: result
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
async _updateCurrentRelease(feat) {
|
|
497
|
-
const firmwareVersion = getFirmwareVersionArray({
|
|
498
|
-
features: feat
|
|
499
|
-
});
|
|
500
|
-
const newFirmwareType = getFirmwareType(feat);
|
|
501
|
-
if (!firmwareVersion) {
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
if (this._currentRelease && newFirmwareType === this.firmwareType && versionUtils.isEqual(this._currentRelease.version, firmwareVersion) && isProductionFirmwareChannel(settingsStore.get('firmwareChannel'))) {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
const release = await getReleaseByVersion(feat, firmwareVersion, newFirmwareType);
|
|
508
|
-
this._currentRelease = release;
|
|
509
|
-
this.availableTranslations = this._currentRelease?.translations ?? {};
|
|
510
|
-
}
|
|
511
|
-
_updateFeatures(feat) {
|
|
512
|
-
const capabilities = parseCapabilities(feat);
|
|
513
|
-
feat.capabilities = capabilities;
|
|
514
|
-
if (this.features?.session_id && !feat.session_id) {
|
|
515
|
-
feat.session_id = this.features.session_id;
|
|
516
|
-
}
|
|
517
|
-
feat.unlocked = feat.unlocked ?? true;
|
|
518
|
-
const revision = parseRevision(feat);
|
|
519
|
-
feat.revision = revision;
|
|
520
|
-
if (!feat.model && feat.major_version === 1) {
|
|
521
|
-
feat.model = '1';
|
|
522
|
-
}
|
|
523
|
-
if (!feat.internal_model || !DeviceModelInternal[feat.internal_model]) {
|
|
524
|
-
feat.internal_model = ensureInternalModelFeature(feat.model);
|
|
525
|
-
}
|
|
526
|
-
const version = this.getVersion();
|
|
527
|
-
const newVersion = getFirmwareOrBootloaderVersionArray(feat);
|
|
528
|
-
this.deviceVersionCheck(feat);
|
|
529
|
-
if (!version || !versionUtils.isEqual(version, newVersion)) {
|
|
530
|
-
this._unavailableCapabilities = getUnavailableCapabilities(feat, getAllNetworks());
|
|
531
|
-
this._firmwareStatus = getFirmwareStatus(feat, getFirmwareType(feat));
|
|
532
|
-
this._firmwareReleaseConfigInfo = getFirmwareReleaseConfigInfo(feat, getFirmwareType(feat));
|
|
533
|
-
if (isProductionFirmwareChannel(settingsStore.get('firmwareChannel'))) {
|
|
534
|
-
this._currentRelease = getReleaseAsset(feat.internal_model, newVersion, getFirmwareType(feat));
|
|
535
|
-
this.availableTranslations = this._currentRelease?.translations ?? {};
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
this._features = feat;
|
|
539
|
-
this._firmwareType = getFirmwareType(feat);
|
|
540
|
-
this.updateNameAndColor();
|
|
541
|
-
this.busy = undefined;
|
|
542
|
-
}
|
|
543
|
-
deviceVersionCheck(feat) {
|
|
544
|
-
const version = this.getVersion();
|
|
545
|
-
const oldId = this.features?.device_id;
|
|
546
|
-
if (!oldId || !!feat.bootloader_mode || !version) return;
|
|
547
|
-
const newVersion = getFirmwareOrBootloaderVersionArray(feat);
|
|
548
|
-
if (feat.device_id !== oldId) {
|
|
549
|
-
if (feat.initialized === this.features?.initialized) {
|
|
550
|
-
const stripConfidential = f => ({
|
|
551
|
-
...f,
|
|
552
|
-
device_id: undefined,
|
|
553
|
-
session_id: undefined,
|
|
554
|
-
label: undefined
|
|
555
|
-
});
|
|
556
|
-
const oldFeatures = this.features;
|
|
557
|
-
const {
|
|
558
|
-
uniquePath: path
|
|
559
|
-
} = this;
|
|
560
|
-
this.transport.enumerate().then(res => {
|
|
561
|
-
const descriptors = res.success ? res.payload : undefined;
|
|
562
|
-
console.error('getFeatures device id mismatch', {
|
|
563
|
-
path,
|
|
564
|
-
oldFeatures: oldFeatures && stripConfidential(oldFeatures),
|
|
565
|
-
newFeatures: stripConfidential(feat),
|
|
566
|
-
descriptors
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
if (!versionUtils.isEqual(version, newVersion)) {
|
|
573
|
-
this.emit(DEVICE.FIRMWARE_VERSION_CHANGED, {
|
|
574
|
-
oldVersion: version,
|
|
575
|
-
newVersion,
|
|
576
|
-
device: this.toMessageObject()
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
updateNameAndColor() {
|
|
581
|
-
const {
|
|
582
|
-
internal_model,
|
|
583
|
-
model_variant
|
|
584
|
-
} = this.thp?.properties ?? {};
|
|
585
|
-
const internalModel = this._features?.internal_model ?? internal_model;
|
|
586
|
-
const unitColor = this._features?.unit_color ?? (model_variant ?? 0) % 256;
|
|
587
|
-
const deviceInfo = models[internalModel] ?? {
|
|
588
|
-
name: `Unknown ${internalModel}`,
|
|
589
|
-
colors: {}
|
|
590
|
-
};
|
|
591
|
-
this.name = deviceInfo.name;
|
|
592
|
-
if (unitColor) {
|
|
593
|
-
const deviceUnitColor = unitColor.toString();
|
|
594
|
-
if (deviceUnitColor in deviceInfo.colors) {
|
|
595
|
-
this.color = deviceInfo.colors[deviceUnitColor];
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
updateFeature(key, value) {
|
|
600
|
-
if (this._features) {
|
|
601
|
-
this._features = {
|
|
602
|
-
...this._features,
|
|
603
|
-
[key]: value
|
|
604
|
-
};
|
|
605
|
-
this.emitDeviceChanged();
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
prompt(type, args) {
|
|
609
|
-
return new Promise(callback => {
|
|
610
|
-
if (!this.listenerCount(type)) {
|
|
611
|
-
const payload = {
|
|
612
|
-
success: false,
|
|
613
|
-
error: new Error(`${type} callback not configured`)
|
|
614
|
-
};
|
|
615
|
-
callback(payload);
|
|
616
|
-
} else {
|
|
617
|
-
this.emit(type, {
|
|
618
|
-
callback,
|
|
619
|
-
...args
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
isUnacquired() {
|
|
625
|
-
return this.features === undefined;
|
|
626
|
-
}
|
|
627
|
-
disconnect() {
|
|
628
|
-
this.logger.debug('Disconnect cleanup');
|
|
629
|
-
this.transport.off(TRANSPORT.STOPPED, this.onTransportStopped);
|
|
630
|
-
this.transport.deviceEvents.off(this.descriptor.path, this.onTransportDeviceEvent);
|
|
631
|
-
this.removeAllListeners();
|
|
632
|
-
this.sessionDfd?.reject(new Error());
|
|
633
|
-
if (this.sessionAcquired) {
|
|
634
|
-
this.transport.releaseSync(this.sessionAcquired);
|
|
635
|
-
this.sessionAcquired = null;
|
|
636
|
-
}
|
|
637
|
-
this.lifecycle.emit(DEVICE.DISCONNECT);
|
|
638
|
-
return this.interrupt(ERRORS.TypedError('Device_Disconnected'));
|
|
639
|
-
}
|
|
640
|
-
isBootloader() {
|
|
641
|
-
return this.features && !!this.features.bootloader_mode;
|
|
642
|
-
}
|
|
643
|
-
isInitialized() {
|
|
644
|
-
return this.features && !!this.features.initialized;
|
|
645
|
-
}
|
|
646
|
-
isSeedless() {
|
|
647
|
-
return this.features && !!this.features.no_backup;
|
|
648
|
-
}
|
|
649
|
-
getVersion() {
|
|
650
|
-
return this.features ? getFirmwareOrBootloaderVersionArray(this.features) : undefined;
|
|
651
|
-
}
|
|
652
|
-
atLeast(versions) {
|
|
653
|
-
const version = this.getVersion();
|
|
654
|
-
if (!this.features || !version) return false;
|
|
655
|
-
if (typeof versions === 'string') {
|
|
656
|
-
return versionUtils.isNewerOrEqual(version, versions);
|
|
657
|
-
}
|
|
658
|
-
const modelVersionIndex = this.features.major_version - 1;
|
|
659
|
-
const modelVersion = versions[modelVersionIndex];
|
|
660
|
-
return versionUtils.isNewerOrEqual(version, modelVersion);
|
|
661
|
-
}
|
|
662
|
-
isUsed() {
|
|
663
|
-
return !!this.transport.getDescriptor(this.descriptor.path)?.session;
|
|
664
|
-
}
|
|
665
|
-
isUsedHere() {
|
|
666
|
-
return !!this.sessionAcquired;
|
|
667
|
-
}
|
|
668
|
-
getBusy() {
|
|
669
|
-
return this.busy;
|
|
670
|
-
}
|
|
671
|
-
isUsedElsewhere() {
|
|
672
|
-
return this.isUsed() && !this.isUsedHere();
|
|
673
|
-
}
|
|
674
|
-
getUniquePath() {
|
|
675
|
-
return this.uniquePath;
|
|
676
|
-
}
|
|
677
|
-
hasUnexpectedMode(allow) {
|
|
678
|
-
if (this.features) {
|
|
679
|
-
if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
680
|
-
return UI_REQUEST.BOOTLOADER;
|
|
681
|
-
}
|
|
682
|
-
if (!this.isInitialized() && !allow.includes(UI_REQUEST.INITIALIZE)) {
|
|
683
|
-
return UI_REQUEST.INITIALIZE;
|
|
684
|
-
}
|
|
685
|
-
if (this.isSeedless() && !allow.includes(UI_REQUEST.SEEDLESS)) {
|
|
686
|
-
return UI_REQUEST.SEEDLESS;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
return null;
|
|
690
|
-
}
|
|
691
|
-
getStatus() {
|
|
692
|
-
if (this.isUsedElsewhere()) return 'occupied';
|
|
693
|
-
if (this.wasUsedElsewhere) return 'used';
|
|
694
|
-
if (this.busy) return this.busy;
|
|
695
|
-
return 'available';
|
|
696
|
-
}
|
|
697
|
-
getDeviceThp() {
|
|
698
|
-
const state = this.thp?.serialize();
|
|
699
|
-
return state ? {
|
|
700
|
-
properties: state.properties,
|
|
701
|
-
credentials: state.credentials,
|
|
702
|
-
channel: state.channel
|
|
703
|
-
} : undefined;
|
|
704
|
-
}
|
|
705
|
-
toMessageObject() {
|
|
706
|
-
const {
|
|
707
|
-
name,
|
|
708
|
-
uniquePath: path,
|
|
709
|
-
descriptor
|
|
710
|
-
} = this;
|
|
711
|
-
const {
|
|
712
|
-
apiType,
|
|
713
|
-
id
|
|
714
|
-
} = descriptor;
|
|
715
|
-
const base = {
|
|
716
|
-
path,
|
|
717
|
-
name,
|
|
718
|
-
descriptor: {
|
|
719
|
-
apiType,
|
|
720
|
-
id
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
if (this.unreadableError) {
|
|
724
|
-
return {
|
|
725
|
-
...base,
|
|
726
|
-
type: 'unreadable',
|
|
727
|
-
error: this.unreadableError,
|
|
728
|
-
label: 'Unreadable device',
|
|
729
|
-
hid: this.possibleHIDdevice
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
if (this.isUnacquired()) {
|
|
733
|
-
const sessionOwner = this.transport.getDescriptor(this.descriptor.path)?.sessionOwner;
|
|
734
|
-
return {
|
|
735
|
-
...base,
|
|
736
|
-
type: 'unacquired',
|
|
737
|
-
label: 'Unacquired device',
|
|
738
|
-
name: this.name,
|
|
739
|
-
transportSessionOwner: this.sessionAcquired ? undefined : sessionOwner,
|
|
740
|
-
thp: this.getDeviceThp(),
|
|
741
|
-
status: this.busy ? this.busy : undefined
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
const defaultLabel = 'My Trezor';
|
|
745
|
-
const label = this.features.label === '' || !this.features.label ? defaultLabel : this.features.label;
|
|
746
|
-
return {
|
|
747
|
-
...base,
|
|
748
|
-
type: 'acquired',
|
|
749
|
-
id: this.features.device_id,
|
|
750
|
-
label,
|
|
751
|
-
state: this.getState(),
|
|
752
|
-
status: this.getStatus(),
|
|
753
|
-
mode: getFirmwareMode(this.features),
|
|
754
|
-
color: this.color,
|
|
755
|
-
firmware: this.firmwareStatus,
|
|
756
|
-
firmwareReleaseConfigInfo: this.firmwareReleaseConfigInfo,
|
|
757
|
-
firmwareType: this.firmwareType,
|
|
758
|
-
features: this.features,
|
|
759
|
-
unavailableCapabilities: this.unavailableCapabilities,
|
|
760
|
-
availableTranslations: this.availableTranslations,
|
|
761
|
-
authenticityChecks: this.authenticityChecks,
|
|
762
|
-
thp: this.getDeviceThp()
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
}
|