From 76ccd79e6c4dc6f1d3269e8f9ac7740f8771ffb7 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Thu, 26 Nov 2026 19:01:57 +0100 Subject: [PATCH 1/4] fix: ask for the pin when a logged-out jade is used A Jade logged out on the device (Session > Log Out, or a timeout) answered Verify on Device and Sign With Jade with DeviceLocked, which showed as busy. Like iOS, the request now unlocks the Jade through the pinserver, checks it opened the same wallet, and runs once more. Verified: just compile, just test, just lint and assembleDevDebug passed on this change. --- .../java/to/bitkit/ext/JadeExceptionExt.kt | 3 ++ .../java/to/bitkit/repositories/JadeRepo.kt | 41 +++++++++++++++--- .../to/bitkit/repositories/JadeRepoTest.kt | 43 +++++++++++++++++++ changelog.d/next/2050.fixed.md | 1 + journeys/hardware-wallet/README.md | 5 +-- .../hardware-wallet/jade-device-locked.xml | 8 +++- 6 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 changelog.d/next/2050.fixed.md diff --git a/app/src/main/java/to/bitkit/ext/JadeExceptionExt.kt b/app/src/main/java/to/bitkit/ext/JadeExceptionExt.kt index bb72fc8bb5..6f6b386f8c 100644 --- a/app/src/main/java/to/bitkit/ext/JadeExceptionExt.kt +++ b/app/src/main/java/to/bitkit/ext/JadeExceptionExt.kt @@ -9,6 +9,9 @@ fun Throwable.isJadeUserCancellation(): Boolean = fun Throwable.isJadeDeviceBusy(): Boolean = generateSequence(this) { it.cause }.any { it is JadeException.DeviceBusy || it is JadeException.DeviceLocked } +fun Throwable.isJadeDeviceLocked(): Boolean = + generateSequence(this) { it.cause }.any { it is JadeException.DeviceLocked } + fun Throwable.isJadeFirmwareError(): Boolean = generateSequence(this) { it.cause }.any { it is JadeException.UnsupportedFirmware } diff --git a/app/src/main/java/to/bitkit/repositories/JadeRepo.kt b/app/src/main/java/to/bitkit/repositories/JadeRepo.kt index df0d147de8..f5a03ff746 100644 --- a/app/src/main/java/to/bitkit/repositories/JadeRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/JadeRepo.kt @@ -36,6 +36,7 @@ import to.bitkit.data.PendingNameUpdate import to.bitkit.di.IoDispatcher import to.bitkit.env.Env import to.bitkit.ext.isJadeDeviceBusy +import to.bitkit.ext.isJadeDeviceLocked import to.bitkit.ext.isJadeUserCancellation import to.bitkit.ext.nowMs import to.bitkit.ext.runSuspendCatching @@ -352,12 +353,14 @@ class JadeRepo @Inject constructor( expectedAddress: String, ): Result = withContext(ioDispatcher) { runSuspendCatching { - jadeService.verifyAddress( - network = Env.network.toJadeNetwork(), - variant = addressType.jadeVariant, - derivationPath = derivationPath, - expectedAddress = expectedAddress, - ) + retryingOnceIfLocked { + jadeService.verifyAddress( + network = Env.network.toJadeNetwork(), + variant = addressType.jadeVariant, + derivationPath = derivationPath, + expectedAddress = expectedAddress, + ) + } }.onFailure { Logger.error("Jade verifyAddress failed", it, context = TAG) _state.update { s -> s.copy(error = errorMessage(it)) } @@ -367,7 +370,9 @@ class JadeRepo @Inject constructor( /** Signs on the device and completes the PSBT into a broadcastable transaction. */ suspend fun signPsbt(psbtBase64: String): Result = withContext(ioDispatcher) { runSuspendCatching { - val signed = jadeService.signPsbt(network = Env.network.toJadeNetwork(), psbtBase64 = psbtBase64) + val signed = retryingOnceIfLocked { + jadeService.signPsbt(network = Env.network.toJadeNetwork(), psbtBase64 = psbtBase64) + } jadeService.finalizePsbt(originalPsbt = psbtBase64, signedPsbt = signed) }.onFailure { Logger.error("Jade signPsbt failed", it, context = TAG) @@ -723,6 +728,28 @@ class JadeRepo @Inject constructor( } } + /** + * A Jade logged out or timed out on the device since it connected answers with [JadeException.DeviceLocked]: + * it asks for its PIN, must open the same wallet, and the request runs once more. + */ + private suspend fun retryingOnceIfLocked(operation: suspend () -> T): T { + try { + return operation() + } catch (e: Throwable) { + if (!e.isJadeDeviceLocked()) throw e + val current = _state.value.connected ?: throw e + Logger.info("The Jade locked since it connected; unlocking and retrying", context = TAG) + val locked = current.copy(versionInfo = current.versionInfo.copy(jadeState = JadeState.LOCKED)) + _state.update { it.copy(connected = locked) } + val unlocked = ensureConnected(current.id, current.walletId).getOrThrow() + if (current.walletId != null && unlocked.walletId != current.walletId) { + Logger.warn("The Jade unlocked into another wallet than '${current.walletId}'", context = TAG) + throw HwWalletMismatchError() + } + return operation() + } + } + private suspend fun unlockConnected(): JadeVersionInfo { _state.update { it.copy(isUnlocking = true) } try { diff --git a/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt b/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt index 78a573ba78..6578ab799b 100644 --- a/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt +++ b/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt @@ -40,6 +40,7 @@ import to.bitkit.models.TransportType import to.bitkit.services.JadeService import to.bitkit.services.JadeTransport import to.bitkit.test.BaseUnitTest +import to.bitkit.utils.AppError import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertIs @@ -728,6 +729,48 @@ class JadeRepoTest : BaseUnitTest() { verify(jadeService).verifyAddress(JadeNetwork.REGTEST, JadeAddressVariant.WPKH, "m/84'/1'/0'/0/0", "bcrt1q") } + @Test + fun `verifyAddress unlocks a jade logged out on the device and retries once`() = test { + val sut = connectedReadyRepo(listOf(knownUsb)) + var calls = 0 + whenever { jadeService.verifyAddress(any(), any(), any(), any()) }.doSuspendableAnswer { + if (calls++ == 0) throw AppError(JadeException.DeviceLocked()) + } + + val result = sut.verifyAddress(HwFundingAddressType.NATIVE_SEGWIT, "m/84'/1'/0'/0/0", "bcrt1q") + + assertTrue(result.isSuccess) + assertEquals(2, calls) + verify(jadeService).unlock(JadeNetwork.REGTEST) + assertEquals(WALLET_ID, sut.state.value.connectedWalletId()) + } + + @Test + fun `signPsbt refuses a jade logged out on the device that unlocks into another wallet`() = test { + val sut = connectedReadyRepo(listOf(knownUsb, passphraseUsb)) + whenever { jadeService.signPsbt(any(), any()) } + .doSuspendableAnswer { throw AppError(JadeException.DeviceLocked()) } + whenever { jadeService.getAccountExport(any(), any(), any()) }.thenReturn(accountExport(xpub = "zpubPass")) + + val result = sut.signPsbt("psbt") + + assertIs(result.exceptionOrNull()) + verify(jadeService).unlock(JadeNetwork.REGTEST) + verify(jadeService, times(1)).signPsbt(any(), any()) + } + + /** A paired Jade connected and unlocked into [WALLET_ID]. */ + private suspend fun connectedReadyRepo(known: List): JadeRepo { + whenever { hwWalletStore.loadKnownDevices(HwWalletVendor.BLOCKSTREAM) }.thenReturn(known) + whenever { jadeService.scan(any(), any()) }.thenReturn(listOf(usbDevice)) + whenever { jadeService.connect(any(), any(), any()) }.thenReturn(versionInfo(JadeState.READY)) + val sut = createRepo() + val connected = sut.autoReconnect(preferredTransport = TransportType.USB).getOrThrow() + assertEquals(WALLET_ID, connected.walletId) + whenever { jadeService.isConnected() }.thenReturn(true) + return sut + } + private fun createRepo() = JadeRepo( context = context, jadeService = jadeService, diff --git a/changelog.d/next/2050.fixed.md b/changelog.d/next/2050.fixed.md new file mode 100644 index 0000000000..5758427dbb --- /dev/null +++ b/changelog.d/next/2050.fixed.md @@ -0,0 +1 @@ +Fixed a Jade logged out on the device showing as busy: it now asks for its PIN and carries on. diff --git a/journeys/hardware-wallet/README.md b/journeys/hardware-wallet/README.md index 95cca5216d..3622627d2e 100644 --- a/journeys/hardware-wallet/README.md +++ b/journeys/hardware-wallet/README.md @@ -84,7 +84,7 @@ the other three rely on, and `passphrase-settings-remove.xml` removes it again. | `jade-uninitialized.xml` | Jade emulator with no wallet: Found shows the not-set-up message | | `jade-wrong-pin.xml` | Interactive Jade emulator: wrong PIN on the device → Found shows the wrong-PIN message, retry pairs | | `jade-network-mismatch.xml` | Jade emulator restricted to mainnet: Found shows the network message | -| `jade-device-locked.xml` | Interactive Jade logged out on the device after pairing: Verify on Device shows the busy message | +| `jade-device-locked.xml` | Interactive Jade logged out on the device after pairing: Verify on Device asks for the PIN on the device and retries | | `jade-psbt-too-large.xml` | Jade with about 200 small inputs: sending all of it shows the too-large message | | `jade-sign-on-device.xml` | Interactive Jade: decline on the device keeps the payment unsent, approve sends it | | `jade-wallet-mismatch.xml` | Paired Jade reseeded: Verify on Device shows the different-wallet message | @@ -179,7 +179,6 @@ The error journeys start the emulator in another state first: `jade-uninitialize (`JADE_MNEMONIC=`), `jade-wrong-pin.xml` (`JADE_MODE=interactive`, where the device shows its own PIN pad and `./scripts/jade-emulator pin` types on it) and `jade-network-mismatch.xml` (`JADE_NETWORK=mainnet`), and `jade-device-locked.xml` logs the interactive device out after -pairing (Android reports the locked Jade as busy; iOS asks for the PIN on the device again and retries, -so its copy of the journey checks that); `jade-psbt-too-large.xml` needs the app on the bitkit-docker Electrum and about 200 small +pairing, so the next request asks for the PIN on the device again and retries; `jade-psbt-too-large.xml` needs the app on the bitkit-docker Electrum and about 200 small inputs on the Jade. `jade-sign-on-device.xml` declines and then approves a payment on the interactive device's own screens. `jade-wallet-mismatch.xml` restarts the emulator with another seed after pairing. `jade-passphrase.xml` starts it with `JADE_PASSPHRASE=always` and pairs the wallet a passphrase typed on the device opens (`./scripts/jade-emulator passphrase`). The bitkit-docker `docs/jade-emulator.md` lists the modes and recipes. diff --git a/journeys/hardware-wallet/jade-device-locked.xml b/journeys/hardware-wallet/jade-device-locked.xml index f67eb0e352..3a5c261c27 100644 --- a/journeys/hardware-wallet/jade-device-locked.xml +++ b/journeys/hardware-wallet/jade-device-locked.xml @@ -3,7 +3,8 @@ Logs the paired Jade out on the device itself and checks the message the app shows when it next needs the Jade. Requires `JADE_MODE=interactive ./scripts/jade-emulator start` in `bitkit-docker`, a regtest debug build with the Jade emulator enabled (see the README) and no - Jade paired. The device answers the next request with HW_LOCKED, which the app reports as busy. + Jade paired. The device answers the next request with HW_LOCKED, and the app asks for the PIN on + the device again and retries. @@ -22,7 +23,10 @@ Run `./scripts/jade-emulator press front right front` in `bitkit-docker` to choose Session, then Log Out, on the device - Tap Receive (testTag "Receive"), select the Jade tab, tap "Show Details" if the address is hidden behind it, then tap "Verify on Device" (testTag "HardwareVerifyAddress") and verify a toast reads "Your Jade is busy. Finish what is shown on the device, then try again." + Tap Receive (testTag "Receive"), select the Jade tab, tap "Show Details" if the address is hidden behind it, then tap "Verify on Device" (testTag "HardwareVerifyAddress") and verify the Jade shows its PIN pad again + + + Run `./scripts/jade-emulator pin 012345`, then `./scripts/jade-emulator press right front` once the device shows Verify Address, and verify the button returns to "Verify on Device" with no error From 3e148301c7898f3fe377cda3611e527a87d03962 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Thu, 26 Nov 2026 20:03:06 +0100 Subject: [PATCH 2/4] fix: unlock a logged-out jade in the connect step A Jade logged out on the device now marks its session locked on any DeviceLocked answer, and the caller's connect step unlocks it: Verify on Device and the send sheet's compose and sign. The PIN prompt then gets the Jade reconnect budget, the sheet can still be left while it waits, and the fingerprint read before composing is covered too. Verified: just compile, just test, just lint and assembleDevDebug passed on this change. --- .../to/bitkit/repositories/HwWalletRepo.kt | 7 +++ .../java/to/bitkit/repositories/JadeRepo.kt | 51 +++++++------------ .../screens/wallets/send/HwSendViewModel.kt | 18 +++++-- .../to/bitkit/repositories/JadeRepoTest.kt | 37 ++++---------- .../wallets/send/HwSendViewModelTest.kt | 19 +++++++ 5 files changed, 71 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/to/bitkit/repositories/HwWalletRepo.kt b/app/src/main/java/to/bitkit/repositories/HwWalletRepo.kt index 0a6aac25a9..1c9cd0cf3c 100644 --- a/app/src/main/java/to/bitkit/repositories/HwWalletRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/HwWalletRepo.kt @@ -46,6 +46,7 @@ import to.bitkit.data.SettingsStore import to.bitkit.di.IoDispatcher import to.bitkit.env.Env import to.bitkit.ext.isHwSessionFailure +import to.bitkit.ext.isJadeDeviceLocked import to.bitkit.ext.runSuspendCatching import to.bitkit.ext.scopedId import to.bitkit.ext.timestamp @@ -705,6 +706,12 @@ class HwWalletRepo @Inject constructor( ensureConnected(walletId).getOrThrow() runSuspendCatching { verifyOnDevice() } + .recoverCatching { error -> + // A Jade logged out on the device asks for its PIN on reconnect, which also checks its wallet. + if (!error.isJadeDeviceLocked()) throw error + ensureConnected(walletId).getOrThrow() + verifyOnDevice() + } .recoverCatching { error -> if (!error.isHwSessionFailure()) throw error disconnectStaleSession(walletId).getOrThrow() diff --git a/app/src/main/java/to/bitkit/repositories/JadeRepo.kt b/app/src/main/java/to/bitkit/repositories/JadeRepo.kt index f5a03ff746..1b0f586aaa 100644 --- a/app/src/main/java/to/bitkit/repositories/JadeRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/JadeRepo.kt @@ -353,15 +353,14 @@ class JadeRepo @Inject constructor( expectedAddress: String, ): Result = withContext(ioDispatcher) { runSuspendCatching { - retryingOnceIfLocked { - jadeService.verifyAddress( - network = Env.network.toJadeNetwork(), - variant = addressType.jadeVariant, - derivationPath = derivationPath, - expectedAddress = expectedAddress, - ) - } + jadeService.verifyAddress( + network = Env.network.toJadeNetwork(), + variant = addressType.jadeVariant, + derivationPath = derivationPath, + expectedAddress = expectedAddress, + ) }.onFailure { + markLockedIfLoggedOut(it) Logger.error("Jade verifyAddress failed", it, context = TAG) _state.update { s -> s.copy(error = errorMessage(it)) } } @@ -370,11 +369,10 @@ class JadeRepo @Inject constructor( /** Signs on the device and completes the PSBT into a broadcastable transaction. */ suspend fun signPsbt(psbtBase64: String): Result = withContext(ioDispatcher) { runSuspendCatching { - val signed = retryingOnceIfLocked { - jadeService.signPsbt(network = Env.network.toJadeNetwork(), psbtBase64 = psbtBase64) - } + val signed = jadeService.signPsbt(network = Env.network.toJadeNetwork(), psbtBase64 = psbtBase64) jadeService.finalizePsbt(originalPsbt = psbtBase64, signedPsbt = signed) }.onFailure { + markLockedIfLoggedOut(it) Logger.error("Jade signPsbt failed", it, context = TAG) _state.update { s -> s.copy(error = errorMessage(it)) } } @@ -382,7 +380,10 @@ class JadeRepo @Inject constructor( suspend fun getMasterFingerprint(): Result = withContext(ioDispatcher) { runSuspendCatching { jadeService.getMasterFingerprint(Env.network.toJadeNetwork()) } - .onFailure { Logger.error("Jade getMasterFingerprint failed", it, context = TAG) } + .onFailure { + markLockedIfLoggedOut(it) + Logger.error("Jade getMasterFingerprint failed", it, context = TAG) + } } suspend fun disconnect(): Result = withContext(ioDispatcher) { @@ -728,26 +729,12 @@ class JadeRepo @Inject constructor( } } - /** - * A Jade logged out or timed out on the device since it connected answers with [JadeException.DeviceLocked]: - * it asks for its PIN, must open the same wallet, and the request runs once more. - */ - private suspend fun retryingOnceIfLocked(operation: suspend () -> T): T { - try { - return operation() - } catch (e: Throwable) { - if (!e.isJadeDeviceLocked()) throw e - val current = _state.value.connected ?: throw e - Logger.info("The Jade locked since it connected; unlocking and retrying", context = TAG) - val locked = current.copy(versionInfo = current.versionInfo.copy(jadeState = JadeState.LOCKED)) - _state.update { it.copy(connected = locked) } - val unlocked = ensureConnected(current.id, current.walletId).getOrThrow() - if (current.walletId != null && unlocked.walletId != current.walletId) { - Logger.warn("The Jade unlocked into another wallet than '${current.walletId}'", context = TAG) - throw HwWalletMismatchError() - } - return operation() - } + private fun markLockedIfLoggedOut(error: Throwable) { + if (!error.isJadeDeviceLocked()) return + val current = _state.value.connected ?: return + Logger.info("Marked Jade '${current.id}' locked after it logged out on the device", context = TAG) + val locked = current.copy(versionInfo = current.versionInfo.copy(jadeState = JadeState.LOCKED)) + _state.update { it.copy(connected = locked) } } private suspend fun unlockConnected(): JadeVersionInfo { diff --git a/app/src/main/java/to/bitkit/ui/screens/wallets/send/HwSendViewModel.kt b/app/src/main/java/to/bitkit/ui/screens/wallets/send/HwSendViewModel.kt index 3330e9dbe5..edd5ae6177 100644 --- a/app/src/main/java/to/bitkit/ui/screens/wallets/send/HwSendViewModel.kt +++ b/app/src/main/java/to/bitkit/ui/screens/wallets/send/HwSendViewModel.kt @@ -31,6 +31,7 @@ import to.bitkit.ext.isHwDeviceBusy import to.bitkit.ext.isHwFirmwareError import to.bitkit.ext.isHwSessionFailure import to.bitkit.ext.isHwUserCancellation +import to.bitkit.ext.isJadeDeviceLocked import to.bitkit.ext.runSuspendCatching import to.bitkit.models.HwFundingBroadcastResult import to.bitkit.models.HwFundingSignedTx @@ -640,8 +641,7 @@ class HwSendViewModel @Inject constructor( amountSats: ULong, satsPerVByte: ULong, ): HwFundingSignedTx { - ensureConnected(walletId) - val funding = withTimeout(COMPOSE_TIMEOUT) { + suspend fun compose() = withTimeout(COMPOSE_TIMEOUT) { hwWalletRepo.composeFundingTransaction( walletId = walletId, address = address, @@ -649,13 +649,25 @@ class HwSendViewModel @Inject constructor( satsPerVByte = satsPerVByte, ).getOrThrow() } + + ensureConnected(walletId) + val firstAttempt = runSuspendCatching { compose() } + val error = firstAttempt.exceptionOrNull() + val funding = if (error == null) { + firstAttempt.getOrThrow() + } else { + // A Jade logged out on the device asks for its PIN here, where the sheet can still be left. + if (!error.isJadeDeviceLocked()) throw error + ensureConnected(walletId) + compose() + } return sign(walletId, funding) } private suspend fun sign(walletId: String, funding: HwFundingTransaction): HwFundingSignedTx { val firstAttempt = runSuspendCatching { signWithTimeoutCleanup(walletId, funding) } val error = firstAttempt.exceptionOrNull() ?: return firstAttempt.getOrThrow() - if (!error.isHwSessionFailure()) throw error + if (!error.isHwSessionFailure() && !error.isJadeDeviceLocked()) throw error ensureConnected(walletId) return signWithTimeoutCleanup(walletId, funding) diff --git a/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt b/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt index 6578ab799b..d406703b00 100644 --- a/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt +++ b/app/src/test/java/to/bitkit/repositories/JadeRepoTest.kt @@ -730,38 +730,23 @@ class JadeRepoTest : BaseUnitTest() { } @Test - fun `verifyAddress unlocks a jade logged out on the device and retries once`() = test { - val sut = connectedReadyRepo(listOf(knownUsb)) - var calls = 0 - whenever { jadeService.verifyAddress(any(), any(), any(), any()) }.doSuspendableAnswer { - if (calls++ == 0) throw AppError(JadeException.DeviceLocked()) - } - - val result = sut.verifyAddress(HwFundingAddressType.NATIVE_SEGWIT, "m/84'/1'/0'/0/0", "bcrt1q") - - assertTrue(result.isSuccess) - assertEquals(2, calls) - verify(jadeService).unlock(JadeNetwork.REGTEST) - assertEquals(WALLET_ID, sut.state.value.connectedWalletId()) - } - - @Test - fun `signPsbt refuses a jade logged out on the device that unlocks into another wallet`() = test { - val sut = connectedReadyRepo(listOf(knownUsb, passphraseUsb)) - whenever { jadeService.signPsbt(any(), any()) } + fun `a jade logged out on the device marks the session locked so ensureConnected unlocks it`() = test { + val sut = connectedReadyRepo() + whenever(jadeService.verifyAddress(any(), any(), any(), any())) .doSuspendableAnswer { throw AppError(JadeException.DeviceLocked()) } - whenever { jadeService.getAccountExport(any(), any(), any()) }.thenReturn(accountExport(xpub = "zpubPass")) - val result = sut.signPsbt("psbt") + val verified = sut.verifyAddress(HwFundingAddressType.NATIVE_SEGWIT, "m/84'/1'/0'/0/0", "bcrt1q") - assertIs(result.exceptionOrNull()) + assertTrue(verified.isFailure) + assertTrue(sut.state.value.connected?.isLocked == true) + val unlocked = sut.ensureConnected(knownUsb.id, WALLET_ID).getOrThrow() + assertFalse(unlocked.isLocked) + assertEquals(WALLET_ID, unlocked.walletId) verify(jadeService).unlock(JadeNetwork.REGTEST) - verify(jadeService, times(1)).signPsbt(any(), any()) } - /** A paired Jade connected and unlocked into [WALLET_ID]. */ - private suspend fun connectedReadyRepo(known: List): JadeRepo { - whenever { hwWalletStore.loadKnownDevices(HwWalletVendor.BLOCKSTREAM) }.thenReturn(known) + private suspend fun connectedReadyRepo(): JadeRepo { + whenever { hwWalletStore.loadKnownDevices(HwWalletVendor.BLOCKSTREAM) }.thenReturn(listOf(knownUsb)) whenever { jadeService.scan(any(), any()) }.thenReturn(listOf(usbDevice)) whenever { jadeService.connect(any(), any(), any()) }.thenReturn(versionInfo(JadeState.READY)) val sut = createRepo() diff --git a/app/src/test/java/to/bitkit/ui/screens/wallets/send/HwSendViewModelTest.kt b/app/src/test/java/to/bitkit/ui/screens/wallets/send/HwSendViewModelTest.kt index 5483a9942e..4a3a19c0fa 100644 --- a/app/src/test/java/to/bitkit/ui/screens/wallets/send/HwSendViewModelTest.kt +++ b/app/src/test/java/to/bitkit/ui/screens/wallets/send/HwSendViewModelTest.kt @@ -3,6 +3,7 @@ package to.bitkit.ui.screens.wallets.send import android.content.Context import androidx.lifecycle.viewModelScope import com.synonym.bitkitcore.BroadcastException +import com.synonym.bitkitcore.JadeException import com.synonym.bitkitcore.TrezorException import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.CompletableDeferred @@ -907,6 +908,24 @@ class HwSendViewModelTest : BaseUnitTest() { return PaymentFixture(funding, signedTx, broadcast) } + @Test + fun `a jade logged out on the device unlocks in the connect step before composing and signing again`() = test { + val fixture = stubSuccessfulPayment() + val locked = AppError(JadeException.DeviceLocked()) + whenever(hwWalletRepo.composeFundingTransaction(WALLET_ID, ADDRESS, AMOUNT_SATS, SATS_PER_VBYTE)) + .thenReturn(Result.failure(locked), Result.success(fixture.funding)) + whenever(hwWalletRepo.signFunding(WALLET_ID, fixture.funding)) + .thenReturn(Result.failure(locked), Result.success(fixture.signedTx)) + + sut.signAndBroadcast(request()) + advanceUntilIdle() + + verify(hwWalletRepo, times(3)).ensureConnected(WALLET_ID) + verify(hwWalletRepo, times(2)).composeFundingTransaction(WALLET_ID, ADDRESS, AMOUNT_SATS, SATS_PER_VBYTE) + verify(hwWalletRepo, times(2)).signFunding(WALLET_ID, fixture.funding) + verify(hwWalletRepo).broadcastFunding(fixture.signedTx) + } + @Test fun `retained hardware receipt blocks ordinary and foreign request signing after restart`() = test { stubSuccessfulPayment() From ba7ac0851e0c711eb390f498e01b8303f1efb379 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Thu, 26 Nov 2026 21:33:48 +0100 Subject: [PATCH 3/4] docs: cover sign with jade after a logout in the locked journey Verified: xmllint on the journey; its send steps ran on the Android emulator against the interactive Jade emulator on 3e148301c. --- journeys/hardware-wallet/README.md | 4 ++-- .../hardware-wallet/jade-device-locked.xml | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/journeys/hardware-wallet/README.md b/journeys/hardware-wallet/README.md index 3622627d2e..c6d2837fda 100644 --- a/journeys/hardware-wallet/README.md +++ b/journeys/hardware-wallet/README.md @@ -84,7 +84,7 @@ the other three rely on, and `passphrase-settings-remove.xml` removes it again. | `jade-uninitialized.xml` | Jade emulator with no wallet: Found shows the not-set-up message | | `jade-wrong-pin.xml` | Interactive Jade emulator: wrong PIN on the device → Found shows the wrong-PIN message, retry pairs | | `jade-network-mismatch.xml` | Jade emulator restricted to mainnet: Found shows the network message | -| `jade-device-locked.xml` | Interactive Jade logged out on the device after pairing: Verify on Device asks for the PIN on the device and retries | +| `jade-device-locked.xml` | Interactive Jade logged out on the device after pairing: Verify on Device and Sign With Jade ask for the PIN on the device and retry | | `jade-psbt-too-large.xml` | Jade with about 200 small inputs: sending all of it shows the too-large message | | `jade-sign-on-device.xml` | Interactive Jade: decline on the device keeps the payment unsent, approve sends it | | `jade-wallet-mismatch.xml` | Paired Jade reseeded: Verify on Device shows the different-wallet message | @@ -179,6 +179,6 @@ The error journeys start the emulator in another state first: `jade-uninitialize (`JADE_MNEMONIC=`), `jade-wrong-pin.xml` (`JADE_MODE=interactive`, where the device shows its own PIN pad and `./scripts/jade-emulator pin` types on it) and `jade-network-mismatch.xml` (`JADE_NETWORK=mainnet`), and `jade-device-locked.xml` logs the interactive device out after -pairing, so the next request asks for the PIN on the device again and retries; `jade-psbt-too-large.xml` needs the app on the bitkit-docker Electrum and about 200 small +pairing, so Verify on Device and then Sign With Jade ask for the PIN on the device again and retry (the send steps need funds on the Jade); `jade-psbt-too-large.xml` needs the app on the bitkit-docker Electrum and about 200 small inputs on the Jade. `jade-sign-on-device.xml` declines and then approves a payment on the interactive device's own screens. `jade-wallet-mismatch.xml` restarts the emulator with another seed after pairing. `jade-passphrase.xml` starts it with `JADE_PASSPHRASE=always` and pairs the wallet a passphrase typed on the device opens (`./scripts/jade-emulator passphrase`). The bitkit-docker `docs/jade-emulator.md` lists the modes and recipes. diff --git a/journeys/hardware-wallet/jade-device-locked.xml b/journeys/hardware-wallet/jade-device-locked.xml index 3a5c261c27..9ffa67d18f 100644 --- a/journeys/hardware-wallet/jade-device-locked.xml +++ b/journeys/hardware-wallet/jade-device-locked.xml @@ -2,9 +2,10 @@ Logs the paired Jade out on the device itself and checks the message the app shows when it next needs the Jade. Requires `JADE_MODE=interactive ./scripts/jade-emulator start` in - `bitkit-docker`, a regtest debug build with the Jade emulator enabled (see the README) and no - Jade paired. The device answers the next request with HW_LOCKED, and the app asks for the PIN on - the device again and retries. + `bitkit-docker`, a regtest debug build with the Jade emulator enabled (see the README), no + Jade paired and funds on the Jade's regtest addresses for the send steps. The device answers + the next request with HW_LOCKED, and the app asks for the PIN on the device again and retries, + on Verify on Device and on Sign With Jade. @@ -28,5 +29,17 @@ Run `./scripts/jade-emulator pin 012345`, then `./scripts/jade-emulator press right front` once the device shows Verify Address, and verify the button returns to "Verify on Device" with no error + + Close the receive sheet and run `./scripts/jade-emulator press front right front` to log out on the device again + + + Tap Send (testTag "Send"), enter a regtest address of the bitkit-docker node manually, select the Jade as the funding source on the amount screen (testTag "AssetButton-switch"), enter 50 000 sats, tap Continue (testTag "ContinueAmount"), swipe to confirm and tap "Sign With Jade" (testTag "HardwareSendOpenTrezorConnect") + + + Verify the Jade shows its PIN pad and the sheet's Back button is still shown, then run `./scripts/jade-emulator pin 012345` + + + Run `./scripts/jade-emulator press front` to pass the Output screen, then `./scripts/jade-emulator press right front` to sign on Send Transaction, and verify the success screen (testTag "SendSuccess") headed "Bitcoin Sent" appears within 30 seconds, with one payment sent + From 1a49aabe86e1a794175d26af499e7009e1ef4a62 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Thu, 26 Nov 2026 22:10:52 +0100 Subject: [PATCH 4/4] docs: add electrum and funding setup to the locked journey Verified: xmllint and git diff --check on the journey; bitkit-docker 48b6c9f exposes electrs on 60001 and ./bitcoin-cli. --- journeys/hardware-wallet/README.md | 2 +- journeys/hardware-wallet/jade-device-locked.xml | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/journeys/hardware-wallet/README.md b/journeys/hardware-wallet/README.md index c6d2837fda..85ecb35cf3 100644 --- a/journeys/hardware-wallet/README.md +++ b/journeys/hardware-wallet/README.md @@ -179,6 +179,6 @@ The error journeys start the emulator in another state first: `jade-uninitialize (`JADE_MNEMONIC=`), `jade-wrong-pin.xml` (`JADE_MODE=interactive`, where the device shows its own PIN pad and `./scripts/jade-emulator pin` types on it) and `jade-network-mismatch.xml` (`JADE_NETWORK=mainnet`), and `jade-device-locked.xml` logs the interactive device out after -pairing, so Verify on Device and then Sign With Jade ask for the PIN on the device again and retry (the send steps need funds on the Jade); `jade-psbt-too-large.xml` needs the app on the bitkit-docker Electrum and about 200 small +pairing, so Verify on Device and then Sign With Jade ask for the PIN on the device again and retry (the send steps need the app on the bitkit-docker Electrum and funds on the Jade); `jade-psbt-too-large.xml` needs the app on the bitkit-docker Electrum and about 200 small inputs on the Jade. `jade-sign-on-device.xml` declines and then approves a payment on the interactive device's own screens. `jade-wallet-mismatch.xml` restarts the emulator with another seed after pairing. `jade-passphrase.xml` starts it with `JADE_PASSPHRASE=always` and pairs the wallet a passphrase typed on the device opens (`./scripts/jade-emulator passphrase`). The bitkit-docker `docs/jade-emulator.md` lists the modes and recipes. diff --git a/journeys/hardware-wallet/jade-device-locked.xml b/journeys/hardware-wallet/jade-device-locked.xml index 9ffa67d18f..b870356a66 100644 --- a/journeys/hardware-wallet/jade-device-locked.xml +++ b/journeys/hardware-wallet/jade-device-locked.xml @@ -2,8 +2,11 @@ Logs the paired Jade out on the device itself and checks the message the app shows when it next needs the Jade. Requires `JADE_MODE=interactive ./scripts/jade-emulator start` in - `bitkit-docker`, a regtest debug build with the Jade emulator enabled (see the README), no - Jade paired and funds on the Jade's regtest addresses for the send steps. The device answers + `bitkit-docker`, a regtest debug build with the Jade emulator enabled (see the README) and no + Jade paired. For the send steps, Settings, Advanced, Electrum Server must point at the + `bitkit-docker` Electrum, and the Jade must hold funds there: after pairing, run + `./bitcoin-cli sendtoaddress JADE_ADDRESS 0.001; ./bitcoin-cli -generate 1` in + `bitkit-docker`, where `JADE_ADDRESS` is the address Receive shows on the Jade tab. The device answers the next request with HW_LOCKED, and the app asks for the PIN on the device again and retries, on Verify on Device and on Sign With Jade. @@ -36,7 +39,7 @@ Tap Send (testTag "Send"), enter a regtest address of the bitkit-docker node manually, select the Jade as the funding source on the amount screen (testTag "AssetButton-switch"), enter 50 000 sats, tap Continue (testTag "ContinueAmount"), swipe to confirm and tap "Sign With Jade" (testTag "HardwareSendOpenTrezorConnect") - Verify the Jade shows its PIN pad and the sheet's Back button is still shown, then run `./scripts/jade-emulator pin 012345` + Verify the Jade shows its PIN pad, then run `./scripts/jade-emulator pin 012345` Run `./scripts/jade-emulator press front` to pass the Output screen, then `./scripts/jade-emulator press right front` to sign on Send Transaction, and verify the success screen (testTag "SendSuccess") headed "Bitcoin Sent" appears within 30 seconds, with one payment sent