-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
037647f
commit 5e2f88b
Showing
11 changed files
with
266 additions
and
2 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
DATABASE_URL=postgres://localhost/hermes | ||
FM_DB_PATH=./.fedimint-test-dir | ||
NSEC= | ||
DOMAIN_URL= | ||
#HERMES_PORT=8080 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,88 @@ | ||
use crate::State; | ||
use anyhow::anyhow; | ||
use fedimint_core::Amount; | ||
|
||
use crate::routes::{LnurlStatus, LnurlType, LnurlWellKnownResponse}; | ||
|
||
pub async fn well_known_lnurlp( | ||
state: &State, | ||
name: String, | ||
) -> anyhow::Result<LnurlWellKnownResponse> { | ||
let user = state.db.get_user_by_name(name.clone())?; | ||
if user.is_none() { | ||
return Err(anyhow!("NotFound")); | ||
} | ||
|
||
let res = LnurlWellKnownResponse { | ||
callback: format!("{}/lnurlp/{}/callback", state.domain, name).parse()?, | ||
max_sendable: Amount { msats: 100000 }, | ||
min_sendable: Amount { msats: 1000 }, | ||
metadata: "test metadata".to_string(), // TODO what should this be? | ||
comment_allowed: None, | ||
tag: LnurlType::PayRequest, | ||
status: LnurlStatus::Ok, | ||
nostr_pubkey: Some(state.nostr.keys().await.public_key()), | ||
allows_nostr: true, | ||
}; | ||
|
||
Ok(res) | ||
} | ||
|
||
#[cfg(all(test, feature = "integration-tests"))] | ||
mod tests_integration { | ||
use nostr::{key::FromSkStr, Keys}; | ||
use secp256k1::Secp256k1; | ||
use std::sync::Arc; | ||
|
||
use crate::{ | ||
db::setup_db, lnurlp::well_known_lnurlp, mint::MockMultiMintWrapperTrait, | ||
models::app_user::NewAppUser, State, | ||
}; | ||
|
||
#[tokio::test] | ||
pub async fn well_known_nip5_lookup_test() { | ||
dotenv::dotenv().ok(); | ||
let pg_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); | ||
let db = setup_db(pg_url); | ||
|
||
// swap out fm with a mock here since that's not what is being tested | ||
let mock_mm = MockMultiMintWrapperTrait::new(); | ||
|
||
// nostr | ||
let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); | ||
let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); | ||
let nostr = nostr_sdk::Client::new(&nostr_sk); | ||
|
||
let mock_mm = Arc::new(mock_mm); | ||
let state = State { | ||
db: db.clone(), | ||
mm: mock_mm, | ||
secp: Secp256k1::new(), | ||
nostr, | ||
domain: "http://hello.com".to_string(), | ||
}; | ||
|
||
let username = "wellknownuser".to_string(); | ||
let user = NewAppUser { | ||
pubkey: "e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443".to_string(), | ||
name: username.clone(), | ||
federation_id: "".to_string(), | ||
federation_invite_code: "".to_string(), | ||
}; | ||
|
||
// don't care about error if already exists | ||
let _ = state.db.insert_new_user(user); | ||
|
||
match well_known_lnurlp(&state, username.clone()).await { | ||
Ok(result) => { | ||
assert_eq!( | ||
result.callback, | ||
"http://hello.com/lnurlp/wellknownuser/callback" | ||
.parse() | ||
.unwrap() | ||
); | ||
} | ||
Err(e) => panic!("shouldn't error: {e}"), | ||
} | ||
} | ||
} |
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,77 @@ | ||
use nostr::prelude::XOnlyPublicKey; | ||
use std::{collections::HashMap, str::FromStr}; | ||
|
||
use crate::State; | ||
|
||
pub fn well_known_nip5( | ||
state: &State, | ||
name: String, | ||
) -> anyhow::Result<HashMap<String, XOnlyPublicKey>> { | ||
let user = state.db.get_user_by_name(name)?; | ||
|
||
let mut names = HashMap::new(); | ||
if let Some(user) = user { | ||
names.insert(user.name, XOnlyPublicKey::from_str(&user.pubkey).unwrap()); | ||
} | ||
|
||
Ok(names) | ||
} | ||
|
||
#[cfg(all(test, feature = "integration-tests"))] | ||
mod tests_integration { | ||
use nostr::{key::FromSkStr, Keys}; | ||
use secp256k1::{PublicKey, Secp256k1, XOnlyPublicKey}; | ||
use std::{str::FromStr, sync::Arc}; | ||
|
||
use crate::{ | ||
db::setup_db, mint::MockMultiMintWrapperTrait, models::app_user::NewAppUser, | ||
nostr::well_known_nip5, State, | ||
}; | ||
|
||
#[tokio::test] | ||
pub async fn well_known_nip5_lookup_test() { | ||
dotenv::dotenv().ok(); | ||
let pg_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); | ||
let db = setup_db(pg_url); | ||
|
||
// swap out fm with a mock here since that's not what is being tested | ||
let mock_mm = MockMultiMintWrapperTrait::new(); | ||
|
||
// nostr | ||
let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); | ||
let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); | ||
let nostr = nostr_sdk::Client::new(&nostr_sk); | ||
|
||
let mock_mm = Arc::new(mock_mm); | ||
let state = State { | ||
db: db.clone(), | ||
mm: mock_mm, | ||
secp: Secp256k1::new(), | ||
nostr, | ||
domain: "http://127.0.0.1:8080".to_string(), | ||
}; | ||
|
||
let username = "wellknownuser".to_string(); | ||
let kpk1 = PublicKey::from_str( | ||
"02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443", | ||
) | ||
.unwrap(); | ||
let pk1 = XOnlyPublicKey::from(kpk1); | ||
let user = NewAppUser { | ||
pubkey: "e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443".to_string(), | ||
name: username.clone(), | ||
federation_id: "".to_string(), | ||
federation_invite_code: "".to_string(), | ||
}; | ||
|
||
// don't care about error if already exists | ||
let _ = state.db.insert_new_user(user); | ||
|
||
match well_known_nip5(&state, username.clone()) { | ||
Ok(result) => { | ||
assert_eq!(result.get(&username).unwrap().to_string(), pk1.to_string()); | ||
} | ||
Err(e) => panic!("shouldn't error: {e}"), | ||
} | ||
} | ||
} |
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.