Skip to content

Commit 6a2e5bd

Browse files
committed
ffi(nostr): add missing #[uniffi::export]
`Request::from_value` to `Request::parse` `Response::from_value` to `Response::parse`
1 parent aa03dfa commit 6a2e5bd

File tree

10 files changed

+24
-32
lines changed

10 files changed

+24
-32
lines changed

bindings/nostr-ffi/src/nips/nip01.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use std::str::FromStr;
55
use std::sync::Arc;
66

77
use nostr::nips::nip01;
8-
use nostr::nips::nip19::ToBech32;
8+
use nostr::nips::nip19::{FromBech32, ToBech32};
99
use nostr::nips::nip21::NostrURI;
10-
use nostr::FromBech32;
1110
use uniffi::Object;
1211

13-
use crate::{error::Result, PublicKey};
12+
use crate::error::Result;
13+
use crate::PublicKey;
1414

1515
/// Coordinate for event (`a` tag)
1616
#[derive(Object)]

bindings/nostr-ffi/src/nips/nip11.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use std::sync::Arc;
77

88
use nostr::nips::nip11;
99
use nostr::Url;
10-
use uniffi::Enum;
11-
use uniffi::Object;
12-
use uniffi::Record;
10+
use uniffi::{Enum, Object, Record};
1311

1412
use crate::error::Result;
1513
use crate::Timestamp;

bindings/nostr-ffi/src/nips/nip13.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
use nostr::nips::nip13;
55

66
/// Gets the number of leading zero bits. Result is between 0 and 255.
7+
#[uniffi::export]
78
pub fn get_leading_zero_bits(bytes: Vec<u8>) -> u8 {
89
nip13::get_leading_zero_bits(bytes)
910
}
1011

1112
/// Returns all possible ID prefixes (hex) that have the specified number of leading zero bits.
1213
///
1314
/// Possible values: 0-255
15+
#[uniffi::export]
1416
pub fn get_prefixes_for_difficulty(leading_zero_bits: u8) -> Vec<String> {
1517
nip13::get_prefixes_for_difficulty(leading_zero_bits)
1618
}

bindings/nostr-ffi/src/nips/nip19.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::sync::Arc;
66

77
use nostr::nips::nip19::{self, FromBech32, ToBech32};
88
use nostr::nips::nip21::NostrURI;
9-
use uniffi::Enum;
10-
use uniffi::Object;
9+
use uniffi::{Enum, Object};
1110

1211
use super::nip01::Coordinate;
1312
use crate::error::Result;

bindings/nostr-ffi/src/nips/nip21.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use std::sync::Arc;
55

66
use nostr::nips::nip21;
7-
use uniffi::Enum;
8-
use uniffi::Object;
7+
use uniffi::{Enum, Object};
98

109
use crate::error::Result;
1110
use crate::nips::nip01::Coordinate;

bindings/nostr-ffi/src/nips/nip26.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ pub fn verify_delegation_signature(
6363
) -> Result<bool> {
6464
let conditions = Conditions::from_str(&conditions)?;
6565
let signature_struct = Signature::from_str(&signature)?;
66-
match nip26::verify_delegation_signature(
66+
Ok(nip26::verify_delegation_signature(
6767
**delegator_public_key,
6868
signature_struct,
6969
**delegatee_public_key,
7070
conditions,
71-
) {
72-
Ok(_) => Ok(true),
73-
Err(_) => Ok(false),
74-
}
71+
)
72+
.is_ok())
7573
}

bindings/nostr-ffi/src/nips/nip47.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::str::FromStr;
55
use std::sync::Arc;
66

77
use nostr::nips::nip47;
8-
use nostr::Url;
8+
use nostr::{JsonUtil, Url};
99
use uniffi::{Enum, Record};
1010

1111
use crate::error::Result;
12-
use crate::{JsonValue, PublicKey, SecretKey};
12+
use crate::{PublicKey, SecretKey};
1313

1414
/// NIP47 Response Error codes
1515
#[derive(Enum)]
@@ -332,8 +332,8 @@ impl From<nip47::Request> for Request {
332332
#[uniffi::export]
333333
impl Request {
334334
#[uniffi::constructor]
335-
pub fn from_value(value: JsonValue) -> Result<Self> {
336-
Ok(nip47::Request::from_value(value.try_into()?)?.into())
335+
pub fn parse(json: String) -> Result<Self> {
336+
Ok(nip47::Request::from_json(json)?.into())
337337
}
338338
}
339339

@@ -554,8 +554,8 @@ impl From<nip47::Response> for Response {
554554
impl Response {
555555
/// Deserialize from JSON string
556556
#[uniffi::constructor]
557-
pub fn from_value(value: JsonValue) -> Result<Self> {
558-
Ok(nip47::Response::from_value(value.try_into()?)?.into())
557+
pub fn parse(json: String) -> Result<Self> {
558+
Ok(nip47::Response::from_json(json)?.into())
559559
}
560560
}
561561

bindings/nostr-ffi/src/nips/nip65.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// Copyright (c) 2023-2024 Rust Nostr Developers
22
// Distributed under the MIT software license
33

4-
use std::{ops::Deref, sync::Arc};
4+
use std::collections::HashMap;
5+
use std::ops::Deref;
6+
use std::sync::Arc;
57

68
use nostr::nips::nip65;
79

810
use crate::{Event, RelayMetadata};
911

1012
/// Extracts the relay info (url, optional read/write flag) from the event
11-
pub fn extract_relay_list(event: Arc<Event>) -> Vec<(String, Option<RelayMetadata>)> {
13+
#[uniffi::export]
14+
pub fn extract_relay_list(event: Arc<Event>) -> HashMap<String, Option<RelayMetadata>> {
1215
nip65::extract_relay_list(event.deref())
1316
.into_iter()
1417
.map(|(s, r)| (s.to_string(), r.map(|r| r.into())))

bindings/nostr-ffi/src/nips/nip98.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
// Copyright (c) 2023-2024 Rust Nostr Developers
22
// Distributed under the MIT software license
33

4-
//! NIP98
5-
//!
6-
//! This NIP defines an ephemerial event used to authorize requests to HTTP servers using nostr events.
7-
//! This is useful for HTTP services which are build for Nostr and deal with Nostr user accounts.
8-
//!
9-
//! <https://github.com/nostr-protocol/nips/blob/master/98.md>
10-
114
use std::str::FromStr;
125

136
use nostr::hashes::sha256::Hash as Sha256Hash;

crates/nostr/src/nips/nip58.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ impl fmt::Display for Error {
4747
}
4848

4949
/// Helper function to filter events for a specific [`Kind`]
50-
pub fn filter_for_kind(events: Vec<Event>, kind_needed: &Kind) -> Vec<Event> {
50+
pub(crate) fn filter_for_kind(events: Vec<Event>, kind_needed: &Kind) -> Vec<Event> {
5151
events
5252
.into_iter()
5353
.filter(|e| e.kind == *kind_needed)
5454
.collect()
5555
}
5656

5757
/// Helper function to extract the awarded public key from an array of PubKey tags
58-
pub fn extract_awarded_public_key(
58+
pub(crate) fn extract_awarded_public_key(
5959
tags: &[Tag],
6060
awarded_public_key: &XOnlyPublicKey,
6161
) -> Option<(XOnlyPublicKey, Option<UncheckedUrl>)> {

0 commit comments

Comments
 (0)