-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip ₿ prefix from lightning address
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,13 @@ fn ln_address_decode(ln_address: &str) -> Result<(String, String, String)> { | |
if ln_address.contains('@') { | ||
let split = ln_address.split('@').collect::<Vec<&str>>(); | ||
let user = split[0].to_lowercase(); | ||
|
||
// BIP-353 addresses have a ₿ prefix. Some users will want to use it as | ||
// lnurl, so strip the prefix if it's there. | ||
let user = user | ||
.strip_prefix('₿') | ||
.map(|p| p.to_string()) | ||
.unwrap_or(user); | ||
// It is safe to downcase the domains since they are case-insensitive. | ||
// https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2 | ||
let domain = split[1].to_lowercase(); | ||
|
@@ -1411,6 +1418,29 @@ pub(crate) mod tests { | |
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_lnurl_pay_lud_16_ln_address_with_prefix() -> Result<(), Box<dyn std::error::Error>> | ||
{ | ||
// Covers cases in LUD-16, with BIP-353 prefix. | ||
|
||
let ln_address = "₿[email protected]"; | ||
let server_ln_address = "[email protected]"; | ||
let _m = mock_lnurl_ln_address_endpoint(server_ln_address, None)?; | ||
|
||
if let InputType::LnUrlPay { data: pd } = parse(ln_address).await? { | ||
assert_eq!(pd.callback, "https://localhost/lnurl-pay/callback/db945b624265fc7f5a8d77f269f7589d789a771bdfd20e91a3cf6f50382a98d7"); | ||
assert_eq!(pd.max_sendable, 16000); | ||
assert_eq!(pd.min_sendable, 4000); | ||
assert_eq!(pd.comment_allowed, 0); | ||
assert_eq!(pd.domain, "domain.net"); | ||
assert_eq!(pd.ln_address, Some(server_ln_address.to_string())); | ||
} else { | ||
panic!("input was not ln address") | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_lnurl_pay_lud_16_ln_address_error() -> Result<()> { | ||
// Covers cases in LUD-16: Paying to static internet identifiers (LN Address) | ||
|