Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e475d57
feat(payments): Internal transfers between own balances in Advanced m…
HashEngineering Nov 7, 2026
bc792e6
fix(payments): address pre-review round 1 on Internal transfers (MO-1…
HashEngineering Nov 7, 2026
30c360c
fix(payments): address pre-review round 2 on Internal transfers (MO-1…
HashEngineering Nov 7, 2026
fad8d31
feat(payments): enable Platform → Core internal transfers (MO-1125)
HashEngineering Nov 9, 2026
e0b969b
fix(payments): show the Internal transfer sheets above the bottom nav…
HashEngineering Nov 9, 2026
66c6ffc
fix(payments): keep the Internal tab clear of the bars (MO-1125)
HashEngineering Nov 10, 2026
a967e1c
feat(payments): hide the Internal tab on the basic Payments screen
HashEngineering Nov 10, 2026
ce65bf5
Merge branch 'feat/advanced-external-send' into feat/advanced-interna…
HashEngineering Nov 10, 2026
cac4f5c
Merge branch 'feat/advanced-external-send' into feat/advanced-interna…
HashEngineering Nov 10, 2026
b3ef474
Merge branch 'feat/advanced-external-send' into feat/advanced-interna…
HashEngineering Nov 10, 2026
925bd88
fix(payments): return Home after a finished Internal transfer
HashEngineering Nov 10, 2026
25f1049
fix(payments): close Internal transfer overlays when the lock screen …
HashEngineering Nov 10, 2026
83d4730
fix(payments): bottom navigation on Receive only; Internal sheets in …
HashEngineering Nov 10, 2026
6de0b19
Merge branch 'simplify/pr1680' into simplify/pr1683
HashEngineering Nov 10, 2026
ec2ce3d
Merge commit '83d47304e' into simplify/pr1683
HashEngineering Nov 10, 2026
0d6601e
Merge branch 'simplify/pr1680' into simplify/pr1683
HashEngineering Nov 10, 2026
23efb2d
Merge branch 'claude/advanced-external-send-fa5ded' into feat/advance…
HashEngineering Nov 11, 2026
78959ad
Merge remote-tracking branch 'origin/feat/advanced-external-send' int…
HashEngineering Nov 12, 2026
75ad19e
fix(payments): forget Internal Transfer state on Reset Wallet
HashEngineering Nov 12, 2026
484273a
fix(ui): keep screen Back handlers above the activity after a restart
HashEngineering Nov 12, 2026
6f7c735
feat(payments): allow Core -> Platform as an Internal Transfer
HashEngineering Nov 12, 2026
b0fb1af
feat(payments): allow Identity -> Shielded as an Internal Transfer
HashEngineering Nov 12, 2026
3070815
fix(payments): Internal Identity -> Shielded uses the identity self-s…
HashEngineering Nov 13, 2026
89e632b
Merge remote-tracking branch 'origin/feat/advanced-external-send' int…
HashEngineering Nov 13, 2026
3e1f3df
fix(payments): keep SDK messages out of Internal Transfer logs
HashEngineering Nov 13, 2026
8e178c4
Merge remote-tracking branch 'origin/feat/advanced-external-send' int…
HashEngineering Nov 14, 2026
64e6c6e
fix(payments): show the Internal Shielded -> Core Max as received
HashEngineering Nov 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions wallet/res/drawable/ic_swap_up_down.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
~ Copyright 2026 Dash Core Group.
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<!-- Up + down stroked arrows (1.5px) for the internal transfer's swap button (Figma btn-s 3325:4692). -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M5,13.5V2.5M2,5.5L5,2.5L8,5.5"
android:strokeColor="#008DE4"
android:strokeWidth="1.5"
android:strokeLineCap="round"
android:strokeLineJoin="round"/>
<path
android:pathData="M11,2.5V13.5M8,10.5L11,13.5L14,10.5"
android:strokeColor="#008DE4"
android:strokeWidth="1.5"
android:strokeLineCap="round"
android:strokeLineJoin="round"/>
</vector>
12 changes: 12 additions & 0 deletions wallet/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,18 @@
<string name="external_send_ambiguous_message">Your payment may have gone through. Do not send it again; your balances will update after the next sync.</string>
<string name="external_send_interrupted_title">Payment not completed</string>
<string name="external_send_interrupted_message">The payment could not be completed. The funds will arrive in your Shielded balance instead; the recipient was not paid.</string>
<!-- Advanced mode: Internal Transfers between own balances (MO-1125) -->
<string name="internal_transfer_transfer_from">Transfer from</string>
<string name="internal_transfer_transfer_to">Transfer to</string>
<string name="internal_transfer_change_from">Change the balance to transfer from</string>
<string name="internal_transfer_change_to">Change the balance to transfer to</string>
<string name="internal_transfer_swap">Swap the From and To balances</string>
<string name="internal_transfer_unavailable">Not available yet</string>
<string name="internal_transfer_insufficient_balance">Insufficient balance</string>
<string name="internal_transfer_confirm_refused">Your balance changed and no longer covers this transfer. Nothing was sent. Check the amount and try again.</string>
<string name="internal_transfer_withdrawal_not_instant">Withdrawals from your Identity balance to Core are not instant and take some time</string>
<string name="internal_transfer_completes_automatically_title">Transfer in progress</string>
<string name="internal_transfer_completes_automatically_message">Your funds left your Core balance and will arrive in your Shielded balance automatically. Do not transfer them again.</string>
<string name="receive_address_unavailable">This address is not available right now</string>
<string name="dash_connect_revoke_access">Revoke access</string>
</resources>
7 changes: 7 additions & 0 deletions wallet/src/de/schildbach/wallet/di/PlatformSdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import de.schildbach.wallet.service.platform.sdk.DashSdkService
import de.schildbach.wallet.service.platform.sdk.DashSdkServiceImpl
import de.schildbach.wallet.service.platform.sdk.ExternalSendService
import de.schildbach.wallet.service.platform.sdk.ExternalSendServiceImpl
import de.schildbach.wallet.service.platform.sdk.InternalTransferService
import de.schildbach.wallet.service.platform.sdk.InternalTransferServiceImpl
import de.schildbach.wallet.service.platform.sdk.PlatformMnemonicProvider
import de.schildbach.wallet.service.platform.sdk.SdkMessageSigner
import de.schildbach.wallet.service.platform.sdk.SecurityGuardMnemonicProvider
Expand Down Expand Up @@ -83,6 +85,11 @@ abstract class PlatformSdkModule {
@Binds
abstract fun bindExternalSendService(service: ExternalSendServiceImpl): ExternalSendService

/** Advanced-mode Internal Transfers (MO-1125): own-balance moves over the External Send routes. */
@Singleton
@Binds
abstract fun bindInternalTransferService(service: InternalTransferServiceImpl): InternalTransferService

/**
* The SDK message-signing seam behind
* [de.schildbach.wallet.security.SecurityFunctions.signMessage] (the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ fun balanceKindOf(destination: SendDestination): SendBalance = when (destination
is SendDestination.Identity -> SendBalance.IDENTITY
}

/**
* The balances a source / From / To picker lists, in order: Identity only for a user known to
* have an identity ([hasIdentity] true; unknown hides it). Shielded is always listed (it shows
* disabled when the feature is off). Shared by the External Send and the internal transfer.
*/
fun pickerBalances(hasIdentity: Boolean?): List<SendBalance> =
SendBalance.entries.filter { it != SendBalance.IDENTITY || hasIdentity == true }

/** Whether a send from [source] into a [destinationKind] balance involves a ~30 s shielded proof. */
fun hasShieldedLeg(source: SendBalance, destinationKind: SendBalance): Boolean =
source == SendBalance.SHIELDED || destinationKind == SendBalance.SHIELDED

/** The result of [detectSendDestination]. */
sealed class DestinationParse {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ sealed class ExternalSendResult {
* user's OWN shielded balance instead; the recipient is not paid. Terminal; no retry.
*/
object InterruptedFundsReturnToShielded : ExternalSendResult()

/**
* Internal transfer Core → own Shielded only ([InternalTransferService]): the L1 asset lock
* went out and the wallet's pending-shield sweep finishes the shield to the user's own
* shielded balance ([ShieldFromWalletOutcome.SHIELD_PENDING_RETRY]). Funds are not lost
* and nothing must be sent again. Terminal; no retry.
*/
object CompletesAutomatically : ExternalSendResult()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,38 @@ internal fun logReadRetry(
retryLog.warn("external send: {} unreadable; unknown, retrying in {} ms ({})", what, retryDelayMs(attempt), safeErrorSummary(cause))
}

/**
* The user's registered identity id from the identity record ([id] and its creation [state]),
* null when there is none yet; an unknown creation state throws (unknown, not "none").
*/
internal fun ownRegisteredIdentity(id: String?, state: String?): String? {
val creation = IdentityCreationState.valueOf(state ?: IdentityCreationState.NONE.name)
return id?.takeIf { it.isNotBlank() && creation >= IdentityCreationState.IDENTITY_REGISTERED }
}

/**
* [ownRegisteredIdentity] of the stored identity record, error-preserving: throws when it is
* unreadable. Shared by the External Send and the internal transfer sources.
*/
internal suspend fun BlockchainIdentityConfig.ownIdentityIdOrThrow(): String? = ownRegisteredIdentity(
getPreservingErrors(BlockchainIdentityConfig.IDENTITY_ID),
getPreservingErrors(BlockchainIdentityConfig.CREATION_STATE)
)

/** `USE_KOTLIN_SDK_SHIELDED`, error-preserving (absent = off): throws when unreadable. */
internal suspend fun DashPayConfig.shieldedEnabledOrThrow(): Boolean =
getPreservingErrors(DashPayConfig.USE_KOTLIN_SDK_SHIELDED) == true

/** The started SDK's wallet manager (starts the SDK first); throws when it is missing. */
internal suspend fun DashSdkService.startedWalletManager(): org.dashfoundation.dashsdk.wallet.PlatformWalletManager {
ensureStarted()
return checkNotNull(walletManagerOrNull()) { "SDK wallet manager missing after ensureStarted()" }
}

/** The SDK wallet bound now: the single loaded one, null when none (or not exactly one) is. */
internal suspend fun DashSdkService.boundWalletIdOrNull(): String? =
startedWalletManager().wallets.value.keys.singleOrNull()

private val retryLog = LoggerFactory.getLogger("de.schildbach.wallet.service.platform.sdk.ExternalSendRetry")

/**
Expand Down Expand Up @@ -618,47 +650,35 @@ internal class DashSdkExternalSendSource(
private val fundingGate: PendingPaymentFundingGate
) : ExternalSendSource {

private suspend fun manager(): org.dashfoundation.dashsdk.wallet.PlatformWalletManager {
sdkService.ensureStarted()
return checkNotNull(sdkService.walletManagerOrNull()) { "SDK wallet manager missing after ensureStarted()" }
}
private suspend fun manager(): org.dashfoundation.dashsdk.wallet.PlatformWalletManager =
sdkService.startedWalletManager()

/** The PINNED wallet — never "whichever is current". */
private suspend fun wallet(walletIdHex: String): org.dashfoundation.dashsdk.wallet.ManagedPlatformWallet =
checkNotNull(manager().wallets.value[walletIdHex]) { "SDK wallet not loaded" }

override fun currentCoreSession(): WalletSession? = sendPaymentService.currentWalletSession()

override suspend fun boundWalletIdOrNull(): String? = manager().wallets.value.keys.singleOrNull()
override suspend fun boundWalletIdOrNull(): String? = sdkService.boundWalletIdOrNull()

override fun currentBoundWalletIdOrNull(): String? = sdkService.loadedWalletIds().singleOrNull()

override suspend fun cutoverCommittedOrThrow(): Boolean = sdkL1SendService.cutoverCommittedOrThrow()

override suspend fun shieldedEnabledOrThrow(): Boolean =
dashPayConfig.getPreservingErrors(DashPayConfig.USE_KOTLIN_SDK_SHIELDED) == true
override suspend fun shieldedEnabledOrThrow(): Boolean = dashPayConfig.shieldedEnabledOrThrow()

override suspend fun ownIdentityIdOrThrow(): String? = ownIdentity(
identityConfig.getPreservingErrors(BlockchainIdentityConfig.IDENTITY_ID),
identityConfig.getPreservingErrors(BlockchainIdentityConfig.CREATION_STATE)
)
override suspend fun ownIdentityIdOrThrow(): String? = identityConfig.ownIdentityIdOrThrow()

override fun observeOwnIdentityId(): Flow<Result<String?>> =
combine(
identityConfig.observePreservingErrors(BlockchainIdentityConfig.IDENTITY_ID),
identityConfig.observePreservingErrors(BlockchainIdentityConfig.CREATION_STATE)
) { id, state -> Result.success(ownIdentity(id, state)) }
) { id, state -> Result.success(ownRegisteredIdentity(id, state)) }
.retryReadErrors(
Result.failure(IllegalStateException("identity record unreadable")),
onError = logReadRetry("identity record")
)

/** A registered identity; an unknown creation state throws (unknown, not "none"). */
private fun ownIdentity(id: String?, state: String?): String? {
val creation = IdentityCreationState.valueOf(state ?: IdentityCreationState.NONE.name)
return id?.takeIf { it.isNotBlank() && creation >= IdentityCreationState.IDENTITY_REGISTERED }
}

override suspend fun managedIdentityIds(walletIdHex: String): List<ByteArray> =
wallet(walletIdHex).inMemoryIdentityStates().filter { !it.watched }.map { it.identityId }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2026 Dash Core Group.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.schildbach.wallet.service.platform.sdk

// Pure, host-testable model of the Advanced-mode "Internal Transfers" (MO-1125): moving
// funds between the user's OWN balances. No native, no Android, no I/O.

/** Whether a From → To pair of own balances can be transferred, and if not, why. */
enum class InternalTransferSupport {
SUPPORTED,

/** From and To are the same balance: never allowed. */
SAME_BALANCE,

/** One side is the Shielded balance and the shielded feature is off (or unreadable). */
SHIELDED_OFF,

/** One side is the Identity balance and the user has no identity (or it is unknown). */
NO_IDENTITY
}

/**
* The one pair matrix of the internal transfer, enforced by the UI AND by
* [InternalTransferService.transfer]: every pair of two different own balances is supported,
* gated only by the shielded feature and the user's identity.
*
* | From \ To | Core | Shielded | Platform | Identity |
* |---|---|---|---|---|
* | Core | — | yes | yes (1) | yes |
* | Shielded | yes | — | yes | yes |
* | Platform | yes (2) | yes | — | yes |
* | Identity | yes | yes (3) | yes | — |
*
* 1. The External Send's Core → Platform (`fundFromAssetLockExternal`) to the wallet's own
* Platform address: the fee (L1 lock reserve plus the Platform-fee margin, whose unused
* part lands on another own Platform address) is paid on top; an interrupted lock is
* resumed by the External Send's pending-funding sweep.
* 2. The External Send's partial Platform → Core withdrawal (`withdrawCredits` with the
* inputs the wallet selects) to the wallet's own unadvertised Core address.
* 3. The Type 21 self-shield (`shieldedShieldFromIdentity`, no recipient: Rust targets the
* wallet's own default shielded address) from the user's own identity, not the External
* Send's to-recipient Type 21, which refuses an own address; the fee is metered by Rust at
* execution.
*
* [shieldedEnabled] and [hasIdentity] are the error-preserving reads: unknown is false.
*/
fun internalTransferSupport(
from: SendBalance,
to: SendBalance,
shieldedEnabled: Boolean,
hasIdentity: Boolean
): InternalTransferSupport {
if (from == to) return InternalTransferSupport.SAME_BALANCE
if ((from == SendBalance.SHIELDED || to == SendBalance.SHIELDED) && !shieldedEnabled) {
return InternalTransferSupport.SHIELDED_OFF
}
if ((from == SendBalance.IDENTITY || to == SendBalance.IDENTITY) && !hasIdentity) {
return InternalTransferSupport.NO_IDENTITY
}
return InternalTransferSupport.SUPPORTED
}

/** An ordered pair of own balances; [from] != [to] always. [toString] carries no amounts or ids. */
data class InternalTransferPair(val from: SendBalance, val to: SendBalance) {
init {
require(from != to) { "an internal transfer needs two different balances" }
}

/** The swap button (AC3): From and To exchange. */
fun swapped(): InternalTransferPair = InternalTransferPair(to, from)

/** Pick [balance] as From; picking the current To swaps the two (AC4). */
fun withFrom(balance: SendBalance): InternalTransferPair = when (balance) {
from -> this
to -> swapped()
else -> copy(from = balance)
}

/** Pick [balance] as To; picking the current From swaps the two (AC4). */
fun withTo(balance: SendBalance): InternalTransferPair = when (balance) {
to -> this
from -> swapped()
else -> copy(to = balance)
}
}

/**
* The pair the Internal tab opens with: From Core; To Shielded when the shielded feature is
* on, otherwise Identity when the user has one, otherwise Platform.
*/
fun defaultInternalTransferPair(shieldedEnabled: Boolean, hasIdentity: Boolean): InternalTransferPair =
InternalTransferPair(
SendBalance.CORE,
when {
shieldedEnabled -> SendBalance.SHIELDED
hasIdentity -> SendBalance.IDENTITY
else -> SendBalance.PLATFORM
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2026 Dash Core Group.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.schildbach.wallet.service.platform.sdk

import kotlinx.coroutines.flow.Flow
import org.dash.wallet.common.money.Dash

/**
* Advanced-mode "Internal Transfers" (MO-1125): move funds between the user's OWN balances
* ([SendBalance]) under the pair matrix [internalTransferSupport]. There is no address entry:
* the destination is always the wallet's own address for the To balance, resolved by this
* service at send time and failing closed. Basic mode does not use this.
*
* Results reuse [ExternalSendResult] / [NotSentReason]. Nothing amount-, address- or
* identity-derived is logged.
*/
interface InternalTransferService {
/** [ExternalSendService.observeBalance]: live spendable balance of [balance]; null = unknown. */
fun observeBalance(balance: SendBalance): Flow<Dash?>

/** [ExternalSendService.observeHasIdentity]; null = could not tell (the UI hides Identity). */
fun observeHasIdentity(): Flow<Boolean?>

/**
* `USE_KOTLIN_SDK_SHIELDED`, error-preserving: true/false when read (absent = false), null
* when unreadable (unknown: treated as off for gating, never as a confirmed "off"); keeps
* observing and never completes on a transient error.
*/
fun observeShieldedEnabled(): Flow<Boolean?>

/** [ExternalSendService.currentWalletIdOrNull]: captured, without suspending, at confirmation. */
fun currentWalletIdOrNull(): String?

/** The fee of a [from] → [to] transfer, null when it cannot be known before the send (never fabricated). */
suspend fun estimateFee(from: SendBalance, to: SendBalance): FeeEstimate?

/** The Max of a [from] → [to] transfer (the balance minus the fee paid on top), null when unknown. */
suspend fun maxSendable(from: SendBalance, to: SendBalance): Dash?

/**
* Move [amount] from [from] to the wallet's own [to] balance. The caller has ALREADY
* authenticated and passes exactly what the user confirmed, including
* [expectedWalletIdHex] ([currentWalletIdOrNull] at confirmation). The implementation
* enforces [internalTransferSupport] itself, refuses unless that wallet is the bound one
* (re-checked right before the write), and resolves the own destination after that check;
* an unavailable destination is [NotSentReason.GENERIC] with nothing submitted. A Core
* destination is NEVER the advertised receive address.
*
* Shielded legs block for a ~30s proof: run this on an application-scoped owner.
*/
suspend fun transfer(
from: SendBalance,
to: SendBalance,
amount: Dash,
isMax: Boolean,
expectedWalletIdHex: String?
): ExternalSendResult
}
Loading
Loading