-
Notifications
You must be signed in to change notification settings - Fork 1
fix: address validation #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jvsena42
wants to merge
15
commits into
master
Choose a base branch
from
fix/address-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+372
−15
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0f9a569
fix: add debounce validation
jvsena42 349e133
chore: create network validator
jvsena42 220c1a5
fix: implement network validation
jvsena42 69f6b40
fix: error message
jvsena42 2e52a24
fix: remove expired error on unified invoice
jvsena42 d5cf3d1
fix: network check on address pasting
jvsena42 53380b8
Merge branch 'master' into fix/address-validation
jvsena42 81967bf
chore: insufficient spending description
jvsena42 e64ab57
fix: display amount on errors
jvsena42 b890f55
Merge branch 'master' into fix/address-validation
jvsena42 925b52b
Merge remote-tracking branch 'origin/fix/address-validation' into fix…
jvsena42 e91a052
fix: check for on-chain sufficient amount
jvsena42 44618b1
fix: typo
jvsena42 eb6e25f
chore: case
jvsena42 84a1241
add toast ids
piotr-iohk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
app/src/main/java/to/bitkit/utils/NetworkValidationHelper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package to.bitkit.utils | ||
|
|
||
| import org.lightningdevkit.ldknode.Network | ||
|
|
||
| /** | ||
| * Helper for validating Bitcoin network compatibility of addresses and invoices | ||
| */ | ||
| object NetworkValidationHelper { | ||
|
|
||
| /** | ||
| * Infer the Bitcoin network from an on-chain address prefix | ||
| * @param address The Bitcoin address to check | ||
| * @return The detected network, or null if the address format is unrecognized | ||
| */ | ||
| fun getAddressNetwork(address: String): Network? { | ||
| val lowercased = address.lowercase() | ||
|
|
||
| // Bech32/Bech32m addresses (order matters: check bcrt1 before bc1) | ||
| return when { | ||
| lowercased.startsWith("bcrt1") -> Network.REGTEST | ||
| lowercased.startsWith("bc1") -> Network.BITCOIN | ||
| lowercased.startsWith("tb1") -> Network.TESTNET | ||
| else -> { | ||
| // Legacy addresses - check first character | ||
| when (address.firstOrNull()) { | ||
| '1', '3' -> Network.BITCOIN | ||
| 'm', 'n', '2' -> Network.TESTNET // testnet and regtest share these | ||
| else -> null | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.