Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions app/src/main/java/to/bitkit/models/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ fun Network.toCoreNetworkType(): NetworkType = when (this) {
Network.SIGNET -> NetworkType.SIGNET
Network.REGTEST -> NetworkType.REGTEST
}

fun NetworkType.toLdkNetwork(): Network = when (this) {
NetworkType.BITCOIN -> Network.BITCOIN
NetworkType.TESTNET -> Network.TESTNET
NetworkType.SIGNET -> Network.SIGNET
NetworkType.REGTEST -> Network.REGTEST
}
16 changes: 16 additions & 0 deletions app/src/main/java/to/bitkit/utils/Bip21Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import to.bitkit.models.SATS_IN_BTC

object Bip21Utils {

private const val BIP21_PREFIX = "bitcoin:"

/**
* Checks if a BIP21 URI is duplicated (contains multiple bitcoin: prefixes).
* Workaround for https://github.com/synonymdev/bitkit-core/issues/63
* @return true if the input contains duplicated BIP21 URIs, false otherwise
*/
fun isDuplicatedBip21(input: String): Boolean {
val lowercased = input.lowercase()
val firstIndex = lowercased.indexOf(BIP21_PREFIX)
if (firstIndex == -1) return false

val secondIndex = lowercased.indexOf(BIP21_PREFIX, firstIndex + BIP21_PREFIX.length)
return secondIndex != -1
}

fun buildBip21Url(
bitcoinAddress: String,
amountSats: ULong? = null,
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/to/bitkit/utils/NetworkValidationHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package to.bitkit.utils

import org.lightningdevkit.ldknode.Network

/**
* Helper for validating Bitcoin network compatibility of addresses and invoices
*/
object NetworkValidationHelper {
/**
* Check if an address/invoice network mismatches the current app network
* @param addressNetwork The network detected from the address/invoice
* @param currentNetwork The app's current network (typically Env.network)
* @return true if there's a mismatch (address won't work on current network)
*/
fun isNetworkMismatch(addressNetwork: Network?, currentNetwork: Network): Boolean {
if (addressNetwork == null) return false

// Special case: regtest uses testnet prefixes (m, n, 2, tb1)
if (currentNetwork == Network.REGTEST && addressNetwork == Network.TESTNET) {
return false
}

return addressNetwork != currentNetwork
}
}
Loading
Loading