diff --git a/bindings/nostr-ffi/Cargo.toml b/bindings/nostr-ffi/Cargo.toml index c38d2a825..72b119cd3 100644 --- a/bindings/nostr-ffi/Cargo.toml +++ b/bindings/nostr-ffi/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["lib", "cdylib", "staticlib"] [dependencies] nostr = { workspace = true, features = ["std", "all-nips"] } -uniffi.workspace = true +uniffi = { workspace = true, features = ["tokio"] } [dev-dependencies] uniffi = { workspace = true, features = ["bindgen-tests"] } diff --git a/bindings/nostr-ffi/src/nips/nip05.rs b/bindings/nostr-ffi/src/nips/nip05.rs index 846f54669..9b116509b 100644 --- a/bindings/nostr-ffi/src/nips/nip05.rs +++ b/bindings/nostr-ffi/src/nips/nip05.rs @@ -12,7 +12,7 @@ use crate::error::Result; use crate::nips::nip19::Nip19Profile; use crate::PublicKey; -#[uniffi::export(default(proxy = None))] +#[uniffi::export(async_runtime = "tokio", default(proxy = None))] pub async fn verify_nip05( public_key: &PublicKey, nip05: &str, @@ -25,7 +25,7 @@ pub async fn verify_nip05( Ok(nip05::verify(public_key.deref(), nip05, proxy).await?) } -#[uniffi::export(default(proxy = None))] +#[uniffi::export(async_runtime = "tokio", default(proxy = None))] pub async fn get_nip05_profile(nip05: &str, proxy: Option) -> Result> { let proxy: Option = match proxy { Some(proxy) => Some(proxy.parse()?), diff --git a/bindings/nostr-ffi/src/nips/nip11.rs b/bindings/nostr-ffi/src/nips/nip11.rs index b0799b736..e90dd7d9d 100644 --- a/bindings/nostr-ffi/src/nips/nip11.rs +++ b/bindings/nostr-ffi/src/nips/nip11.rs @@ -24,6 +24,21 @@ impl From for RelayInformationDocument { } } +#[uniffi::export(async_runtime = "tokio", default(proxy = None))] +pub async fn nip11_get_information_document( + url: &str, + proxy: Option, +) -> Result { + let url: Url = Url::parse(url)?; + let proxy: Option = match proxy { + Some(proxy) => Some(proxy.parse()?), + None => None, + }; + Ok(RelayInformationDocument { + inner: nip11::RelayInformationDocument::get(url, proxy).await?, + }) +} + #[uniffi::export] impl RelayInformationDocument { #[uniffi::constructor] @@ -34,18 +49,6 @@ impl RelayInformationDocument { } } - #[uniffi::constructor(default(proxy = None))] - pub async fn get(url: &str, proxy: Option) -> Result { - let url: Url = Url::parse(url)?; - let proxy: Option = match proxy { - Some(proxy) => Some(proxy.parse()?), - None => None, - }; - Ok(Self { - inner: nip11::RelayInformationDocument::get(url, proxy).await?, - }) - } - pub fn name(&self) -> Option { self.inner.name.clone() } diff --git a/bindings/nostr-ffi/tests/test_generated_bindings.rs b/bindings/nostr-ffi/tests/test_generated_bindings.rs index 20da56065..54b80e1ff 100644 --- a/bindings/nostr-ffi/tests/test_generated_bindings.rs +++ b/bindings/nostr-ffi/tests/test_generated_bindings.rs @@ -1 +1 @@ -uniffi::build_foreign_language_testcases!("tests/test_equality.py"); +uniffi::build_foreign_language_testcases!("tests/test_equality.py", "tests/test_nip05.py"); diff --git a/bindings/nostr-ffi/tests/test_nip05.py b/bindings/nostr-ffi/tests/test_nip05.py new file mode 100644 index 000000000..801052405 --- /dev/null +++ b/bindings/nostr-ffi/tests/test_nip05.py @@ -0,0 +1,14 @@ +import asyncio +from nostr_ffi import * + +async def main(): + nip_05 = "yuki@yukikishimoto.com" + public_key = PublicKey.parse("npub1drvpzev3syqt0kjrls50050uzf25gehpz9vgdw08hvex7e0vgfeq0eseet") + proxy = None + if await verify_nip05(public_key, nip_05, proxy): + print(f" '{nip_05}' verified, for {public_key.to_bech32()}") + else: + print(f" Unable to verify NIP-05, for {public_key.to_bech32()}") + +if __name__ == '__main__': + asyncio.run(main()) \ No newline at end of file