@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
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { DEVICE } from "@trezor/connect-common";
|
|
2
|
-
import { ERRORS } from "@trezor/connect-common/lib/constants/index.js";
|
|
3
|
-
import { MessagesSchema as Messages } from "@trezor/protobuf";
|
|
4
|
-
import { Assert } from "@trezor/schema-utils";
|
|
5
|
-
import { TRANSPORT, isErrorWithoutDeviceInteraction } from "@trezor/transport-common";
|
|
6
|
-
import { scheduleAction } from "@trezor/utils";
|
|
7
|
-
const blacklist = {
|
|
8
|
-
PassphraseAck: ['passphrase'],
|
|
9
|
-
CipheredKeyValue: ['value'],
|
|
10
|
-
GetPublicKey: ['address_n'],
|
|
11
|
-
PublicKey: ['node', 'xpub'],
|
|
12
|
-
DecryptedMessage: ['message', 'address'],
|
|
13
|
-
Features: true
|
|
14
|
-
};
|
|
15
|
-
const allowedCallsBeforeInitialize = ['Cancel', 'Initialize', 'GetFeatures', 'GetFirmwareHash', 'ChangeLanguage', 'DataChunkAck', 'RebootToBootloader', 'FirmwareErase', 'FirmwareUpload', 'RecoveryDevice', 'WipeDevice'];
|
|
16
|
-
const filterForLog = (type, msg) => blacklist[type] === true ? '(redacted...)' : (blacklist[type] ?? []).reduce((prev, cur) => ({
|
|
17
|
-
...prev,
|
|
18
|
-
[cur]: '(redacted...)'
|
|
19
|
-
}), msg);
|
|
20
|
-
const isExpectedResponse = (response, expected) => (Array.isArray(expected) ? expected : expected.split('|')).includes(response.type);
|
|
21
|
-
const success = payload => ({
|
|
22
|
-
success: true,
|
|
23
|
-
payload
|
|
24
|
-
});
|
|
25
|
-
const error = error => ({
|
|
26
|
-
success: false,
|
|
27
|
-
error
|
|
28
|
-
});
|
|
29
|
-
const nestedError = cause => error(ERRORS.nestError(cause));
|
|
30
|
-
const fail = msg => error(isErrorWithoutDeviceInteraction(msg) ? new ERRORS.TransportError(msg) : new Error(msg));
|
|
31
|
-
export class DeviceCurrentSession {
|
|
32
|
-
device;
|
|
33
|
-
transport;
|
|
34
|
-
session;
|
|
35
|
-
logger;
|
|
36
|
-
disposed;
|
|
37
|
-
callPromise;
|
|
38
|
-
abortController;
|
|
39
|
-
constructor(device, transport, session, logger) {
|
|
40
|
-
this.device = device;
|
|
41
|
-
this.transport = transport;
|
|
42
|
-
this.session = session;
|
|
43
|
-
this.logger = logger;
|
|
44
|
-
transport.deviceEvents.once(device.transportPath, e => {
|
|
45
|
-
if (!this.disposed) {
|
|
46
|
-
this.disposed = ERRORS.TypedError(e.type === TRANSPORT.DEVICE_DISCONNECTED ? 'Device_Disconnected' : 'Device_UsedElsewhere');
|
|
47
|
-
this.abortController?.abort(this.disposed);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
isDisposed() {
|
|
52
|
-
return !!this.disposed;
|
|
53
|
-
}
|
|
54
|
-
async typedCall(type, expectedType, msg = {}) {
|
|
55
|
-
const deviceSessionId = this.device.getThpState()?.sessionId || this.device?.features?.session_id;
|
|
56
|
-
if (!allowedCallsBeforeInitialize.includes(type) && !deviceSessionId) {
|
|
57
|
-
console.error('Runtime', `typedCall: Device not initialized when calling ${type}. call Initialize first`);
|
|
58
|
-
}
|
|
59
|
-
Assert(Messages.MessageType.properties[type], msg);
|
|
60
|
-
this.abortController = new AbortController();
|
|
61
|
-
const {
|
|
62
|
-
signal
|
|
63
|
-
} = this.abortController;
|
|
64
|
-
const abortPromise = new Promise(resolve => signal.addEventListener('abort', () => resolve(signal.reason)));
|
|
65
|
-
const callPromise = this.callLoop(type, msg, abortPromise);
|
|
66
|
-
this.callPromise = callPromise;
|
|
67
|
-
const response = await callPromise;
|
|
68
|
-
this.callPromise = undefined;
|
|
69
|
-
this.abortController = undefined;
|
|
70
|
-
if (!response.success) throw response.error;
|
|
71
|
-
const {
|
|
72
|
-
payload
|
|
73
|
-
} = response;
|
|
74
|
-
const receivedType = payload.type;
|
|
75
|
-
if (isExpectedResponse(payload, expectedType)) {
|
|
76
|
-
return payload;
|
|
77
|
-
} else {
|
|
78
|
-
await scheduleAction(abort => this.transport.receive({
|
|
79
|
-
session: this.session,
|
|
80
|
-
protocol: this.device.protocol,
|
|
81
|
-
thpState: this.device.getThpState(),
|
|
82
|
-
signal: abort
|
|
83
|
-
}), {
|
|
84
|
-
timeout: 500
|
|
85
|
-
}).catch(() => {});
|
|
86
|
-
throw ERRORS.TypedError('Runtime', `assertType: Response of unexpected type: ${receivedType}. Should be ${expectedType}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async callLoop(type, msg, abortPromise) {
|
|
90
|
-
let [name, data] = [type, msg];
|
|
91
|
-
let pinUnlocked = false;
|
|
92
|
-
while (true) {
|
|
93
|
-
const timeout = this.device.possibleT1 && name === 'GetFeatures' ? 3_000 : undefined;
|
|
94
|
-
const callPromise = this.call(name, data, {
|
|
95
|
-
timeout
|
|
96
|
-
});
|
|
97
|
-
const [abortedDuringCall, response] = await Promise.race([callPromise.then(res => [false, res]), abortPromise.then(res => [true, nestedError(res)])]);
|
|
98
|
-
if (name === 'ButtonAck' && abortedDuringCall && !this.disposed) {
|
|
99
|
-
this.device.getThpState()?.sync('send', 'Cancel');
|
|
100
|
-
await this.send('Cancel', {});
|
|
101
|
-
}
|
|
102
|
-
await callPromise;
|
|
103
|
-
if (this.disposed) return nestedError(this.disposed);
|
|
104
|
-
if (!response.success) return response;
|
|
105
|
-
const res = response.payload;
|
|
106
|
-
switch (res.type) {
|
|
107
|
-
case 'Failure':
|
|
108
|
-
{
|
|
109
|
-
const {
|
|
110
|
-
code,
|
|
111
|
-
message
|
|
112
|
-
} = res.message;
|
|
113
|
-
if (name === 'GetFeatures' && code === 'Failure_UnexpectedMessage') {
|
|
114
|
-
[name, data] = ['Initialize', {}];
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
const err = message || code === 'Failure_FirmwareError' && 'Firmware installation failed' || code === 'Failure_ActionCancelled' && 'Action cancelled by user' || 'Failure_UnknownMessage';
|
|
118
|
-
return error(new ERRORS.TrezorError(code || 'Failure_UnknownCode', err));
|
|
119
|
-
}
|
|
120
|
-
case 'ButtonRequest':
|
|
121
|
-
{
|
|
122
|
-
if (res.message.code === 'ButtonRequest_PassphraseEntry') {
|
|
123
|
-
this.device.emit(DEVICE.PASSPHRASE_ON_DEVICE);
|
|
124
|
-
} else {
|
|
125
|
-
this.device.emit(DEVICE.BUTTON, {
|
|
126
|
-
device: this.device,
|
|
127
|
-
payload: res.message
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
[name, data] = ['ButtonAck', {}];
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
case 'PinMatrixRequest':
|
|
134
|
-
{
|
|
135
|
-
const promptRes = await Promise.race([this.device.prompt(DEVICE.PIN, {
|
|
136
|
-
type: res.message.type
|
|
137
|
-
}), abortPromise.then(nestedError)]);
|
|
138
|
-
if (!promptRes.success) {
|
|
139
|
-
const cancelRes = await this.call('Cancel', {});
|
|
140
|
-
return cancelRes.success ? promptRes : cancelRes;
|
|
141
|
-
}
|
|
142
|
-
pinUnlocked = true;
|
|
143
|
-
[name, data] = ['PinMatrixAck', {
|
|
144
|
-
pin: promptRes.payload
|
|
145
|
-
}];
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
case 'PassphraseRequest':
|
|
149
|
-
{
|
|
150
|
-
const promptRes = await Promise.race([this.device.prompt(DEVICE.PASSPHRASE, {}), abortPromise.then(nestedError)]);
|
|
151
|
-
if (!promptRes.success) {
|
|
152
|
-
const cancelRes = await this.call('Cancel', {});
|
|
153
|
-
return cancelRes.success ? promptRes : cancelRes;
|
|
154
|
-
}
|
|
155
|
-
const payload = promptRes.payload.passphraseOnDevice ? {
|
|
156
|
-
on_device: true
|
|
157
|
-
} : {
|
|
158
|
-
passphrase: promptRes.payload.value.normalize('NFKD')
|
|
159
|
-
};
|
|
160
|
-
[name, data] = ['PassphraseAck', payload];
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
case 'WordRequest':
|
|
164
|
-
{
|
|
165
|
-
const promptRes = await Promise.race([this.device.prompt(DEVICE.WORD, {
|
|
166
|
-
type: res.message.type
|
|
167
|
-
}), abortPromise.then(nestedError)]);
|
|
168
|
-
if (!promptRes.success) {
|
|
169
|
-
const cancelRes = await this.call('Cancel', {});
|
|
170
|
-
return cancelRes.success ? promptRes : cancelRes;
|
|
171
|
-
}
|
|
172
|
-
[name, data] = ['WordAck', {
|
|
173
|
-
word: promptRes.payload
|
|
174
|
-
}];
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
default:
|
|
178
|
-
{
|
|
179
|
-
if (!this.disposed && pinUnlocked && !this.device.features.unlocked) {
|
|
180
|
-
await this.device.getFeatures().catch(() => {});
|
|
181
|
-
}
|
|
182
|
-
return success(res);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async call(name, data, options = {}) {
|
|
188
|
-
if (this.disposed) return Promise.resolve(nestedError(this.disposed));
|
|
189
|
-
this.logger.debug('Sending', name, filterForLog(name, data));
|
|
190
|
-
const result = await this.transport.call({
|
|
191
|
-
name,
|
|
192
|
-
data,
|
|
193
|
-
session: this.session,
|
|
194
|
-
protocol: this.device.protocol,
|
|
195
|
-
thpState: this.device.getThpState(),
|
|
196
|
-
...options
|
|
197
|
-
});
|
|
198
|
-
if (result.success) {
|
|
199
|
-
const {
|
|
200
|
-
type,
|
|
201
|
-
message
|
|
202
|
-
} = result.payload;
|
|
203
|
-
this.logger.debug('Received', type, filterForLog(type, message));
|
|
204
|
-
} else {
|
|
205
|
-
this.logger.warn('Received transport error', result.error.code, result.error.message);
|
|
206
|
-
}
|
|
207
|
-
return result.success ? success(result.payload) : fail(result.error.message || result.error.code);
|
|
208
|
-
}
|
|
209
|
-
async send(name, data, options = {}) {
|
|
210
|
-
if (this.disposed) return Promise.resolve(nestedError(this.disposed));
|
|
211
|
-
const result = await this.transport.send({
|
|
212
|
-
name,
|
|
213
|
-
data,
|
|
214
|
-
session: this.session,
|
|
215
|
-
protocol: this.device.protocol,
|
|
216
|
-
thpState: this.device.getThpState(),
|
|
217
|
-
...options
|
|
218
|
-
});
|
|
219
|
-
return result.success ? success(result.payload) : fail(result.error.message || result.error.code);
|
|
220
|
-
}
|
|
221
|
-
async receive(options = {}) {
|
|
222
|
-
if (this.disposed) return Promise.resolve(nestedError(this.disposed));
|
|
223
|
-
const result = await this.transport.receive({
|
|
224
|
-
session: this.session,
|
|
225
|
-
protocol: this.device.protocol,
|
|
226
|
-
thpState: this.device.getThpState(),
|
|
227
|
-
...options
|
|
228
|
-
});
|
|
229
|
-
return result.success ? success(result.payload) : fail(result.error.message || result.error.code);
|
|
230
|
-
}
|
|
231
|
-
cancelCall() {
|
|
232
|
-
return this.call('Cancel', {});
|
|
233
|
-
}
|
|
234
|
-
async abort(reason) {
|
|
235
|
-
this.abortController?.abort(reason);
|
|
236
|
-
await this.callPromise;
|
|
237
|
-
this.disposed = reason;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { DEVICE } from '@trezor/connect-common';
|
|
2
|
-
import type { ConnectSettings, DecodedTrezorPushNotification, DeviceUniquePath, StaticSessionId, TransportError, TransportInfo } from '@trezor/connect-common';
|
|
3
|
-
import type { CreateLogger } from '@trezor/connect-common/lib/types/settings';
|
|
4
|
-
import { type Descriptor, TRANSPORT } from '@trezor/transport-common';
|
|
5
|
-
import { TypedEmitter } from '@trezor/utils';
|
|
6
|
-
import { Device } from "./Device.js";
|
|
7
|
-
interface DeviceListEvents {
|
|
8
|
-
[TRANSPORT.START]: TransportInfo;
|
|
9
|
-
[TRANSPORT.ERROR]: TransportError;
|
|
10
|
-
[DEVICE.CONNECT]: Device;
|
|
11
|
-
[DEVICE.CONNECT_UNACQUIRED]: Device;
|
|
12
|
-
[DEVICE.TREZOR_PUSH_NOTIFICATION]: DecodedTrezorPushNotification & {
|
|
13
|
-
device: Device;
|
|
14
|
-
};
|
|
15
|
-
[DEVICE.DISCONNECT]: Device;
|
|
16
|
-
[DEVICE.CHANGED]: Device;
|
|
17
|
-
}
|
|
18
|
-
export interface IDeviceList {
|
|
19
|
-
isConnected(): this is DeviceList;
|
|
20
|
-
pendingConnection(): Promise<void> | undefined;
|
|
21
|
-
addAuthPenalty: DeviceList['addAuthPenalty'];
|
|
22
|
-
removeAuthPenalty: DeviceList['removeAuthPenalty'];
|
|
23
|
-
on: DeviceList['on'];
|
|
24
|
-
once: DeviceList['once'];
|
|
25
|
-
init: DeviceList['init'];
|
|
26
|
-
dispose: DeviceList['dispose'];
|
|
27
|
-
}
|
|
28
|
-
export declare const assertDeviceListConnected: (deviceList: IDeviceList) => asserts deviceList is DeviceList;
|
|
29
|
-
type ConstructorParams = {
|
|
30
|
-
createLogger: CreateLogger;
|
|
31
|
-
};
|
|
32
|
-
type InitParams = Pick<ConnectSettings, 'transports' | 'pendingTransportEvent' | 'transportReconnect'>;
|
|
33
|
-
export declare class DeviceList extends TypedEmitter<DeviceListEvents> implements IDeviceList {
|
|
34
|
-
private readonly transportManagers;
|
|
35
|
-
private transports;
|
|
36
|
-
private devices;
|
|
37
|
-
private deviceCounter;
|
|
38
|
-
private readonly handshakeLock;
|
|
39
|
-
private readonly authPenaltyManager;
|
|
40
|
-
private readonly createLogger;
|
|
41
|
-
private getConnectedTransports;
|
|
42
|
-
isConnected(): this is DeviceList;
|
|
43
|
-
pendingConnection(): Promise<void> | undefined;
|
|
44
|
-
getActiveTransports(): {
|
|
45
|
-
apiType: "usb" | "bluetooth" | "udp";
|
|
46
|
-
type: "BridgeTransport" | "NodeUsbTransport" | "WebUsbTransport" | "UdpTransport" | "NativeUsbTransport" | "BluetoothTransport" | "NativeBluetoothTransport";
|
|
47
|
-
version: string;
|
|
48
|
-
}[];
|
|
49
|
-
constructor({
|
|
50
|
-
createLogger
|
|
51
|
-
}: ConstructorParams);
|
|
52
|
-
private getSimilarDevices;
|
|
53
|
-
private onDeviceConnected;
|
|
54
|
-
private onPushNotification;
|
|
55
|
-
private onBatteryLevel;
|
|
56
|
-
private getOrCreateTransportManager;
|
|
57
|
-
init({
|
|
58
|
-
transports,
|
|
59
|
-
transportReconnect,
|
|
60
|
-
pendingTransportEvent
|
|
61
|
-
}?: InitParams): Promise<void>;
|
|
62
|
-
private initializeTransport;
|
|
63
|
-
private waitForDevices;
|
|
64
|
-
getDeviceCount(): number;
|
|
65
|
-
getPrioritizedDevices(): Device[];
|
|
66
|
-
getAllDevices(): readonly Device[];
|
|
67
|
-
getOnlyDevice(apiType?: Descriptor['apiType']): Device | undefined;
|
|
68
|
-
getDeviceByPath(path: DeviceUniquePath): Device | undefined;
|
|
69
|
-
getDeviceByStaticState(state: StaticSessionId): Device | undefined;
|
|
70
|
-
dispose(): Promise<void>;
|
|
71
|
-
enumerate(): Promise<void>;
|
|
72
|
-
addAuthPenalty(device: Device): void;
|
|
73
|
-
removeAuthPenalty(device: Device): void;
|
|
74
|
-
}
|
|
75
|
-
export {};
|
package/lib/device/DeviceList.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { DEVICE, asDeviceUniquePath } from "@trezor/connect-common";
|
|
2
|
-
import { ERRORS } from "@trezor/connect-common/lib/constants/index.js";
|
|
3
|
-
import { parseStaticSessionId } from "@trezor/device-utils";
|
|
4
|
-
import { TRANSPORT } from "@trezor/transport-common";
|
|
5
|
-
import { TypedEmitter, arrayDistinct, createDeferred, getSynchronize, isNotUndefined, resolveAfter, typedObjectKeys } from "@trezor/utils";
|
|
6
|
-
import { Device } from "./Device.js";
|
|
7
|
-
import { createTransportList } from "./TransportList.js";
|
|
8
|
-
import { TransportManager } from "./TransportManager.js";
|
|
9
|
-
import { trezorPushNotificationHandler } from "./workflow/trezorPushNotification.js";
|
|
10
|
-
const createAuthPenaltyManager = (priority = 2) => {
|
|
11
|
-
const penalizedDevices = {};
|
|
12
|
-
const get = () => 100 * priority + Object.keys(penalizedDevices).reduce((penalty, key) => {
|
|
13
|
-
const devicePenalty = penalizedDevices[key];
|
|
14
|
-
return Math.max(penalty, devicePenalty);
|
|
15
|
-
}, 0);
|
|
16
|
-
const add = device => {
|
|
17
|
-
if (!device.isInitialized() || device.isBootloader() || !device.features.device_id) return;
|
|
18
|
-
const deviceID = device.features.device_id;
|
|
19
|
-
const currentPenalty = penalizedDevices[deviceID];
|
|
20
|
-
const penalty = currentPenalty ? currentPenalty + 500 : 2000;
|
|
21
|
-
penalizedDevices[deviceID] = Math.min(penalty, 5000);
|
|
22
|
-
};
|
|
23
|
-
const remove = device => {
|
|
24
|
-
if (!device.isInitialized() || device.isBootloader() || !device.features.device_id) return;
|
|
25
|
-
const deviceID = device.features.device_id;
|
|
26
|
-
delete penalizedDevices[deviceID];
|
|
27
|
-
};
|
|
28
|
-
return {
|
|
29
|
-
get,
|
|
30
|
-
add,
|
|
31
|
-
remove
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const getTransportInfo = transport => ({
|
|
35
|
-
apiType: transport.apiType,
|
|
36
|
-
type: transport.name,
|
|
37
|
-
version: transport.version
|
|
38
|
-
});
|
|
39
|
-
export const assertDeviceListConnected = deviceList => {
|
|
40
|
-
if (!deviceList.isConnected()) {
|
|
41
|
-
throw ERRORS.TypedError('Transport_Missing');
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
export class DeviceList extends TypedEmitter {
|
|
45
|
-
transportManagers = {};
|
|
46
|
-
transports = [];
|
|
47
|
-
devices = [];
|
|
48
|
-
deviceCounter = Date.now();
|
|
49
|
-
handshakeLock;
|
|
50
|
-
authPenaltyManager;
|
|
51
|
-
createLogger;
|
|
52
|
-
getConnectedTransports() {
|
|
53
|
-
return Object.values(this.transportManagers).map(manager => manager.get()).filter(isNotUndefined);
|
|
54
|
-
}
|
|
55
|
-
isConnected() {
|
|
56
|
-
return !!this.getConnectedTransports().length;
|
|
57
|
-
}
|
|
58
|
-
pendingConnection() {
|
|
59
|
-
const pending = Object.values(this.transportManagers).map(manager => manager.pending()).filter(isNotUndefined);
|
|
60
|
-
if (pending.length) return Promise.all(pending).then(() => {});
|
|
61
|
-
}
|
|
62
|
-
getActiveTransports() {
|
|
63
|
-
return this.getConnectedTransports().map(getTransportInfo);
|
|
64
|
-
}
|
|
65
|
-
constructor({
|
|
66
|
-
createLogger
|
|
67
|
-
}) {
|
|
68
|
-
super();
|
|
69
|
-
this.createLogger = createLogger;
|
|
70
|
-
this.handshakeLock = getSynchronize();
|
|
71
|
-
this.authPenaltyManager = createAuthPenaltyManager();
|
|
72
|
-
}
|
|
73
|
-
getSimilarDevices(device) {
|
|
74
|
-
return this.devices.filter(d => {
|
|
75
|
-
if (d.descriptor.apiType === device.transport.apiType) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
if (device.descriptor.id && d.features?.device_id === device.descriptor.id) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
if (device.descriptor.model && d.descriptor.model === device.descriptor.model) {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
async onDeviceConnected(descriptor, transport) {
|
|
88
|
-
const id = (this.deviceCounter++).toString(16).slice(-8);
|
|
89
|
-
const device = new Device({
|
|
90
|
-
id: asDeviceUniquePath(id),
|
|
91
|
-
transport,
|
|
92
|
-
descriptor,
|
|
93
|
-
createLogger: this.createLogger
|
|
94
|
-
});
|
|
95
|
-
const similarUsedDevices = this.getSimilarDevices(device).some(d => d.isUsed() || d.getBusy() === 'rebooting');
|
|
96
|
-
if (!similarUsedDevices) {
|
|
97
|
-
const penalty = this.authPenaltyManager.get();
|
|
98
|
-
const stillConnected = await this.handshakeLock(() => resolveAfter(penalty && penalty + 501).then(() => device.handshake()));
|
|
99
|
-
if (!stillConnected) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (descriptor.id && descriptor.apiType === 'bluetooth') {
|
|
104
|
-
transport.subscribe({
|
|
105
|
-
path: device.descriptor.id,
|
|
106
|
-
channels: ['battery-level', 'trezor-push-notification']
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
this.devices.push(device);
|
|
110
|
-
device.lifecycle.on(DEVICE.CONNECT, () => this.emit(DEVICE.CONNECT, device));
|
|
111
|
-
device.lifecycle.on(DEVICE.CHANGED, () => this.emit(DEVICE.CHANGED, device));
|
|
112
|
-
device.lifecycle.on(DEVICE.CONNECT_UNACQUIRED, () => this.emit(DEVICE.CONNECT_UNACQUIRED, device));
|
|
113
|
-
device.lifecycle.on(DEVICE.TREZOR_PUSH_NOTIFICATION, payload => {
|
|
114
|
-
this.emit(DEVICE.TREZOR_PUSH_NOTIFICATION, {
|
|
115
|
-
device,
|
|
116
|
-
...payload
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
device.lifecycle.on(DEVICE.DISCONNECT, () => {
|
|
120
|
-
device.lifecycle.removeAllListeners();
|
|
121
|
-
this.authPenaltyManager.remove(device);
|
|
122
|
-
const index = this.devices.indexOf(device);
|
|
123
|
-
if (index >= 0) this.devices.splice(index, 1);
|
|
124
|
-
this.emit(DEVICE.DISCONNECT, device);
|
|
125
|
-
});
|
|
126
|
-
this.emit(device.isUnacquired() ? DEVICE.CONNECT_UNACQUIRED : DEVICE.CONNECT, device);
|
|
127
|
-
}
|
|
128
|
-
onPushNotification(event) {
|
|
129
|
-
const device = this.devices.find(d => d.descriptor.id === event.id);
|
|
130
|
-
if (device) {
|
|
131
|
-
trezorPushNotificationHandler({
|
|
132
|
-
device,
|
|
133
|
-
message: event.data
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
onBatteryLevel(event) {
|
|
138
|
-
const device = this.devices.find(d => d.descriptor.id === event.id);
|
|
139
|
-
device?.updateFeature('soc', event.data[0]);
|
|
140
|
-
}
|
|
141
|
-
getOrCreateTransportManager(apiType) {
|
|
142
|
-
if (!this.transportManagers[apiType]) {
|
|
143
|
-
const manager = new TransportManager(this.initializeTransport.bind(this));
|
|
144
|
-
manager.on(TRANSPORT.START, transport => this.emit(TRANSPORT.START, getTransportInfo(transport)));
|
|
145
|
-
manager.on(TRANSPORT.ERROR, error => this.emit(TRANSPORT.ERROR, {
|
|
146
|
-
apiType,
|
|
147
|
-
error
|
|
148
|
-
}));
|
|
149
|
-
this.transportManagers[apiType] = manager;
|
|
150
|
-
}
|
|
151
|
-
return this.transportManagers[apiType];
|
|
152
|
-
}
|
|
153
|
-
async init({
|
|
154
|
-
transports,
|
|
155
|
-
transportReconnect,
|
|
156
|
-
pendingTransportEvent
|
|
157
|
-
} = {}) {
|
|
158
|
-
this.transports = createTransportList(this.transports, transports);
|
|
159
|
-
const promises = this.transports.map(t => t.apiType).concat(typedObjectKeys(this.transportManagers)).filter(arrayDistinct).map(apiType => this.getOrCreateTransportManager(apiType).init({
|
|
160
|
-
transports: this.transports.filter(t => t.apiType === apiType),
|
|
161
|
-
transportReconnect,
|
|
162
|
-
pendingTransportEvent
|
|
163
|
-
}));
|
|
164
|
-
await Promise.all(promises);
|
|
165
|
-
}
|
|
166
|
-
async initializeTransport(transport, pendingTransportEvent, signal) {
|
|
167
|
-
transport.on(TRANSPORT.DEVICE_CONNECTED, d => this.onDeviceConnected(d, transport));
|
|
168
|
-
transport.on(TRANSPORT.TREZOR_PUSH_NOTIFICATION, this.onPushNotification.bind(this));
|
|
169
|
-
transport.on(TRANSPORT.BATTERY_LEVEL, this.onBatteryLevel.bind(this));
|
|
170
|
-
const enumerateResult = await transport.enumerate({
|
|
171
|
-
signal
|
|
172
|
-
});
|
|
173
|
-
if (!enumerateResult.success) {
|
|
174
|
-
throw new Error(enumerateResult.error.message || enumerateResult.error.code);
|
|
175
|
-
}
|
|
176
|
-
const descriptors = enumerateResult.payload;
|
|
177
|
-
transport.handleDescriptorsChange(descriptors);
|
|
178
|
-
transport.listen();
|
|
179
|
-
if (pendingTransportEvent && descriptors.length) {
|
|
180
|
-
await this.waitForDevices(transport, signal);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
waitForDevices(transport, signal) {
|
|
184
|
-
const {
|
|
185
|
-
promise,
|
|
186
|
-
reject,
|
|
187
|
-
resolve
|
|
188
|
-
} = createDeferred();
|
|
189
|
-
const onAbort = () => reject(signal.reason);
|
|
190
|
-
signal.addEventListener('abort', onAbort);
|
|
191
|
-
const onError = error => reject(new Error(error));
|
|
192
|
-
transport.once(TRANSPORT.ERROR, onError);
|
|
193
|
-
const autoResolveTransportEventTimeout = setTimeout(resolve, 10000);
|
|
194
|
-
this.handshakeLock(resolve);
|
|
195
|
-
return promise.finally(() => {
|
|
196
|
-
transport.off(TRANSPORT.ERROR, onError);
|
|
197
|
-
signal.removeEventListener('abort', onAbort);
|
|
198
|
-
clearTimeout(autoResolveTransportEventTimeout);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
getDeviceCount() {
|
|
202
|
-
return this.devices.length;
|
|
203
|
-
}
|
|
204
|
-
getPrioritizedDevices() {
|
|
205
|
-
return [...this.devices].sort((a, b) => (a.descriptor.apiType === 'bluetooth' ? 1 : 0) - (b.descriptor.apiType === 'bluetooth' ? 1 : 0));
|
|
206
|
-
}
|
|
207
|
-
getAllDevices() {
|
|
208
|
-
return this.getPrioritizedDevices();
|
|
209
|
-
}
|
|
210
|
-
getOnlyDevice(apiType) {
|
|
211
|
-
const devices = apiType ? this.devices.filter(d => d.descriptor.apiType === apiType) : this.devices;
|
|
212
|
-
return devices.length === 1 ? devices[0] : undefined;
|
|
213
|
-
}
|
|
214
|
-
getDeviceByPath(path) {
|
|
215
|
-
return this.getPrioritizedDevices().find(d => d.getUniquePath() === path);
|
|
216
|
-
}
|
|
217
|
-
getDeviceByStaticState(state) {
|
|
218
|
-
const {
|
|
219
|
-
deviceId
|
|
220
|
-
} = parseStaticSessionId(state);
|
|
221
|
-
return this.getPrioritizedDevices().find(d => d.features?.device_id === deviceId);
|
|
222
|
-
}
|
|
223
|
-
async dispose() {
|
|
224
|
-
this.removeAllListeners();
|
|
225
|
-
const promises = Object.values(this.transportManagers).map(manager => manager.dispose());
|
|
226
|
-
await Promise.all(promises);
|
|
227
|
-
}
|
|
228
|
-
async enumerate() {
|
|
229
|
-
const promises = this.getConnectedTransports().map(async transport => {
|
|
230
|
-
const res = await transport.enumerate();
|
|
231
|
-
if (res.success) {
|
|
232
|
-
transport.handleDescriptorsChange(res.payload);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
await Promise.all(promises);
|
|
236
|
-
}
|
|
237
|
-
addAuthPenalty(device) {
|
|
238
|
-
return this.authPenaltyManager.add(device);
|
|
239
|
-
}
|
|
240
|
-
removeAuthPenalty(device) {
|
|
241
|
-
return this.authPenaltyManager.remove(device);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ConnectSettingsTransport } from '@trezor/connect-common/lib/types/settings';
|
|
2
|
-
import { type Transport } from '@trezor/transport-common';
|
|
3
|
-
export declare const createTransportList: (existing: Transport[], transports?: ConnectSettingsTransport[]) => Transport[];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ERRORS } from "@trezor/connect-common/lib/constants/index.js";
|
|
2
|
-
import { isTransportInstance } from "@trezor/transport-common";
|
|
3
|
-
const reuseOrUse = (existing, candidate) => existing.find(t => t.name === candidate.name) ?? candidate;
|
|
4
|
-
const resolveOne = (existing, arg) => {
|
|
5
|
-
if (!isTransportInstance(arg)) {
|
|
6
|
-
throw ERRORS.TypedError('Runtime', `init({ transports }) entry is not a valid Transport instance`);
|
|
7
|
-
}
|
|
8
|
-
return reuseOrUse(existing, arg);
|
|
9
|
-
};
|
|
10
|
-
export const createTransportList = (existing, transports) => {
|
|
11
|
-
if (!transports?.length) return [];
|
|
12
|
-
return transports.map(transport => resolveOne(existing, transport));
|
|
13
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { TRANSPORT, type Transport } from '@trezor/transport-common';
|
|
2
|
-
import { TypedEmitter } from '@trezor/utils';
|
|
3
|
-
type TransportManagerEvents = {
|
|
4
|
-
[TRANSPORT.START]: Transport;
|
|
5
|
-
[TRANSPORT.ERROR]: string;
|
|
6
|
-
};
|
|
7
|
-
type StartTransport = (transport: Transport, pendingTransportEvent: boolean, signal: AbortSignal) => Promise<void>;
|
|
8
|
-
type InitParams = {
|
|
9
|
-
transports: Transport[];
|
|
10
|
-
transportReconnect?: boolean;
|
|
11
|
-
pendingTransportEvent?: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare class TransportManager extends TypedEmitter<TransportManagerEvents> {
|
|
14
|
-
private lock;
|
|
15
|
-
private transports;
|
|
16
|
-
private activeTransport?;
|
|
17
|
-
private transportReconnect;
|
|
18
|
-
private upgradeTimeout?;
|
|
19
|
-
private readonly startTransport;
|
|
20
|
-
constructor(startTransport: StartTransport);
|
|
21
|
-
pending(): Promise<void> | undefined;
|
|
22
|
-
get(): Transport | undefined;
|
|
23
|
-
init({
|
|
24
|
-
transports,
|
|
25
|
-
transportReconnect,
|
|
26
|
-
pendingTransportEvent
|
|
27
|
-
}: InitParams): Promise<void>;
|
|
28
|
-
dispose(): Promise<void>;
|
|
29
|
-
private selectTransport;
|
|
30
|
-
private scheduleUpgradeCheck;
|
|
31
|
-
private createInitPromise;
|
|
32
|
-
}
|
|
33
|
-
export {};
|