File tree Expand file tree Collapse file tree 10 files changed +24
-32
lines changed
bindings/nostr-ffi/src/nips Expand file tree Collapse file tree 10 files changed +24
-32
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,12 @@ use std::str::FromStr;
5
5
use std:: sync:: Arc ;
6
6
7
7
use nostr:: nips:: nip01;
8
- use nostr:: nips:: nip19:: ToBech32 ;
8
+ use nostr:: nips:: nip19:: { FromBech32 , ToBech32 } ;
9
9
use nostr:: nips:: nip21:: NostrURI ;
10
- use nostr:: FromBech32 ;
11
10
use uniffi:: Object ;
12
11
13
- use crate :: { error:: Result , PublicKey } ;
12
+ use crate :: error:: Result ;
13
+ use crate :: PublicKey ;
14
14
15
15
/// Coordinate for event (`a` tag)
16
16
#[ derive( Object ) ]
Original file line number Diff line number Diff line change @@ -7,9 +7,7 @@ use std::sync::Arc;
7
7
8
8
use nostr:: nips:: nip11;
9
9
use nostr:: Url ;
10
- use uniffi:: Enum ;
11
- use uniffi:: Object ;
12
- use uniffi:: Record ;
10
+ use uniffi:: { Enum , Object , Record } ;
13
11
14
12
use crate :: error:: Result ;
15
13
use crate :: Timestamp ;
Original file line number Diff line number Diff line change 4
4
use nostr:: nips:: nip13;
5
5
6
6
/// Gets the number of leading zero bits. Result is between 0 and 255.
7
+ #[ uniffi:: export]
7
8
pub fn get_leading_zero_bits ( bytes : Vec < u8 > ) -> u8 {
8
9
nip13:: get_leading_zero_bits ( bytes)
9
10
}
10
11
11
12
/// Returns all possible ID prefixes (hex) that have the specified number of leading zero bits.
12
13
///
13
14
/// Possible values: 0-255
15
+ #[ uniffi:: export]
14
16
pub fn get_prefixes_for_difficulty ( leading_zero_bits : u8 ) -> Vec < String > {
15
17
nip13:: get_prefixes_for_difficulty ( leading_zero_bits)
16
18
}
Original file line number Diff line number Diff line change @@ -6,8 +6,7 @@ use std::sync::Arc;
6
6
7
7
use nostr:: nips:: nip19:: { self , FromBech32 , ToBech32 } ;
8
8
use nostr:: nips:: nip21:: NostrURI ;
9
- use uniffi:: Enum ;
10
- use uniffi:: Object ;
9
+ use uniffi:: { Enum , Object } ;
11
10
12
11
use super :: nip01:: Coordinate ;
13
12
use crate :: error:: Result ;
Original file line number Diff line number Diff line change 4
4
use std:: sync:: Arc ;
5
5
6
6
use nostr:: nips:: nip21;
7
- use uniffi:: Enum ;
8
- use uniffi:: Object ;
7
+ use uniffi:: { Enum , Object } ;
9
8
10
9
use crate :: error:: Result ;
11
10
use crate :: nips:: nip01:: Coordinate ;
Original file line number Diff line number Diff line change @@ -63,13 +63,11 @@ pub fn verify_delegation_signature(
63
63
) -> Result < bool > {
64
64
let conditions = Conditions :: from_str ( & conditions) ?;
65
65
let signature_struct = Signature :: from_str ( & signature) ?;
66
- match nip26:: verify_delegation_signature (
66
+ Ok ( nip26:: verify_delegation_signature (
67
67
* * delegator_public_key,
68
68
signature_struct,
69
69
* * delegatee_public_key,
70
70
conditions,
71
- ) {
72
- Ok ( _) => Ok ( true ) ,
73
- Err ( _) => Ok ( false ) ,
74
- }
71
+ )
72
+ . is_ok ( ) )
75
73
}
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ use std::str::FromStr;
5
5
use std:: sync:: Arc ;
6
6
7
7
use nostr:: nips:: nip47;
8
- use nostr:: Url ;
8
+ use nostr:: { JsonUtil , Url } ;
9
9
use uniffi:: { Enum , Record } ;
10
10
11
11
use crate :: error:: Result ;
12
- use crate :: { JsonValue , PublicKey , SecretKey } ;
12
+ use crate :: { PublicKey , SecretKey } ;
13
13
14
14
/// NIP47 Response Error codes
15
15
#[ derive( Enum ) ]
@@ -332,8 +332,8 @@ impl From<nip47::Request> for Request {
332
332
#[ uniffi:: export]
333
333
impl Request {
334
334
#[ 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 ( ) )
337
337
}
338
338
}
339
339
@@ -554,8 +554,8 @@ impl From<nip47::Response> for Response {
554
554
impl Response {
555
555
/// Deserialize from JSON string
556
556
#[ 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 ( ) )
559
559
}
560
560
}
561
561
Original file line number Diff line number Diff line change 1
1
// Copyright (c) 2023-2024 Rust Nostr Developers
2
2
// Distributed under the MIT software license
3
3
4
- use std:: { ops:: Deref , sync:: Arc } ;
4
+ use std:: collections:: HashMap ;
5
+ use std:: ops:: Deref ;
6
+ use std:: sync:: Arc ;
5
7
6
8
use nostr:: nips:: nip65;
7
9
8
10
use crate :: { Event , RelayMetadata } ;
9
11
10
12
/// 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 > > {
12
15
nip65:: extract_relay_list ( event. deref ( ) )
13
16
. into_iter ( )
14
17
. map ( |( s, r) | ( s. to_string ( ) , r. map ( |r| r. into ( ) ) ) )
Original file line number Diff line number Diff line change 1
1
// Copyright (c) 2023-2024 Rust Nostr Developers
2
2
// Distributed under the MIT software license
3
3
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
-
11
4
use std:: str:: FromStr ;
12
5
13
6
use nostr:: hashes:: sha256:: Hash as Sha256Hash ;
Original file line number Diff line number Diff line change @@ -47,15 +47,15 @@ impl fmt::Display for Error {
47
47
}
48
48
49
49
/// 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 > {
51
51
events
52
52
. into_iter ( )
53
53
. filter ( |e| e. kind == * kind_needed)
54
54
. collect ( )
55
55
}
56
56
57
57
/// 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 (
59
59
tags : & [ Tag ] ,
60
60
awarded_public_key : & XOnlyPublicKey ,
61
61
) -> Option < ( XOnlyPublicKey , Option < UncheckedUrl > ) > {
You can’t perform that action at this time.
0 commit comments