-
Notifications
You must be signed in to change notification settings - Fork 15
feat: minimal sweep WIF QR implementation #355
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
otaliptus
wants to merge
9
commits into
bitcoindevkit:main
Choose a base branch
from
otaliptus:feat/wif-sweep-qr-minimal
base: main
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7bec09
feat(sweep): add minimal WIF QR sweep flow (esplora-only)
otaliptus 1e7aa44
fix(onboarding): surface errors and block WIF in wallet-creation flow
otaliptus b6bd50a
refactor(send): keep scanner alert title behavior unchanged
otaliptus fe573f4
fix(onboarding): restore alert state flag and keep error modal wiring
otaliptus 056ee4a
test(wif): add minimal coverage
otaliptus a372fc7
fix: formatting
otaliptus 2a83be1
fix: dialog title
otaliptus ce9a36b
fix(review): error blocking
otaliptus 0e75258
fix(review): shared wif parser
otaliptus 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // | ||
| // WifParser.swift | ||
| // BDKSwiftExampleWallet | ||
| // | ||
| // Created by otaliptus on 3/3/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| // Note: this parser is just a pretty simple heuristic for the simple wallet | ||
| enum WifParser { | ||
| static func extract(from value: String) -> String? { | ||
| var candidates = [value] | ||
|
|
||
| if let components = URLComponents(string: value), | ||
| let queryItems = components.queryItems | ||
| { | ||
| for item in queryItems { | ||
| let key = item.name.lowercased() | ||
| if key == "wif" || key == "privkey" || key == "private_key" || key == "privatekey", | ||
| let itemValue = item.value | ||
| { | ||
| candidates.append(itemValue) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for candidate in candidates { | ||
| var token = candidate.trimmingCharacters(in: .whitespacesAndNewlines) | ||
|
|
||
| if token.lowercased().hasPrefix("wif:") { | ||
| token = String(token.dropFirst(4)) | ||
| } | ||
|
|
||
| if isLikelyWif(token) { | ||
| return token | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| static func isLikelyWif(_ value: String) -> Bool { | ||
| guard value.count == 51 || value.count == 52 else { | ||
| return false | ||
| } | ||
|
|
||
| guard let first = value.first, "5KL9c".contains(first) else { | ||
| return false | ||
| } | ||
|
|
||
| let base58Charset = CharacterSet( | ||
| charactersIn: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | ||
| ) | ||
| return value.unicodeScalars.allSatisfy { base58Charset.contains($0) } | ||
| } | ||
| } |
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.
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.
non-blocking: is it intentional to call getAddress() before confirming any candidate WIF wallet has funds?
my thought was getAddress() reveals/persists the next external address, so failed/empty sweeps can still advance the receive index.
Should we defer destination address creation until after the first candidate with non-zero balance is found? Just wondering/thoughts, haven't fully fleshed it out in my head.
also this is non-blocking for merge because it seemed more like a correctness/UX polish issue where no funds are lost and wallet still works the only downside was just consuming a receive address index earlier than necessary on failed sweeps
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.
Nope, it wasn't intentional. I get what you mean I think.
I guess something lazy like this would fix?