Skip to content

Commit fc26291

Browse files
committed
Add missing docs
1 parent efbfb25 commit fc26291

File tree

12 files changed

+118
-13
lines changed

12 files changed

+118
-13
lines changed

lib/src/rust/api/client.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,25 @@ import 'protocol/event.dart';
99

1010
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Client>>
1111
abstract class Client implements RustOpaqueInterface {
12+
/// Add relay
13+
///
14+
/// Relays added with this method will have both `READ` and `WRITE` flags enabled.
15+
///
16+
/// If the relay already exists, the flags will be updated and `false` returned.
17+
///
18+
/// If are set pool subscriptions, the new added relay will inherit them.
19+
///
20+
/// Connection is **NOT** automatically started with relay, remember to call `connect` method!
1221
Future<bool> addRelay({required String url});
1322

23+
/// Connect to all added relays
1424
Future<void> connect();
1525

1626
factory Client() => NostrSdk.instance.api.crateApiClientClientNew();
1727

28+
/// Send event
29+
///
30+
/// Send `Event` to all relays with `WRITE` flag.
31+
/// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered).
1832
Future<String> sendEvent({required Event event});
1933
}

lib/src/rust/api/protocol/event.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
1010

1111
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Event>>
1212
abstract class Event implements RustOpaqueInterface {
13+
/// Serialize as JSON
1314
String asJson();
1415

16+
/// Serialize as pretty JSON
1517
String asPrettyJson();
1618

1719
/// Get event author (`pubkey` field)
1820
PublicKey author();
1921

22+
/// Get event content
2023
String content();
2124

25+
/// Get UNIX timestamp
2226
BigInt createdAt();
2327

28+
/// Deserialize from JSON
2429
static Event fromJson({required String json}) =>
2530
NostrSdk.instance.api.crateApiProtocolEventEventFromJson(json: json);
2631

32+
/// Get event ID
2733
String id();
2834

2935
/// Returns `true` if the event has an expiration tag that is expired.
@@ -37,18 +43,21 @@ abstract class Event implements RustOpaqueInterface {
3743
/// <https://github.com/nostr-protocol/nips/blob/master/70.md>
3844
bool isProtected();
3945

46+
/// Get event kind
4047
int kind();
4148

49+
/// Get event signature
4250
String signature();
4351

52+
/// Get event tags
4453
List<Tag> tags();
4554

46-
/// Verify both `EventId` and `Signature`
55+
/// Verify both the event ID and the signature
4756
void verify();
4857

49-
/// Verify if the `EventId` it's composed correctly
58+
/// Verify if the event ID it's composed correctly
5059
bool verifyId();
5160

52-
/// Verify only event `Signature`
61+
/// Verify only the event signature
5362
bool verifySignature();
5463
}

lib/src/rust/api/protocol/key.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
1212
abstract class Keys implements RustOpaqueInterface {
1313
/// Generate random keys
1414
///
15-
/// This constructor use a random number generator that retrieves randomness from the operating system.
15+
/// This constructor uses a random number generator that retrieves randomness from the operating system.
1616
static Keys generate() =>
1717
NostrSdk.instance.api.crateApiProtocolKeyKeysGenerate();
1818

19+
/// Construct keys from secret key
1920
factory Keys({required SecretKey secretKey}) =>
2021
NostrSdk.instance.api.crateApiProtocolKeyKeysNew(secretKey: secretKey);
2122

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

27+
/// Get public key
2628
PublicKey publicKey();
2729

30+
/// Get secret key
2831
SecretKey secretKey();
2932
}

lib/src/rust/api/protocol/key/public_key.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
1111

1212
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_PublicKey>>
1313
abstract class PublicKey implements RustOpaqueInterface {
14+
/// Parse from bytes
1415
static PublicKey fromSlice({required List<int> publicKey}) =>
1516
NostrSdk.instance.api
1617
.crateApiProtocolKeyPublicKeyPublicKeyFromSlice(publicKey: publicKey);
@@ -19,9 +20,12 @@ abstract class PublicKey implements RustOpaqueInterface {
1920
static PublicKey parse({required String publicKey}) => NostrSdk.instance.api
2021
.crateApiProtocolKeyPublicKeyPublicKeyParse(publicKey: publicKey);
2122

23+
/// Serialize to bech32
2224
String toBech32();
2325

26+
/// Serialize to hex
2427
String toHex();
2528

29+
/// Serialize as nostr URI
2630
String toNostrUri();
2731
}

lib/src/rust/api/protocol/key/secret_key.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
1111

1212
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_SecretKey>>
1313
abstract class SecretKey implements RustOpaqueInterface {
14+
/// Parse from bytes
1415
static SecretKey fromSlice({required List<int> secretKey}) =>
1516
NostrSdk.instance.api
1617
.crateApiProtocolKeySecretKeySecretKeyFromSlice(secretKey: secretKey);
@@ -25,7 +26,9 @@ abstract class SecretKey implements RustOpaqueInterface {
2526
static SecretKey parse({required String secretKey}) => NostrSdk.instance.api
2627
.crateApiProtocolKeySecretKeySecretKeyParse(secretKey: secretKey);
2728

29+
/// Serialize to bech32
2830
String toBech32();
2931

32+
/// Serialize to hex
3033
String toSecretHex();
3134
}

lib/src/rust/frb_generated.dart

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,13 +2127,27 @@ class ClientImpl extends RustOpaque implements Client {
21272127
NostrSdk.instance.api.rust_arc_decrement_strong_count_ClientPtr,
21282128
);
21292129

2130+
/// Add relay
2131+
///
2132+
/// Relays added with this method will have both `READ` and `WRITE` flags enabled.
2133+
///
2134+
/// If the relay already exists, the flags will be updated and `false` returned.
2135+
///
2136+
/// If are set pool subscriptions, the new added relay will inherit them.
2137+
///
2138+
/// Connection is **NOT** automatically started with relay, remember to call `connect` method!
21302139
Future<bool> addRelay({required String url}) =>
21312140
NostrSdk.instance.api.crateApiClientClientAddRelay(that: this, url: url);
21322141

2142+
/// Connect to all added relays
21332143
Future<void> connect() => NostrSdk.instance.api.crateApiClientClientConnect(
21342144
that: this,
21352145
);
21362146

2147+
/// Send event
2148+
///
2149+
/// Send `Event` to all relays with `WRITE` flag.
2150+
/// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered).
21372151
Future<String> sendEvent({required Event event}) => NostrSdk.instance.api
21382152
.crateApiClientClientSendEvent(that: this, event: event);
21392153
}
@@ -2157,10 +2171,12 @@ class EventImpl extends RustOpaque implements Event {
21572171
NostrSdk.instance.api.rust_arc_decrement_strong_count_EventPtr,
21582172
);
21592173

2174+
/// Serialize as JSON
21602175
String asJson() => NostrSdk.instance.api.crateApiProtocolEventEventAsJson(
21612176
that: this,
21622177
);
21632178

2179+
/// Serialize as pretty JSON
21642180
String asPrettyJson() =>
21652181
NostrSdk.instance.api.crateApiProtocolEventEventAsPrettyJson(
21662182
that: this,
@@ -2171,15 +2187,18 @@ class EventImpl extends RustOpaque implements Event {
21712187
that: this,
21722188
);
21732189

2190+
/// Get event content
21742191
String content() => NostrSdk.instance.api.crateApiProtocolEventEventContent(
21752192
that: this,
21762193
);
21772194

2195+
/// Get UNIX timestamp
21782196
BigInt createdAt() =>
21792197
NostrSdk.instance.api.crateApiProtocolEventEventCreatedAt(
21802198
that: this,
21812199
);
21822200

2201+
/// Get event ID
21832202
String id() => NostrSdk.instance.api.crateApiProtocolEventEventId(
21842203
that: this,
21852204
);
@@ -2200,30 +2219,33 @@ class EventImpl extends RustOpaque implements Event {
22002219
that: this,
22012220
);
22022221

2222+
/// Get event kind
22032223
int kind() => NostrSdk.instance.api.crateApiProtocolEventEventKind(
22042224
that: this,
22052225
);
22062226

2227+
/// Get event signature
22072228
String signature() =>
22082229
NostrSdk.instance.api.crateApiProtocolEventEventSignature(
22092230
that: this,
22102231
);
22112232

2233+
/// Get event tags
22122234
List<Tag> tags() => NostrSdk.instance.api.crateApiProtocolEventEventTags(
22132235
that: this,
22142236
);
22152237

2216-
/// Verify both `EventId` and `Signature`
2238+
/// Verify both the event ID and the signature
22172239
void verify() => NostrSdk.instance.api.crateApiProtocolEventEventVerify(
22182240
that: this,
22192241
);
22202242

2221-
/// Verify if the `EventId` it's composed correctly
2243+
/// Verify if the event ID it's composed correctly
22222244
bool verifyId() => NostrSdk.instance.api.crateApiProtocolEventEventVerifyId(
22232245
that: this,
22242246
);
22252247

2226-
/// Verify only event `Signature`
2248+
/// Verify only the event signature
22272249
bool verifySignature() =>
22282250
NostrSdk.instance.api.crateApiProtocolEventEventVerifySignature(
22292251
that: this,
@@ -2249,11 +2271,13 @@ class KeysImpl extends RustOpaque implements Keys {
22492271
NostrSdk.instance.api.rust_arc_decrement_strong_count_KeysPtr,
22502272
);
22512273

2274+
/// Get public key
22522275
PublicKey publicKey() =>
22532276
NostrSdk.instance.api.crateApiProtocolKeyKeysPublicKey(
22542277
that: this,
22552278
);
22562279

2280+
/// Get secret key
22572281
SecretKey secretKey() =>
22582282
NostrSdk.instance.api.crateApiProtocolKeyKeysSecretKey(
22592283
that: this,
@@ -2279,16 +2303,19 @@ class PublicKeyImpl extends RustOpaque implements PublicKey {
22792303
NostrSdk.instance.api.rust_arc_decrement_strong_count_PublicKeyPtr,
22802304
);
22812305

2306+
/// Serialize to bech32
22822307
String toBech32() =>
22832308
NostrSdk.instance.api.crateApiProtocolKeyPublicKeyPublicKeyToBech32(
22842309
that: this,
22852310
);
22862311

2312+
/// Serialize to hex
22872313
String toHex() =>
22882314
NostrSdk.instance.api.crateApiProtocolKeyPublicKeyPublicKeyToHex(
22892315
that: this,
22902316
);
22912317

2318+
/// Serialize as nostr URI
22922319
String toNostrUri() =>
22932320
NostrSdk.instance.api.crateApiProtocolKeyPublicKeyPublicKeyToNostrUri(
22942321
that: this,
@@ -2314,11 +2341,13 @@ class SecretKeyImpl extends RustOpaque implements SecretKey {
23142341
NostrSdk.instance.api.rust_arc_decrement_strong_count_SecretKeyPtr,
23152342
);
23162343

2344+
/// Serialize to bech32
23172345
String toBech32() =>
23182346
NostrSdk.instance.api.crateApiProtocolKeySecretKeySecretKeyToBech32(
23192347
that: this,
23202348
);
23212349

2350+
/// Serialize to hex
23222351
String toSecretHex() =>
23232352
NostrSdk.instance.api.crateApiProtocolKeySecretKeySecretKeyToSecretHex(
23242353
that: this,

rust/src/api/client/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,28 @@ impl _Client {
2121
}
2222
}
2323

24+
/// Add relay
25+
///
26+
/// Relays added with this method will have both `READ` and `WRITE` flags enabled.
27+
///
28+
/// If the relay already exists, the flags will be updated and `false` returned.
29+
///
30+
/// If are set pool subscriptions, the new added relay will inherit them.
31+
///
32+
/// Connection is **NOT** automatically started with relay, remember to call `connect` method!
2433
pub async fn add_relay(&self, url: &str) -> Result<bool> {
2534
Ok(self.inner.add_relay(url).await?)
2635
}
2736

37+
/// Connect to all added relays
2838
pub async fn connect(&self) {
2939
self.inner.connect().await
3040
}
3141

42+
/// Send event
43+
///
44+
/// Send `Event` to all relays with `WRITE` flag.
45+
/// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered).
3246
pub async fn send_event(&self, event: _Event) -> Result<String> {
3347
let output = self.inner.send_event(event.inner).await?;
3448
Ok(output.id().to_string())

rust/src/api/protocol/event/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ pub mod tag;
1111
use self::tag::_Tag;
1212
use super::key::public_key::_PublicKey;
1313

14+
/// Nostr event
1415
#[frb(name = "Event")]
1516
pub struct _Event {
1617
pub(crate) inner: Event,
1718
}
1819

1920
#[frb(sync)]
2021
impl _Event {
22+
/// Get event ID
2123
pub fn id(&self) -> String {
2224
self.inner.id.to_hex()
2325
}
@@ -27,14 +29,17 @@ impl _Event {
2729
self.inner.pubkey.into()
2830
}
2931

32+
/// Get UNIX timestamp
3033
pub fn created_at(&self) -> u64 {
3134
self.inner.created_at.as_u64()
3235
}
3336

37+
/// Get event kind
3438
pub fn kind(&self) -> u16 {
3539
self.inner.kind.as_u16()
3640
}
3741

42+
/// Get event tags
3843
pub fn tags(&self) -> Vec<_Tag> {
3944
self.inner
4045
.tags
@@ -44,25 +49,27 @@ impl _Event {
4449
.collect()
4550
}
4651

52+
/// Get event content
4753
pub fn content(&self) -> String {
4854
self.inner.content.to_string()
4955
}
5056

57+
/// Get event signature
5158
pub fn signature(&self) -> String {
5259
self.inner.sig.to_string()
5360
}
5461

55-
/// Verify both `EventId` and `Signature`
62+
/// Verify both the event ID and the signature
5663
pub fn verify(&self) -> Result<()> {
5764
Ok(self.inner.verify()?)
5865
}
5966

60-
/// Verify if the `EventId` it's composed correctly
67+
/// Verify if the event ID it's composed correctly
6168
pub fn verify_id(&self) -> bool {
6269
self.inner.verify_id()
6370
}
6471

65-
/// Verify only event `Signature`
72+
/// Verify only the event signature
6673
pub fn verify_signature(&self) -> bool {
6774
self.inner.verify_signature()
6875
}
@@ -82,17 +89,19 @@ impl _Event {
8289
self.inner.is_protected()
8390
}
8491

85-
#[frb(sync)]
92+
/// Deserialize from JSON
8693
pub fn from_json(json: &str) -> Result<Self> {
8794
Ok(Self {
8895
inner: Event::from_json(json)?,
8996
})
9097
}
9198

99+
/// Serialize as JSON
92100
pub fn as_json(&self) -> Result<String> {
93101
Ok(self.inner.try_as_json()?)
94102
}
95103

104+
/// Serialize as pretty JSON
96105
pub fn as_pretty_json(&self) -> Result<String> {
97106
Ok(self.inner.try_as_pretty_json()?)
98107
}

0 commit comments

Comments
 (0)