-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These commits: 1. encode fragment paramters as bech32 strings (with no checksum), with 2 character param names in the human readable part, and `+` as a delimiter - expiry time parameter encoded as a little endian u32, in line with bitcoin header timestamp and unix time nLocktime encoding. `EX` hrp - ohttp has `OH` hrp, same byte representation as previously encoded in base64 - receiver key has `RK` hrp, same byte representation as previously encoded in base64 2. use bech32 with no human readable part for the subdirectory IDs 3. uppercase the scheme and host of the URI 4. move the pj so it follows the pjos parameter Once the `#` %-escaping bug is fixed (see #373), and as long as no path elements between the host and the subdirectory ID, the entire `pj` parameter of the bip21 URI can be encoded in a QR using the alphanumeric mode. Closes #389. Manually verified, with manual % escaping of `#`, using the `qrencode` CLI encoder alphanumeric mode is indeed used for everything following `pj=`.
- Loading branch information
Showing
14 changed files
with
301 additions
and
163 deletions.
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.