Skip to content

Commit

Permalink
Bump bech32 to 0.11 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvolk131 committed May 12, 2024
1 parent e9863ff commit 5a3e5d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ path = "src/lib.rs"
anyhow = "1.0.70"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
bech32 = "0.9.1"
bech32 = "0.11"
bitcoin = { version = "0.30.2", default-features = false, features = ["serde", "rand"] }
ureq = { version = "2.5.0", features = ["json"], optional = true }
reqwest = { version = "0.12.3", optional = true, default-features = false, features = ["json"] }
Expand Down
8 changes: 3 additions & 5 deletions src/lnurl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::lightning_address::LightningAddress;
use crate::Error;
use bech32::{ToBase32, Variant};
use serde::{Deserialize, Deserializer, Serialize};
use std::fmt::{Display, Formatter};
use std::str::FromStr;
Expand All @@ -13,8 +12,8 @@ pub struct LnUrl {
impl LnUrl {
#[inline]
pub fn encode(&self) -> String {
let base32 = self.url.as_bytes().to_base32();
bech32::encode("lnurl", base32, Variant::Bech32).unwrap()
bech32::encode::<bech32::Bech32>(bech32::Hrp::parse("lnurl").unwrap(), self.url.as_bytes())
.unwrap()
}

pub fn is_lnurl_auth(&self) -> bool {
Expand Down Expand Up @@ -68,8 +67,7 @@ impl FromStr for LnUrl {

fn from_str(s: &str) -> Result<Self, Error> {
if s.to_lowercase().starts_with("lnurl") {
let (_, data, _) = bech32::decode(s).map_err(|_| Error::InvalidLnUrl)?;
let bytes = bech32::FromBase32::from_base32(&data).map_err(|_| Error::InvalidLnUrl)?;
let (_, bytes) = bech32::decode(s).map_err(|_| Error::InvalidLnUrl)?;
let url = String::from_utf8(bytes).map_err(|_| Error::InvalidLnUrl)?;
Ok(LnUrl { url })
} else {
Expand Down

0 comments on commit 5a3e5d4

Please sign in to comment.