-
Notifications
You must be signed in to change notification settings - Fork 1
feat: support all address types #431
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
ben-kaufman
wants to merge
34
commits into
master
Choose a base branch
from
feat/multiple-addresses-types
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.
+1,948
−1,343
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
75dc541
feat: support all address types
ben-kaufman 36c600e
Fix legacy type issues
ben-kaufman 32a3ba6
Update ldk-node
ben-kaufman 4cab166
fix balance check on disable
ben-kaufman 82cf9ad
fix timeout issue
ben-kaufman 13b8ab4
fix
ben-kaufman 9ac4142
fix multiple address support for backup and migration
ben-kaufman bff806b
remove funds sweep for different address types
ben-kaufman 8ca8c88
fixes
ben-kaufman b85158f
update ldk-node
ben-kaufman 4181b50
update ldk-node
ben-kaufman 6502cb3
update ldk node
ben-kaufman cd23f7d
fix wipe and update comments
ben-kaufman 184d32d
fixes
ben-kaufman 6f448f0
extract texts
ben-kaufman dcb9dc6
remove empty wallets from monitor list after restore
ben-kaufman b0e40c3
add tests
ben-kaufman 125600e
Merge branch 'master' into feat/multiple-addresses-types
ben-kaufman 39b5e5f
fix rebase string updates
ben-kaufman 7ced729
Update AddressViewer.swift
ben-kaufman 37dd99e
review fixes
ben-kaufman ae742df
Merge branch 'master' into feat/multiple-addresses-types
ben-kaufman dc1ab2a
fix AddressScriptType ref
ben-kaufman 07eb373
fix: change allAddressTypes from computed var to stored let
github-actions[bot] faf9eb7
fixes
ben-kaufman 8e59b05
Merge branch 'master' into feat/multiple-addresses-types
ben-kaufman 8956313
Add tests
ben-kaufman e541654
add retry logic to find payment
ben-kaufman f5b2c3d
Update unit-tests.yml
ben-kaufman 99dff14
Fix explore screen title
ben-kaufman 7c05c7d
Fix activity not created on send: create immediately from txid, incre…
ben-kaufman d1ac6b5
Replace node restart with dynamic address type APIs (#447)
ben-kaufman 3de48ec
Merge branch 'master' into feat/multiple-addresses-types
ben-kaufman 2f5ef26
toast test 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
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
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
3 changes: 1 addition & 2 deletions
3
Bitkit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import LDKNode | ||
|
|
||
| extension LDKNode.AddressType { | ||
| // MARK: - All cases (ordered) | ||
|
|
||
| static let allAddressTypes: [LDKNode.AddressType] = [.legacy, .nestedSegwit, .nativeSegwit, .taproot] | ||
|
|
||
| /// All address types with `selected` first, remaining in standard order. | ||
| static func prioritized(selected: LDKNode.AddressType) -> [LDKNode.AddressType] { | ||
| var types = [selected] | ||
| for type in allAddressTypes where type != selected { | ||
| types.append(type) | ||
| } | ||
| return types | ||
| } | ||
|
|
||
| // MARK: - Storage string (UserDefaults / BitkitCore APIs) | ||
|
|
||
| /// String value used in UserDefaults and BitkitCore APIs. | ||
| var stringValue: String { | ||
| switch self { | ||
| case .legacy: return "legacy" | ||
| case .nestedSegwit: return "nestedSegwit" | ||
| case .nativeSegwit: return "nativeSegwit" | ||
| case .taproot: return "taproot" | ||
| } | ||
| } | ||
|
|
||
| /// Parses storage string; returns nil for invalid or unknown values. | ||
| static func from(string: String) -> LDKNode.AddressType? { | ||
| switch string { | ||
| case "legacy": return .legacy | ||
| case "nestedSegwit": return .nestedSegwit | ||
| case "nativeSegwit": return .nativeSegwit | ||
| case "taproot": return .taproot | ||
| default: return nil | ||
| } | ||
| } | ||
|
|
||
| /// Parses storage string; returns `.nativeSegwit` for nil or invalid (backward compatibility). | ||
| static func fromStorage(_ string: String?) -> LDKNode.AddressType { | ||
| guard let s = string, let type = from(string: s) else { return .nativeSegwit } | ||
| return type | ||
| } | ||
|
|
||
| /// Parses a comma-separated string of address types; filters invalid values. | ||
| static func parseCommaSeparated(_ string: String) -> [LDKNode.AddressType] { | ||
| string.split(separator: ",") | ||
| .map { String($0).trimmingCharacters(in: .whitespaces) } | ||
| .compactMap { from(string: $0) } | ||
| } | ||
|
|
||
| // MARK: - Derivation path | ||
|
|
||
| /// BIP derivation path using current network (Env.network) for coin type. | ||
| var derivationPath: String { | ||
| let coinType = Env.network == .bitcoin ? "0" : "1" | ||
| return derivationPath(coinType: coinType) | ||
| } | ||
|
|
||
| /// BIP derivation path for the given coin type ("0" mainnet, "1" testnet). | ||
| func derivationPath(coinType: String) -> String { | ||
| switch self { | ||
| case .legacy: return "m/44'/\(coinType)'/0'/0" // BIP 44 | ||
| case .nestedSegwit: return "m/49'/\(coinType)'/0'/0" // BIP 49 | ||
| case .nativeSegwit: return "m/84'/\(coinType)'/0'/0" // BIP 84 | ||
| case .taproot: return "m/86'/\(coinType)'/0'/0" // BIP 86 | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Localized display | ||
|
|
||
| var localizedTitle: String { | ||
| switch self { | ||
| case .legacy: return "Legacy" | ||
| case .nestedSegwit: return "Nested Segwit" | ||
| case .nativeSegwit: return "Native Segwit" | ||
| case .taproot: return "Taproot" | ||
| } | ||
| } | ||
|
|
||
| /// Short label for compact UI (e.g. "Native"). | ||
| var shortLabel: String { | ||
| switch self { | ||
| case .legacy: return "Legacy" | ||
| case .nestedSegwit: return "Nested" | ||
| case .nativeSegwit: return "Native" | ||
| case .taproot: return "Taproot" | ||
| } | ||
| } | ||
|
|
||
| var localizedDescription: String { | ||
| switch self { | ||
| case .legacy: return "Pay-to-public-key-hash (1x...)" | ||
| case .nestedSegwit: return "Pay-to-Script-Hash (3x...)" | ||
| case .nativeSegwit: return "Pay-to-witness-public-key-hash (bc1x...)" | ||
| case .taproot: return "Pay-to-Taproot (bc1px...)" | ||
| } | ||
| } | ||
|
|
||
| var example: String { | ||
| switch self { | ||
| case .legacy: return "(1x...)" | ||
| case .nestedSegwit: return "(3x...)" | ||
| case .nativeSegwit: return "(bc1x...)" | ||
| case .taproot: return "(bc1px...)" | ||
| } | ||
| } | ||
|
|
||
| var shortExample: String { | ||
| switch self { | ||
| case .legacy: return "1x..." | ||
| case .nestedSegwit: return "3x..." | ||
| case .nativeSegwit: return "bc1q..." | ||
| case .taproot: return "bc1p..." | ||
| } | ||
| } | ||
|
|
||
| /// Accessibility / UI test identifier. | ||
| var testId: String { | ||
| switch self { | ||
| case .legacy: return "p2pkh" | ||
| case .nestedSegwit: return "p2sh-p2wpkh" | ||
| case .nativeSegwit: return "p2wpkh" | ||
| case .taproot: return "p2tr" | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Address format validation | ||
|
|
||
| /// Returns true if the address has the expected prefix for this address type on the given network. | ||
| /// Defensive check only; not a full script/checksum validation. | ||
| func matchesAddressFormat(_ address: String, network: LDKNode.Network) -> Bool { | ||
| let trimmed = address.trimmingCharacters(in: .whitespaces) | ||
| guard !trimmed.isEmpty else { return false } | ||
| let isMainnet = network == .bitcoin | ||
| switch self { | ||
| case .legacy: | ||
| return isMainnet ? trimmed.hasPrefix("1") : trimmed.hasPrefix("m") || trimmed.hasPrefix("n") | ||
| case .nestedSegwit: | ||
| return isMainnet ? trimmed.hasPrefix("3") : trimmed.hasPrefix("2") | ||
| case .nativeSegwit: | ||
| return isMainnet ? trimmed.hasPrefix("bc1q") : trimmed.hasPrefix("tb1q") || trimmed.hasPrefix("bcrt1q") | ||
| case .taproot: | ||
| return isMainnet ? trimmed.hasPrefix("bc1p") : trimmed.hasPrefix("tb1p") || trimmed.hasPrefix("bcrt1p") | ||
| } | ||
| } | ||
| } | ||
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to only use the full name for the different address types. Never heard them being abbreviated like this. Doesn't seem to break the UI in the address viewer as far as I can see.