-
Notifications
You must be signed in to change notification settings - Fork 39
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
Qr optimizations #417
Merged
+301
−163
Merged
Qr optimizations #417
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c4e40b
bump rust-bitcoin to 0.32.5 for bech32 re-export
nothingmuch fa8475f
add NoChecksum bech32 helpers in their own mod
nothingmuch 7604a94
Encode subdirectory ID as bech32
nothingmuch 9da88a7
Encode fragment parameters as bech32
nothingmuch b26ae16
Uppercase scheme and host in pj uri
nothingmuch 32004db
Remove Option wrapper from fragment param setters
nothingmuch 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 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 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 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 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 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 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,49 @@ | ||
use std::fmt; | ||
|
||
use bitcoin::bech32::primitives::decode::{CheckedHrpstring, CheckedHrpstringError}; | ||
use bitcoin::bech32::{self, EncodeError, Hrp, NoChecksum}; | ||
|
||
pub mod nochecksum { | ||
use super::*; | ||
|
||
pub fn decode(encoded: &str) -> Result<(Hrp, Vec<u8>), CheckedHrpstringError> { | ||
let hrp_string = CheckedHrpstring::new::<NoChecksum>(encoded)?; | ||
Ok((hrp_string.hrp(), hrp_string.byte_iter().collect::<Vec<u8>>())) | ||
} | ||
|
||
pub fn encode(hrp: Hrp, data: &[u8]) -> Result<String, EncodeError> { | ||
bech32::encode_upper::<NoChecksum>(hrp, data) | ||
} | ||
|
||
pub fn encode_to_fmt(f: &mut fmt::Formatter, hrp: Hrp, data: &[u8]) -> Result<(), EncodeError> { | ||
bech32::encode_upper_to_fmt::<NoChecksum, fmt::Formatter>(f, hrp, data) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn bech32_for_qr() { | ||
let bytes = vec![0u8, 1, 2, 3, 31, 32, 33, 95, 0, 96, 127, 128, 129, 254, 255, 0]; | ||
let hrp = Hrp::parse("STUFF").unwrap(); | ||
let encoded = nochecksum::encode(hrp, &bytes).unwrap(); | ||
let decoded = nochecksum::decode(&encoded).unwrap(); | ||
assert_eq!(decoded, (hrp, bytes.to_vec())); | ||
|
||
// no checksum | ||
assert_eq!( | ||
encoded.len() as f32, | ||
(hrp.as_str().len() + 1) as f32 + (bytes.len() as f32 * 8.0 / 5.0).ceil() | ||
); | ||
|
||
// TODO assert uppercase | ||
|
||
// should not error | ||
let corrupted = encoded + "QQPP"; | ||
let decoded = nochecksum::decode(&corrupted).unwrap(); | ||
assert_eq!(decoded.0, hrp); | ||
assert_ne!(decoded, (hrp, bytes.to_vec())); | ||
} | ||
} |
This file contains 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.
This update is missing from payjoin-directory, but I don't think it matters since the specified [^]0.32.4 allows for 0.32.5
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.
oops, i missed that. i think this should be addressed in #418
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.
in fact, cargo udeps points out payjoin-directory doesn't even use its bitcoin dep