@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/core/index.js
DELETED
|
@@ -1,805 +0,0 @@
|
|
|
1
|
-
import EventEmitter from "events";
|
|
2
|
-
import { CORE_CALL, CORE_CALL_CANCEL, CORE_EVENT, DEVICE, POPUP, RESPONSE_EVENT, SET_ENABLED_NETWORKS, UI_EVENT, UI_REQUEST, UI_RESPONSE, createDeviceMessage, createResponseMessage, createTransportMessage, createUiMessage } from "@trezor/connect-common";
|
|
3
|
-
import { ERRORS } from "@trezor/connect-common/lib/constants/index.js";
|
|
4
|
-
import { parseLocalFirmwares } from "@trezor/connect-common/lib/data/connectSettings.js";
|
|
5
|
-
import { noopCreateLogger, noopLogger, setLogWriter } from "@trezor/connect-common/lib/utils/debug.js";
|
|
6
|
-
import { TRANSPORT, TRANSPORT_ERROR } from "@trezor/transport-common";
|
|
7
|
-
import { createDeferred, createLazy, getSynchronize, throwError } from "@trezor/utils";
|
|
8
|
-
import { getMethod } from "./method.js";
|
|
9
|
-
import { onCallFirmwareUpdate } from "./onCallFirmwareUpdate.js";
|
|
10
|
-
import { dispose as disposeBackend } from "../backend/BlockchainLink.js";
|
|
11
|
-
import * as enabledNetworksStore from "../data/enabledNetworksStore.js";
|
|
12
|
-
import { initializeFirmwareConfig } from "../data/firmwareInfo.js";
|
|
13
|
-
import * as firmwareReleaseStore from "../data/firmwareReleaseStore.js";
|
|
14
|
-
import * as localFirmwareStore from "../data/localFirmwareStore.js";
|
|
15
|
-
import { loadProtobufModules } from "../data/protobufLoader.js";
|
|
16
|
-
import * as settingsStore from "../data/settingsStore.js";
|
|
17
|
-
import { DeviceList, assertDeviceListConnected } from "../device/DeviceList.js";
|
|
18
|
-
import { validateState } from "../device/workflow/validateState.js";
|
|
19
|
-
import { createUiPromiseManager } from "../utils/uiPromiseManager.js";
|
|
20
|
-
const createSendCoreMessageWithCallId = (sendCoreMessage, callId) => message => {
|
|
21
|
-
const isUiRequestMessage = message.event === UI_EVENT && message.type.startsWith('ui-');
|
|
22
|
-
const hasCallId = 'callId' in message && Boolean(message.callId);
|
|
23
|
-
if (callId && isUiRequestMessage && !hasCallId) {
|
|
24
|
-
sendCoreMessage({
|
|
25
|
-
...message,
|
|
26
|
-
callId
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
sendCoreMessage(message);
|
|
31
|
-
};
|
|
32
|
-
const selectDevice = ({
|
|
33
|
-
deviceList
|
|
34
|
-
}, methodCallDevice) => {
|
|
35
|
-
assertDeviceListConnected(deviceList);
|
|
36
|
-
let device;
|
|
37
|
-
if (methodCallDevice?.state?.staticSessionId) {
|
|
38
|
-
device = deviceList.getDeviceByStaticState(methodCallDevice.state.staticSessionId);
|
|
39
|
-
}
|
|
40
|
-
if (!device && methodCallDevice?.path) {
|
|
41
|
-
device = deviceList.getDeviceByPath(methodCallDevice.path);
|
|
42
|
-
}
|
|
43
|
-
if (!device) {
|
|
44
|
-
device = deviceList.getOnlyDevice();
|
|
45
|
-
}
|
|
46
|
-
if (!device) {
|
|
47
|
-
throw ERRORS.TypedError('Device_NotFound');
|
|
48
|
-
}
|
|
49
|
-
return device;
|
|
50
|
-
};
|
|
51
|
-
const inner = async (context, method, device) => {
|
|
52
|
-
const {
|
|
53
|
-
uiPromises,
|
|
54
|
-
sendCoreMessage
|
|
55
|
-
} = context;
|
|
56
|
-
const firmwareException = method.checkFirmwareRange();
|
|
57
|
-
if (firmwareException) {
|
|
58
|
-
return Promise.reject(ERRORS.TypedError('Device_FwException', firmwareException));
|
|
59
|
-
}
|
|
60
|
-
const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode);
|
|
61
|
-
if (unexpectedMode) {
|
|
62
|
-
return Promise.reject(ERRORS.TypedError('Device_ModeException', unexpectedMode));
|
|
63
|
-
}
|
|
64
|
-
method.checkDeviceCapability();
|
|
65
|
-
const deviceNeedsBackup = device.features.backup_availability === 'Required';
|
|
66
|
-
if (deviceNeedsBackup) {
|
|
67
|
-
if (method.confirmMissingBackup) {
|
|
68
|
-
const uiPromise = uiPromises.create(UI_RESPONSE.RECEIVE_CONFIRMATION, device);
|
|
69
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.REQUEST_CONFIRMATION, {
|
|
70
|
-
view: 'no-backup'
|
|
71
|
-
}, {
|
|
72
|
-
requestId: uiPromise.requestId
|
|
73
|
-
}));
|
|
74
|
-
const permitted = await uiPromise.promise.then(({
|
|
75
|
-
payload
|
|
76
|
-
}) => payload);
|
|
77
|
-
if (!permitted) {
|
|
78
|
-
return Promise.reject(ERRORS.TypedError('Method_PermissionsNotGranted'));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.DEVICE_NEEDS_BACKUP, device.toMessageObject()));
|
|
82
|
-
}
|
|
83
|
-
if (device.firmwareStatus === 'outdated') {
|
|
84
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.FIRMWARE_OUTDATED, device.toMessageObject()));
|
|
85
|
-
}
|
|
86
|
-
if (method.useDeviceState) {
|
|
87
|
-
await validateState({
|
|
88
|
-
device,
|
|
89
|
-
method,
|
|
90
|
-
signal: context.signal,
|
|
91
|
-
sendCoreMessage
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
const response = await method.run({
|
|
96
|
-
sendCoreMessage,
|
|
97
|
-
createUiPromise: uiPromises.create
|
|
98
|
-
});
|
|
99
|
-
return createResponseMessage(method.responseID, true, response, {
|
|
100
|
-
path: device.getUniquePath(),
|
|
101
|
-
state: device.getState(),
|
|
102
|
-
instance: device.getInstance()
|
|
103
|
-
});
|
|
104
|
-
} catch (error) {
|
|
105
|
-
return Promise.reject(error);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const onCall = async (context, message) => {
|
|
109
|
-
if (!message.id || !message.payload || message.type !== CORE_CALL) {
|
|
110
|
-
throw ERRORS.TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing');
|
|
111
|
-
}
|
|
112
|
-
const {
|
|
113
|
-
uiPromises,
|
|
114
|
-
callMethods,
|
|
115
|
-
methodSynchronize,
|
|
116
|
-
resolveWaitForFirstMethod,
|
|
117
|
-
sendCoreMessage,
|
|
118
|
-
logger
|
|
119
|
-
} = context;
|
|
120
|
-
const responseID = message.id;
|
|
121
|
-
let method;
|
|
122
|
-
try {
|
|
123
|
-
method = await methodSynchronize(async () => {
|
|
124
|
-
logger.debug('loading method...');
|
|
125
|
-
const method2 = await getMethod(message);
|
|
126
|
-
logger.debug('method selected', method2.name);
|
|
127
|
-
await method2.initAsync?.();
|
|
128
|
-
return method2;
|
|
129
|
-
});
|
|
130
|
-
resolveWaitForFirstMethod();
|
|
131
|
-
callMethods.push(method);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
sendCoreMessage(createResponseMessage(responseID, false, {
|
|
134
|
-
error
|
|
135
|
-
}));
|
|
136
|
-
return Promise.resolve();
|
|
137
|
-
}
|
|
138
|
-
if (message.payload.__info) {
|
|
139
|
-
const response = method.getMethodInfo();
|
|
140
|
-
if (message.payload.__precomposed) {
|
|
141
|
-
response.precomposed = await method.payloadToPrecomposed();
|
|
142
|
-
}
|
|
143
|
-
sendCoreMessage(createResponseMessage(method.responseID, true, response));
|
|
144
|
-
return Promise.resolve();
|
|
145
|
-
}
|
|
146
|
-
const sendCoreMessageWithCallId = createSendCoreMessageWithCallId(sendCoreMessage, method.callId);
|
|
147
|
-
const methodContext = {
|
|
148
|
-
...context,
|
|
149
|
-
sendCoreMessage: sendCoreMessageWithCallId
|
|
150
|
-
};
|
|
151
|
-
if (!method.useDevice) {
|
|
152
|
-
try {
|
|
153
|
-
const response = await method.run({
|
|
154
|
-
sendCoreMessage: sendCoreMessageWithCallId,
|
|
155
|
-
createUiPromise: uiPromises.create
|
|
156
|
-
});
|
|
157
|
-
sendCoreMessageWithCallId(createResponseMessage(method.responseID, true, response));
|
|
158
|
-
} catch (error) {
|
|
159
|
-
sendCoreMessageWithCallId(createResponseMessage(method.responseID, false, {
|
|
160
|
-
error
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
return Promise.resolve();
|
|
164
|
-
}
|
|
165
|
-
return await onCallDevice(methodContext, message, method);
|
|
166
|
-
};
|
|
167
|
-
const onCallDevice = async (context, message, method) => {
|
|
168
|
-
const {
|
|
169
|
-
deviceList,
|
|
170
|
-
callMethods,
|
|
171
|
-
sendCoreMessage,
|
|
172
|
-
logger
|
|
173
|
-
} = context;
|
|
174
|
-
const responseID = message.id;
|
|
175
|
-
const {
|
|
176
|
-
transports,
|
|
177
|
-
pendingTransportEvent
|
|
178
|
-
} = settingsStore.get();
|
|
179
|
-
if (!deviceList.isConnected() && !deviceList.pendingConnection()) {
|
|
180
|
-
deviceList.init({
|
|
181
|
-
transports,
|
|
182
|
-
pendingTransportEvent
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
await deviceList.pendingConnection();
|
|
186
|
-
let tempDevice;
|
|
187
|
-
try {
|
|
188
|
-
tempDevice = selectDevice(context, message.payload.device);
|
|
189
|
-
} catch (error) {
|
|
190
|
-
if (error.code === 'Transport_Missing') {
|
|
191
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.TRANSPORT));
|
|
192
|
-
}
|
|
193
|
-
sendCoreMessage(createResponseMessage(responseID, false, {
|
|
194
|
-
error
|
|
195
|
-
}));
|
|
196
|
-
throw error;
|
|
197
|
-
}
|
|
198
|
-
const device = tempDevice;
|
|
199
|
-
method.setDevice(device);
|
|
200
|
-
const previousCall = callMethods.filter(call => call && call !== method && call.device?.getUniquePath() === method.device?.getUniquePath());
|
|
201
|
-
if (previousCall.length > 0 && method.overridePreviousCall) {
|
|
202
|
-
previousCall.forEach(call => {
|
|
203
|
-
call.overridden = true;
|
|
204
|
-
});
|
|
205
|
-
const overrideError = ERRORS.TypedError('Method_Override');
|
|
206
|
-
await device.interrupt(overrideError);
|
|
207
|
-
if (method.overridden) {
|
|
208
|
-
sendCoreMessage(createResponseMessage(method.responseID, false, {
|
|
209
|
-
error: overrideError
|
|
210
|
-
}));
|
|
211
|
-
throw overrideError;
|
|
212
|
-
}
|
|
213
|
-
} else if (device.currentRun) {
|
|
214
|
-
if (device.isUnacquired()) {
|
|
215
|
-
await device.currentRun;
|
|
216
|
-
} else {
|
|
217
|
-
sendCoreMessage(createResponseMessage(responseID, false, {
|
|
218
|
-
error: ERRORS.TypedError('Device_CallInProgress')
|
|
219
|
-
}));
|
|
220
|
-
throw ERRORS.TypedError('Device_CallInProgress');
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
device.setInstance(message.payload.device?.instance);
|
|
224
|
-
device.setState(method.deviceState);
|
|
225
|
-
registerDeviceEvents(context, method)(device);
|
|
226
|
-
method.resolveCardanoCapability();
|
|
227
|
-
let messageResponse;
|
|
228
|
-
try {
|
|
229
|
-
const innerAction = () => inner(context, method, device).then(response => {
|
|
230
|
-
messageResponse = response;
|
|
231
|
-
});
|
|
232
|
-
await device.run(innerAction, {
|
|
233
|
-
keepSession: method.keepSession,
|
|
234
|
-
skipFinalReload: method.skipFinalReload,
|
|
235
|
-
useCardanoDerivation: method.useCardanoDerivation
|
|
236
|
-
});
|
|
237
|
-
} catch (error) {
|
|
238
|
-
if (error.cause) {
|
|
239
|
-
logger.debug('device.run error caught, caused by:', error.cause);
|
|
240
|
-
}
|
|
241
|
-
if (error.code === 'Device_Disconnected') {
|
|
242
|
-
deviceList.addAuthPenalty(device);
|
|
243
|
-
}
|
|
244
|
-
if (method) {
|
|
245
|
-
if (deviceList.isConnected() && error.message === TRANSPORT_ERROR.SESSION_WRONG_PREVIOUS) {
|
|
246
|
-
await deviceList.enumerate();
|
|
247
|
-
}
|
|
248
|
-
messageResponse = createResponseMessage(method.responseID, false, {
|
|
249
|
-
error
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
} finally {
|
|
253
|
-
if (method.keepSession && method.deviceState && method.deviceState.sessionId !== device.getState()?.sessionId) {
|
|
254
|
-
device.emitDeviceChanged();
|
|
255
|
-
}
|
|
256
|
-
const response = messageResponse;
|
|
257
|
-
if (response) {
|
|
258
|
-
device.eventNames().forEach(e => device.removeAllListeners(e));
|
|
259
|
-
closePopup(context);
|
|
260
|
-
cleanup(context);
|
|
261
|
-
if (method) {
|
|
262
|
-
method.dispose();
|
|
263
|
-
}
|
|
264
|
-
if (response.success) {
|
|
265
|
-
deviceList.removeAuthPenalty(device);
|
|
266
|
-
}
|
|
267
|
-
sendCoreMessage(response);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
const cleanup = ({
|
|
272
|
-
uiPromises,
|
|
273
|
-
logger
|
|
274
|
-
}) => {
|
|
275
|
-
uiPromises.clear();
|
|
276
|
-
logger.debug('Cleanup...');
|
|
277
|
-
};
|
|
278
|
-
const closePopup = ({
|
|
279
|
-
sendCoreMessage
|
|
280
|
-
}) => {
|
|
281
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
|
|
282
|
-
};
|
|
283
|
-
const onDeviceButtonHandler = (device, context, method) => ({
|
|
284
|
-
payload: request
|
|
285
|
-
}) => {
|
|
286
|
-
const {
|
|
287
|
-
sendCoreMessage
|
|
288
|
-
} = context;
|
|
289
|
-
const data = typeof method?.getButtonRequestData === 'function' && request.code ? method?.getButtonRequestData(request.code, request.name) : undefined;
|
|
290
|
-
sendCoreMessage(createDeviceMessage(DEVICE.BUTTON, {
|
|
291
|
-
...request,
|
|
292
|
-
device: device.toMessageObject()
|
|
293
|
-
}));
|
|
294
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.REQUEST_BUTTON, {
|
|
295
|
-
...request,
|
|
296
|
-
device: device.toMessageObject(),
|
|
297
|
-
data
|
|
298
|
-
}));
|
|
299
|
-
};
|
|
300
|
-
const onDevicePinHandler = (device, context) => async ({
|
|
301
|
-
type,
|
|
302
|
-
callback
|
|
303
|
-
}) => {
|
|
304
|
-
const {
|
|
305
|
-
uiPromises,
|
|
306
|
-
sendCoreMessage
|
|
307
|
-
} = context;
|
|
308
|
-
const uiPromise = uiPromises.create(UI_RESPONSE.RECEIVE_PIN, device);
|
|
309
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
310
|
-
device: device.toMessageObject(),
|
|
311
|
-
type
|
|
312
|
-
}, {
|
|
313
|
-
requestId: uiPromise.requestId
|
|
314
|
-
}));
|
|
315
|
-
try {
|
|
316
|
-
const uiResp = await uiPromise.promise;
|
|
317
|
-
if (uiResp.payload == null) {
|
|
318
|
-
callback({
|
|
319
|
-
success: false,
|
|
320
|
-
error: new Error(`${UI_RESPONSE.RECEIVE_PIN} missing payload`)
|
|
321
|
-
});
|
|
322
|
-
} else {
|
|
323
|
-
callback({
|
|
324
|
-
success: true,
|
|
325
|
-
payload: uiResp.payload
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
} catch (error) {
|
|
329
|
-
callback({
|
|
330
|
-
success: false,
|
|
331
|
-
error
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
const onDeviceWordHandler = (device, context) => async ({
|
|
336
|
-
type,
|
|
337
|
-
callback
|
|
338
|
-
}) => {
|
|
339
|
-
const {
|
|
340
|
-
uiPromises,
|
|
341
|
-
sendCoreMessage
|
|
342
|
-
} = context;
|
|
343
|
-
const uiPromise = uiPromises.create(UI_RESPONSE.RECEIVE_WORD, device);
|
|
344
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.REQUEST_WORD, {
|
|
345
|
-
device: device.toMessageObject(),
|
|
346
|
-
type
|
|
347
|
-
}, {
|
|
348
|
-
requestId: uiPromise.requestId
|
|
349
|
-
}));
|
|
350
|
-
try {
|
|
351
|
-
const uiResp = await uiPromise.promise;
|
|
352
|
-
if (uiResp.payload == null) {
|
|
353
|
-
callback({
|
|
354
|
-
success: false,
|
|
355
|
-
error: new Error(`${UI_RESPONSE.RECEIVE_WORD} missing payload`)
|
|
356
|
-
});
|
|
357
|
-
} else {
|
|
358
|
-
callback({
|
|
359
|
-
success: true,
|
|
360
|
-
payload: uiResp.payload
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
} catch (error) {
|
|
364
|
-
callback({
|
|
365
|
-
success: false,
|
|
366
|
-
error
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
const onDevicePassphraseHandler = (device, context) => async ({
|
|
371
|
-
callback
|
|
372
|
-
}) => {
|
|
373
|
-
const {
|
|
374
|
-
uiPromises,
|
|
375
|
-
sendCoreMessage
|
|
376
|
-
} = context;
|
|
377
|
-
const uiPromise = uiPromises.create(UI_RESPONSE.RECEIVE_PASSPHRASE, device);
|
|
378
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE, {
|
|
379
|
-
device: device.toMessageObject()
|
|
380
|
-
}, {
|
|
381
|
-
requestId: uiPromise.requestId
|
|
382
|
-
}));
|
|
383
|
-
try {
|
|
384
|
-
const uiResp = await uiPromise.promise;
|
|
385
|
-
if (uiResp.payload == null) {
|
|
386
|
-
callback({
|
|
387
|
-
success: false,
|
|
388
|
-
error: new Error(`${UI_RESPONSE.RECEIVE_PASSPHRASE} missing payload`)
|
|
389
|
-
});
|
|
390
|
-
} else {
|
|
391
|
-
callback({
|
|
392
|
-
success: true,
|
|
393
|
-
payload: uiResp.payload
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
} catch (error) {
|
|
397
|
-
callback({
|
|
398
|
-
success: false,
|
|
399
|
-
error
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
const onEmptyPassphraseHandler = () => ({
|
|
404
|
-
callback
|
|
405
|
-
}) => {
|
|
406
|
-
callback({
|
|
407
|
-
success: true,
|
|
408
|
-
payload: {
|
|
409
|
-
value: ''
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
};
|
|
413
|
-
const onThpPairingHandler = (device, context) => async ({
|
|
414
|
-
callback,
|
|
415
|
-
payload
|
|
416
|
-
}) => {
|
|
417
|
-
const {
|
|
418
|
-
uiPromises,
|
|
419
|
-
sendCoreMessage
|
|
420
|
-
} = context;
|
|
421
|
-
const uiPromise = uiPromises.create(UI_RESPONSE.RECEIVE_THP_PAIRING_TAG, device);
|
|
422
|
-
sendCoreMessage(createUiMessage(UI_REQUEST.REQUEST_THP_PAIRING, {
|
|
423
|
-
device: device.toMessageObject(),
|
|
424
|
-
...payload
|
|
425
|
-
}, {
|
|
426
|
-
requestId: uiPromise.requestId
|
|
427
|
-
}));
|
|
428
|
-
try {
|
|
429
|
-
const uiResp = await uiPromise.promise;
|
|
430
|
-
if (uiResp.payload == null) {
|
|
431
|
-
callback({
|
|
432
|
-
success: false,
|
|
433
|
-
error: new Error(`${UI_RESPONSE.RECEIVE_THP_PAIRING_TAG} missing payload`)
|
|
434
|
-
});
|
|
435
|
-
} else {
|
|
436
|
-
callback({
|
|
437
|
-
success: true,
|
|
438
|
-
payload: uiResp.payload
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
} catch (error) {
|
|
442
|
-
callback({
|
|
443
|
-
success: false,
|
|
444
|
-
error
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
const onThpCredentialsChangedHandler = (device, context) => payload => {
|
|
449
|
-
const {
|
|
450
|
-
sendCoreMessage
|
|
451
|
-
} = context;
|
|
452
|
-
sendCoreMessage(createDeviceMessage(DEVICE.THP_CREDENTIALS_CHANGED, {
|
|
453
|
-
device: device.toMessageObject(),
|
|
454
|
-
...payload
|
|
455
|
-
}));
|
|
456
|
-
};
|
|
457
|
-
const onThpPhaseChangedHandler = (device, context) => payload => {
|
|
458
|
-
const {
|
|
459
|
-
sendCoreMessage
|
|
460
|
-
} = context;
|
|
461
|
-
sendCoreMessage(createDeviceMessage(DEVICE.THP_PAIRING_STATUS_CHANGED, {
|
|
462
|
-
device: device.toMessageObject(),
|
|
463
|
-
...payload
|
|
464
|
-
}));
|
|
465
|
-
};
|
|
466
|
-
const registerDeviceEvents = (context, method) => device => {
|
|
467
|
-
device.removeAllListeners();
|
|
468
|
-
device.on(DEVICE.BUTTON, onDeviceButtonHandler(device, context, method));
|
|
469
|
-
device.on(DEVICE.PIN, onDevicePinHandler(device, context));
|
|
470
|
-
device.on(DEVICE.WORD, onDeviceWordHandler(device, context));
|
|
471
|
-
device.on(DEVICE.PASSPHRASE, (method?.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler)(device, context));
|
|
472
|
-
device.on(DEVICE.PASSPHRASE_ON_DEVICE, () => {
|
|
473
|
-
context.sendCoreMessage(createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
474
|
-
device: device.toMessageObject()
|
|
475
|
-
}));
|
|
476
|
-
});
|
|
477
|
-
device.on(DEVICE.FIRMWARE_VERSION_CHANGED, payload => {
|
|
478
|
-
context.sendCoreMessage(createDeviceMessage(DEVICE.FIRMWARE_VERSION_CHANGED, payload));
|
|
479
|
-
});
|
|
480
|
-
device.on(DEVICE.THP_PAIRING, onThpPairingHandler(device, context));
|
|
481
|
-
device.on(DEVICE.THP_CREDENTIALS_CHANGED, onThpCredentialsChangedHandler(device, context));
|
|
482
|
-
device.on(DEVICE.THP_PAIRING_STATUS_CHANGED, onThpPhaseChangedHandler(device, context));
|
|
483
|
-
};
|
|
484
|
-
const abortRunningCall = (context, error, callId) => {
|
|
485
|
-
const {
|
|
486
|
-
uiPromises,
|
|
487
|
-
deviceList,
|
|
488
|
-
callMethods,
|
|
489
|
-
resetWaitForFirstMethod,
|
|
490
|
-
sendCoreMessage
|
|
491
|
-
} = context;
|
|
492
|
-
if (callId) {
|
|
493
|
-
const method = callMethods.find(m => m.callId === callId);
|
|
494
|
-
if (!method) {
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
if (method.device?.isUsedHere()) {
|
|
498
|
-
method.device.interrupt(error);
|
|
499
|
-
} else {
|
|
500
|
-
sendCoreMessage(createResponseMessage(method.responseID, false, {
|
|
501
|
-
error
|
|
502
|
-
}));
|
|
503
|
-
}
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
if (deviceList.isConnected() && deviceList.getDeviceCount() > 0) {
|
|
507
|
-
deviceList.getAllDevices().forEach(d => {
|
|
508
|
-
if (d.isUsedHere()) {
|
|
509
|
-
d.interrupt(error);
|
|
510
|
-
} else {
|
|
511
|
-
const success = uiPromises.resolve({
|
|
512
|
-
type: DEVICE.DISCONNECT,
|
|
513
|
-
payload: undefined
|
|
514
|
-
});
|
|
515
|
-
if (!success) {
|
|
516
|
-
callMethods.forEach(m => {
|
|
517
|
-
sendCoreMessage(createResponseMessage(m.responseID, false, {
|
|
518
|
-
error
|
|
519
|
-
}));
|
|
520
|
-
});
|
|
521
|
-
callMethods.splice(0, callMethods.length);
|
|
522
|
-
resetWaitForFirstMethod();
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
} else {
|
|
527
|
-
uiPromises.rejectAll(error);
|
|
528
|
-
}
|
|
529
|
-
cleanup(context);
|
|
530
|
-
};
|
|
531
|
-
const onPopupClosed = context => {
|
|
532
|
-
abortRunningCall(context, ERRORS.TypedError('Method_Interrupted'));
|
|
533
|
-
};
|
|
534
|
-
const onCallCancel = (context, reason, callId) => {
|
|
535
|
-
abortRunningCall(context, ERRORS.TypedError('Method_Cancel', reason), callId);
|
|
536
|
-
};
|
|
537
|
-
const initDeviceList = context => {
|
|
538
|
-
const {
|
|
539
|
-
deviceList,
|
|
540
|
-
sendCoreMessage,
|
|
541
|
-
logger
|
|
542
|
-
} = context;
|
|
543
|
-
deviceList.on(DEVICE.CONNECT, device => {
|
|
544
|
-
sendCoreMessage(createDeviceMessage(DEVICE.CONNECT, device.toMessageObject()));
|
|
545
|
-
});
|
|
546
|
-
deviceList.on(DEVICE.CONNECT_UNACQUIRED, device => {
|
|
547
|
-
sendCoreMessage(createDeviceMessage(DEVICE.CONNECT_UNACQUIRED, device.toMessageObject()));
|
|
548
|
-
});
|
|
549
|
-
deviceList.on(DEVICE.DISCONNECT, device => {
|
|
550
|
-
sendCoreMessage(createDeviceMessage(DEVICE.DISCONNECT, device.toMessageObject()));
|
|
551
|
-
});
|
|
552
|
-
deviceList.on(DEVICE.CHANGED, device => {
|
|
553
|
-
sendCoreMessage(createDeviceMessage(DEVICE.CHANGED, device.toMessageObject()));
|
|
554
|
-
});
|
|
555
|
-
deviceList.on(DEVICE.TREZOR_PUSH_NOTIFICATION, payload => {
|
|
556
|
-
sendCoreMessage(createDeviceMessage(DEVICE.TREZOR_PUSH_NOTIFICATION, {
|
|
557
|
-
device: payload.device.toMessageObject(),
|
|
558
|
-
mode: payload.mode,
|
|
559
|
-
type: payload.type
|
|
560
|
-
}));
|
|
561
|
-
});
|
|
562
|
-
deviceList.on(TRANSPORT.START, transport => sendCoreMessage(createTransportMessage(TRANSPORT.START, transport)));
|
|
563
|
-
deviceList.on(TRANSPORT.ERROR, error => {
|
|
564
|
-
logger.warn('TRANSPORT.ERROR', error.error);
|
|
565
|
-
sendCoreMessage(createTransportMessage(TRANSPORT.ERROR, error));
|
|
566
|
-
});
|
|
567
|
-
};
|
|
568
|
-
export class Core extends EventEmitter {
|
|
569
|
-
abortController = new AbortController();
|
|
570
|
-
callMethods = [];
|
|
571
|
-
methodSynchronize = getSynchronize();
|
|
572
|
-
uiPromises = createUiPromiseManager();
|
|
573
|
-
createLogger = noopCreateLogger;
|
|
574
|
-
coreLogger = noopLogger;
|
|
575
|
-
waitForFirstMethod = createDeferred();
|
|
576
|
-
_deviceList;
|
|
577
|
-
get deviceList() {
|
|
578
|
-
return this._deviceList ?? throwError('Core not initialized: deviceList');
|
|
579
|
-
}
|
|
580
|
-
sendCoreMessage(message) {
|
|
581
|
-
if (message.event === RESPONSE_EVENT) {
|
|
582
|
-
const index = this.callMethods.findIndex(call => call?.responseID === message.id);
|
|
583
|
-
if (index >= 0) {
|
|
584
|
-
this.callMethods.splice(index, 1);
|
|
585
|
-
if (this.callMethods.length === 0) {
|
|
586
|
-
this.waitForFirstMethod = createDeferred();
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
this.emit(CORE_EVENT, message);
|
|
591
|
-
}
|
|
592
|
-
getCoreContext() {
|
|
593
|
-
return {
|
|
594
|
-
signal: this.abortController.signal,
|
|
595
|
-
uiPromises: this.uiPromises,
|
|
596
|
-
deviceList: this.deviceList,
|
|
597
|
-
logger: this.coreLogger,
|
|
598
|
-
callMethods: this.callMethods,
|
|
599
|
-
methodSynchronize: this.methodSynchronize,
|
|
600
|
-
sendCoreMessage: this.sendCoreMessage.bind(this),
|
|
601
|
-
resetWaitForFirstMethod: () => {
|
|
602
|
-
this.waitForFirstMethod = createDeferred();
|
|
603
|
-
},
|
|
604
|
-
resolveWaitForFirstMethod: () => {
|
|
605
|
-
this.waitForFirstMethod.resolve();
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
handleMessage(message) {
|
|
610
|
-
this.coreLogger.debug('handleMessage', message.type);
|
|
611
|
-
switch (message.type) {
|
|
612
|
-
case POPUP.CLOSED:
|
|
613
|
-
onPopupClosed(this.getCoreContext());
|
|
614
|
-
break;
|
|
615
|
-
case CORE_CALL_CANCEL:
|
|
616
|
-
onCallCancel(this.getCoreContext(), message.payload?.reason, message.payload?.callId);
|
|
617
|
-
break;
|
|
618
|
-
case TRANSPORT.SET_TRANSPORTS:
|
|
619
|
-
settingsStore.update({
|
|
620
|
-
transports: message.payload.transports
|
|
621
|
-
});
|
|
622
|
-
resetTransports(this.getCoreContext());
|
|
623
|
-
break;
|
|
624
|
-
case SET_ENABLED_NETWORKS:
|
|
625
|
-
enabledNetworksStore.add(message.payload);
|
|
626
|
-
break;
|
|
627
|
-
case TRANSPORT.REQUEST_DEVICE:
|
|
628
|
-
if (this.deviceList.isConnected()) {
|
|
629
|
-
this.deviceList.enumerate();
|
|
630
|
-
}
|
|
631
|
-
break;
|
|
632
|
-
case TRANSPORT.GET_INFO:
|
|
633
|
-
this.sendCoreMessage(createResponseMessage(message.id, true, this.getActiveTransports()));
|
|
634
|
-
break;
|
|
635
|
-
case UI_RESPONSE.RECEIVE_CONFIRMATION:
|
|
636
|
-
case UI_RESPONSE.RECEIVE_PIN:
|
|
637
|
-
case UI_RESPONSE.RECEIVE_PASSPHRASE:
|
|
638
|
-
case UI_RESPONSE.RECEIVE_THP_PAIRING_TAG:
|
|
639
|
-
case UI_RESPONSE.RECEIVE_ACCOUNT:
|
|
640
|
-
case UI_RESPONSE.RECEIVE_FEE:
|
|
641
|
-
case UI_RESPONSE.RECEIVE_WORD:
|
|
642
|
-
case UI_RESPONSE.RECEIVE_DISCOVERY_ACCOUNTS:
|
|
643
|
-
this.uiPromises.resolve(message);
|
|
644
|
-
break;
|
|
645
|
-
case UI_RESPONSE.RECEIVE_FIRMWARE:
|
|
646
|
-
{
|
|
647
|
-
const localFirmwares = message.payload && parseLocalFirmwares(message.payload);
|
|
648
|
-
if (localFirmwares) {
|
|
649
|
-
localFirmwareStore.set(localFirmwares);
|
|
650
|
-
}
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
case CORE_CALL:
|
|
654
|
-
if (message.payload.method === 'firmwareUpdate') {
|
|
655
|
-
if (message.payload.__info) {
|
|
656
|
-
this.sendCoreMessage(createResponseMessage(message.id, true, {
|
|
657
|
-
name: 'firmwareUpdate',
|
|
658
|
-
info: 'Update firmware',
|
|
659
|
-
requiredPermissions: [{
|
|
660
|
-
permission: 'internal'
|
|
661
|
-
}],
|
|
662
|
-
useUi: true,
|
|
663
|
-
useDevice: true,
|
|
664
|
-
useDeviceState: false
|
|
665
|
-
}));
|
|
666
|
-
break;
|
|
667
|
-
}
|
|
668
|
-
assertDeviceListConnected(this.deviceList);
|
|
669
|
-
const coreContext = this.getCoreContext();
|
|
670
|
-
const sendCoreMessageWithCallId = createSendCoreMessageWithCallId(this.sendCoreMessage.bind(this), message.payload.callId);
|
|
671
|
-
onCallFirmwareUpdate({
|
|
672
|
-
params: message.payload,
|
|
673
|
-
context: {
|
|
674
|
-
deviceList: this.deviceList,
|
|
675
|
-
postMessage: sendCoreMessageWithCallId,
|
|
676
|
-
selectDevice: path => selectDevice(coreContext, {
|
|
677
|
-
path
|
|
678
|
-
}),
|
|
679
|
-
log: this.coreLogger,
|
|
680
|
-
abortSignal: this.abortController.signal,
|
|
681
|
-
registerEvents: registerDeviceEvents(coreContext),
|
|
682
|
-
uiPromises: coreContext.uiPromises
|
|
683
|
-
}
|
|
684
|
-
}).then(payload => {
|
|
685
|
-
this.sendCoreMessage(createResponseMessage(message.id, true, payload));
|
|
686
|
-
}).catch(error => {
|
|
687
|
-
this.sendCoreMessage(createResponseMessage(message.id, false, {
|
|
688
|
-
error
|
|
689
|
-
}));
|
|
690
|
-
this.coreLogger.error('onCallFirmwareUpdate', error);
|
|
691
|
-
});
|
|
692
|
-
} else {
|
|
693
|
-
onCall(this.getCoreContext(), message).catch(error => {
|
|
694
|
-
this.coreLogger.error('onCall', error);
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
dispose() {
|
|
700
|
-
disposeBackend();
|
|
701
|
-
this.removeAllListeners();
|
|
702
|
-
this.abortController.abort();
|
|
703
|
-
this.deviceList.dispose();
|
|
704
|
-
}
|
|
705
|
-
async getCurrentMethod() {
|
|
706
|
-
await this.waitForFirstMethod.promise;
|
|
707
|
-
return await this.methodSynchronize(() => this.callMethods[0]);
|
|
708
|
-
}
|
|
709
|
-
getActiveTransports() {
|
|
710
|
-
if (this.deviceList.isConnected()) {
|
|
711
|
-
return this.deviceList.getActiveTransports();
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
enumerate() {
|
|
715
|
-
if (this.deviceList.isConnected()) {
|
|
716
|
-
this.deviceList.enumerate();
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
async init(settings, onCoreEvent, logWriterFactory) {
|
|
720
|
-
if (logWriterFactory) {
|
|
721
|
-
setLogWriter(logWriterFactory);
|
|
722
|
-
}
|
|
723
|
-
this.createLogger = settings.createLogger ?? noopCreateLogger;
|
|
724
|
-
this.coreLogger = this.createLogger('Core');
|
|
725
|
-
const throttlePromise = createDeferred();
|
|
726
|
-
throttlePromise.promise.catch(() => {});
|
|
727
|
-
const onCoreEventThrottled = message => throttlePromise.promise.then(() => onCoreEvent(message));
|
|
728
|
-
try {
|
|
729
|
-
settingsStore.set({
|
|
730
|
-
...settings,
|
|
731
|
-
enabledNetworks: undefined
|
|
732
|
-
});
|
|
733
|
-
enabledNetworksStore.set(settings.enabledNetworks ?? []);
|
|
734
|
-
await firmwareReleaseStore.init(settings.firmwareChannel, false, initializeFirmwareConfig);
|
|
735
|
-
const localFirmwares = settings.localFirmwares && parseLocalFirmwares(settings.localFirmwares);
|
|
736
|
-
if (localFirmwares) {
|
|
737
|
-
localFirmwareStore.set(localFirmwares);
|
|
738
|
-
}
|
|
739
|
-
await loadProtobufModules();
|
|
740
|
-
this._deviceList = new DeviceList({
|
|
741
|
-
createLogger: this.createLogger
|
|
742
|
-
});
|
|
743
|
-
initDeviceList(this.getCoreContext());
|
|
744
|
-
this.on(CORE_EVENT, onCoreEventThrottled);
|
|
745
|
-
} catch (error) {
|
|
746
|
-
this.coreLogger.error('init', error);
|
|
747
|
-
throttlePromise.reject(error);
|
|
748
|
-
throw error;
|
|
749
|
-
}
|
|
750
|
-
const {
|
|
751
|
-
transports,
|
|
752
|
-
pendingTransportEvent,
|
|
753
|
-
transportReconnect
|
|
754
|
-
} = settingsStore.get();
|
|
755
|
-
try {
|
|
756
|
-
this.deviceList.init({
|
|
757
|
-
transports,
|
|
758
|
-
pendingTransportEvent,
|
|
759
|
-
transportReconnect
|
|
760
|
-
});
|
|
761
|
-
} catch (error) {
|
|
762
|
-
this.sendCoreMessage(createTransportMessage(TRANSPORT.ERROR, {
|
|
763
|
-
error
|
|
764
|
-
}));
|
|
765
|
-
throttlePromise.reject(error);
|
|
766
|
-
throw error;
|
|
767
|
-
}
|
|
768
|
-
if (!transportReconnect) {
|
|
769
|
-
await this.deviceList.pendingConnection();
|
|
770
|
-
}
|
|
771
|
-
this.on(CORE_EVENT, onCoreEvent);
|
|
772
|
-
this.off(CORE_EVENT, onCoreEventThrottled);
|
|
773
|
-
setTimeout(throttlePromise.resolve, 0);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
const resetTransports = async ({
|
|
777
|
-
deviceList,
|
|
778
|
-
sendCoreMessage
|
|
779
|
-
}) => {
|
|
780
|
-
const {
|
|
781
|
-
transports,
|
|
782
|
-
pendingTransportEvent,
|
|
783
|
-
transportReconnect
|
|
784
|
-
} = settingsStore.get();
|
|
785
|
-
try {
|
|
786
|
-
await deviceList.init({
|
|
787
|
-
transports,
|
|
788
|
-
pendingTransportEvent,
|
|
789
|
-
transportReconnect
|
|
790
|
-
});
|
|
791
|
-
} catch (error) {
|
|
792
|
-
sendCoreMessage(createTransportMessage(TRANSPORT.ERROR, {
|
|
793
|
-
error
|
|
794
|
-
}));
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
const initCore = async (...params) => {
|
|
798
|
-
const core = new Core();
|
|
799
|
-
await core.init(...params);
|
|
800
|
-
return core;
|
|
801
|
-
};
|
|
802
|
-
const disposeCore = core => {
|
|
803
|
-
core.dispose();
|
|
804
|
-
};
|
|
805
|
-
export const initCoreState = () => createLazy(initCore, disposeCore);
|