Skip to content
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

Add support for uppercase bech32 #444

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cosmrs/src/base/account_id.rs
Original file line number Diff line number Diff line change
@@ -79,7 +79,11 @@ impl FromStr for AccountId {
type Err = ErrorReport;

fn from_str(s: &str) -> Result<Self> {
let (hrp, bytes) = bech32::decode(s).wrap_err(format!("invalid bech32: '{}'", s))?;
let (hrp, bytes) = if s.starts_with(|c: char| c.is_uppercase()) {
bech32::decode_upper(s)
} else {
bech32::decode(s)
}.wrap_err(format!("invalid uppercase bech32: '{}'", s))?;
tony-iqlusion marked this conversation as resolved.
Show resolved Hide resolved
penso marked this conversation as resolved.
Show resolved Hide resolved
Self::new(&hrp, &bytes)
}
}
@@ -148,6 +152,14 @@ mod tests {
.unwrap();
}

/// See https://en.bitcoin.it/wiki/BIP_0173 -- UPPERCASE is a valid bech32
#[test]
fn with_uppercase() {
"STARS1JUME25TTJLCAQQJZJJQX9HUMVZE3VCC8QF2KWL"
.parse::<AccountId>()
.unwrap();
}

#[test]
fn to_string() {
let account_id = "juno10j9gpw9t4jsz47qgnkvl5n3zlm2fz72k67rxsg"