Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NIP22 - Comment #612

Closed
wants to merge 14 commits into from
4 changes: 4 additions & 0 deletions bindings/nostr-sdk-ffi/src/protocol/event/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ pub enum KindEnum {
Repost,
/// Generic Repost (NIP18)
GenericRepost,
/// Comment (NIP22)
Comment,
/// Reaction (NIP25)
Reaction,
/// Badge Award (NIP58)
Expand Down Expand Up @@ -352,6 +354,7 @@ impl From<nostr::Kind> for KindEnum {
nostr::Kind::EventDeletion => Self::EventDeletion,
nostr::Kind::Repost => Self::Repost,
nostr::Kind::GenericRepost => Self::GenericRepost,
nostr::Kind::Comment => Self::Comment,
nostr::Kind::Reaction => Self::Reaction,
nostr::Kind::BadgeAward => Self::BadgeAward,
nostr::Kind::ChannelCreation => Self::ChannelCreation,
Expand Down Expand Up @@ -438,6 +441,7 @@ impl From<KindEnum> for nostr::Kind {
KindEnum::EventDeletion => Self::EventDeletion,
KindEnum::Repost => Self::Repost,
KindEnum::GenericRepost => Self::GenericRepost,
KindEnum::Comment => Self::Comment,
KindEnum::Reaction => Self::Reaction,
KindEnum::BadgeAward => Self::BadgeAward,
KindEnum::ChannelCreation => Self::ChannelCreation,
Expand Down
66 changes: 60 additions & 6 deletions bindings/nostr-sdk-ffi/src/protocol/event/tag/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ pub enum TagStandard {
marker: Option<Marker>,
/// Should be the public key of the author of the referenced event
public_key: Option<Arc<PublicKey>>,
/// Whether the e tag is an uppercase E or not
uppercase: bool,
},
Quote {
event_id: Arc<EventId>,
relay_url: Option<String>,
/// Should be the public key of the author of the referenced event
public_key: Option<Arc<PublicKey>>,
},
/// Git clone (`clone` tag)
///
Expand Down Expand Up @@ -101,13 +109,19 @@ pub enum TagStandard {
},
ExternalIdentity {
identity: Identity,
/// Whether the i tag is an uppercase I or not
uppercase: bool,
},
CoordinateTag {
coordinate: Arc<Coordinate>,
relay_url: Option<String>,
/// Whether the a tag is an uppercase A or not
uppercase: bool,
},
Kind {
kind: KindEnum,
/// Whether the k tag is an uppercase K or not
uppercase: bool,
},
RelayUrl {
relay_url: String,
Expand Down Expand Up @@ -279,11 +293,22 @@ impl From<tag::TagStandard> for TagStandard {
relay_url,
marker,
public_key,
uppercase,
} => Self::EventTag {
event_id: Arc::new(event_id.into()),
relay_url: relay_url.map(|u| u.to_string()),
marker: marker.map(|m| m.into()),
public_key: public_key.map(|p| Arc::new(p.into())),
uppercase,
},
tag::TagStandard::Quote {
event_id,
relay_url,
public_key,
} => Self::Quote {
event_id: Arc::new(event_id.into()),
relay_url: relay_url.map(|u| u.to_string()),
public_key: public_key.map(|p| Arc::new(p.into())),
},
tag::TagStandard::GitClone(urls) => Self::GitClone {
urls: urls.into_iter().map(|r| r.to_string()).collect(),
Expand Down Expand Up @@ -344,14 +369,23 @@ impl From<tag::TagStandard> for TagStandard {
tag::TagStandard::Coordinate {
coordinate,
relay_url,
uppercase,
} => Self::CoordinateTag {
coordinate: Arc::new(coordinate.into()),
relay_url: relay_url.map(|u| u.to_string()),
uppercase,
},
tag::TagStandard::ExternalIdentity(identity) => Self::ExternalIdentity {
tag::TagStandard::ExternalIdentity {
identity,
uppercase,
} => Self::ExternalIdentity {
identity: identity.into(),
uppercase,
},
tag::TagStandard::Kind { kind, uppercase } => Self::Kind {
kind: kind.into(),
uppercase,
},
tag::TagStandard::Kind(kind) => Self::Kind { kind: kind.into() },
tag::TagStandard::Relay(url) => Self::RelayUrl {
relay_url: url.to_string(),
},
Expand Down Expand Up @@ -475,11 +509,22 @@ impl TryFrom<TagStandard> for tag::TagStandard {
relay_url,
marker,
public_key,
uppercase,
} => Ok(Self::Event {
event_id: **event_id,
relay_url: relay_url.map(UncheckedUrl::from),
marker: marker.map(nip10::Marker::from),
public_key: public_key.map(|p| **p),
uppercase,
}),
TagStandard::Quote {
event_id,
relay_url,
public_key,
} => Ok(Self::Quote {
event_id: **event_id,
relay_url: relay_url.map(UncheckedUrl::from),
public_key: public_key.map(|p| **p),
}),
TagStandard::GitClone { urls } => {
let mut parsed_urls: Vec<Url> = Vec::with_capacity(urls.len());
Expand Down Expand Up @@ -534,17 +579,26 @@ impl TryFrom<TagStandard> for tag::TagStandard {
TagStandard::Hashtag { hashtag } => Ok(Self::Hashtag(hashtag)),
TagStandard::Geohash { geohash } => Ok(Self::Geohash(geohash)),
TagStandard::Identifier { identifier } => Ok(Self::Identifier(identifier)),
TagStandard::ExternalIdentity { identity } => {
Ok(Self::ExternalIdentity(identity.into()))
}
TagStandard::ExternalIdentity {
identity,
uppercase,
} => Ok(Self::ExternalIdentity {
identity: identity.into(),
uppercase,
}),
TagStandard::CoordinateTag {
coordinate,
relay_url,
uppercase,
} => Ok(Self::Coordinate {
coordinate: coordinate.as_ref().deref().clone(),
relay_url: relay_url.map(UncheckedUrl::from),
uppercase,
}),
TagStandard::Kind { kind, uppercase } => Ok(Self::Kind {
kind: kind.into(),
uppercase,
}),
TagStandard::Kind { kind } => Ok(Self::Kind(kind.into())),
TagStandard::RelayUrl { relay_url } => Ok(Self::Relay(UncheckedUrl::from(relay_url))),
TagStandard::POW { nonce, difficulty } => Ok(Self::POW {
nonce: nonce.parse()?,
Expand Down
30 changes: 8 additions & 22 deletions bindings/nostr-sdk-flutter/lib/src/rust/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,14 @@ import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'protocol/event.dart';

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Client>>
abstract class Client implements RustOpaqueInterface {
Future<bool> addRelay({required String url});

Future<void> connect();


static Client default_() =>
RustLib.instance.api.crateApiClientClientDefault();


// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Client>>
abstract class Client implements RustOpaqueInterface {
Future<bool> addRelay({required String url });


Future<void> connect();


static Client default_()=>RustLib.instance.api.crateApiClientClientDefault();


Future<String> sendEvent({required Event event });




}


Future<String> sendEvent({required Event event});
}
85 changes: 30 additions & 55 deletions bindings/nostr-sdk-flutter/lib/src/rust/api/protocol/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,47 @@ import '../../frb_generated.dart';
import 'key/public_key.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Event>>
abstract class Event implements RustOpaqueInterface {
Future<String> asJson();

Future<String> asPrettyJson();


/// Get event author (`pubkey` field)
Future<PublicKey> author();


// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Event>>
abstract class Event implements RustOpaqueInterface {
Future<String> asJson();
Future<String> content();

Future<BigInt> createdAt();

Future<String> asPrettyJson();
static Event fromJson({required String json}) =>
RustLib.instance.api.crateApiProtocolEventEventFromJson(json: json);

Future<String> id();

/// Get event author (`pubkey` field)
Future<PublicKey> author();
/// Returns `true` if the event has an expiration tag that is expired.
/// If an event has no expiration tag, then it will return `false`.
///
/// <https://github.com/nostr-protocol/nips/blob/master/40.md>
Future<bool> isExpired();

/// Check if it's a protected event
///
/// <https://github.com/nostr-protocol/nips/blob/master/70.md>
Future<bool> isProtected();

Future<String> content();
Future<int> kind();

Future<String> signature();

Future<BigInt> createdAt();
Future<List<List<String>>> tags();

/// Verify both `EventId` and `Signature`
Future<void> verify();

static Event fromJson({required String json })=>RustLib.instance.api.crateApiProtocolEventEventFromJson(json: json);
/// Verify if the `EventId` it's composed correctly
Future<bool> verifyId();


Future<String> id();


/// Returns `true` if the event has an expiration tag that is expired.
/// If an event has no expiration tag, then it will return `false`.
///
/// <https://github.com/nostr-protocol/nips/blob/master/40.md>
Future<bool> isExpired();


/// Check if it's a protected event
///
/// <https://github.com/nostr-protocol/nips/blob/master/70.md>
Future<bool> isProtected();


Future<int> kind();


Future<String> signature();


Future<List<List<String>>> tags();


/// Verify both `EventId` and `Signature`
Future<void> verify();


/// Verify if the `EventId` it's composed correctly
Future<bool> verifyId();


/// Verify only event `Signature`
Future<bool> verifySignature();




}


/// Verify only event `Signature`
Future<bool> verifySignature();
}
43 changes: 15 additions & 28 deletions bindings/nostr-sdk-flutter/lib/src/rust/api/protocol/key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,22 @@ import 'key/public_key.dart';
import 'key/secret_key.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Keys>>
abstract class Keys implements RustOpaqueInterface {
/// Generate random keys
///
/// This constructor use a random number generator that retrieves randomness from the operating system.
static Keys generate() =>
RustLib.instance.api.crateApiProtocolKeyKeysGenerate();


factory Keys({required SecretKey secretKey}) =>
RustLib.instance.api.crateApiProtocolKeyKeysNew(secretKey: secretKey);


/// Parse secret key from `hex` or `bech32`
static Keys parse({required String secretKey}) =>
RustLib.instance.api.crateApiProtocolKeyKeysParse(secretKey: secretKey);


// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Keys>>
abstract class Keys implements RustOpaqueInterface {
/// Generate random keys
///
/// This constructor use a random number generator that retrieves randomness from the operating system.
static Keys generate()=>RustLib.instance.api.crateApiProtocolKeyKeysGenerate();
Future<PublicKey> publicKey();


factory Keys({required SecretKey secretKey })=>RustLib.instance.api.crateApiProtocolKeyKeysNew(secretKey: secretKey);


/// Parse secret key from `hex` or `bech32`
static Keys parse({required String secretKey })=>RustLib.instance.api.crateApiProtocolKeyKeysParse(secretKey: secretKey);


Future<PublicKey> publicKey();


Future<SecretKey> secretKey();




}


Future<SecretKey> secretKey();
}
Loading
Loading