Skip to content

Commit

Permalink
bindings: remove redundant parsing methods from EventId, `PublicKey…
Browse files Browse the repository at this point in the history
…` and `SecretKey`

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 30, 2024
1 parent 4340821 commit 9c7339f
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 309 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* nostr: update `FromBech32::from_bech32` method signature ([Yuki Kishimoto])
* nostr: update `NostrURI::from_nostr_uri` method signature ([Yuki Kishimoto])
* nostr: remove generics from parsing methods in `key` module ([Yuki Kishimoto])
* bindings: remove redundant parsing methods from `EventId`, `PublicKey` and `SecretKey` ([Yuki Kishimoto])

### Changed

Expand Down
23 changes: 1 addition & 22 deletions bindings/nostr-sdk-ffi/src/protocol/event/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::ops::Deref;
use std::sync::Arc;

use nostr::nips::nip21::NostrURI;
use nostr::prelude::{FromBech32, ToBech32};
use nostr::prelude::ToBech32;
use uniffi::Object;

use super::Kind;
Expand Down Expand Up @@ -70,27 +70,6 @@ impl EventId {
})
}

#[uniffi::constructor]
pub fn from_hex(hex: &str) -> Result<Self> {
Ok(Self {
inner: nostr::EventId::from_hex(hex)?,
})
}

#[uniffi::constructor]
pub fn from_bech32(bech32: &str) -> Result<Self> {
Ok(Self {
inner: nostr::EventId::from_bech32(bech32)?,
})
}

#[uniffi::constructor]
pub fn from_nostr_uri(uri: &str) -> Result<Self> {
Ok(Self {
inner: nostr::EventId::from_nostr_uri(uri)?,
})
}

pub fn as_bytes(&self) -> Vec<u8> {
self.inner.as_bytes().to_vec()
}
Expand Down
23 changes: 1 addition & 22 deletions bindings/nostr-sdk-ffi/src/protocol/key/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::ops::Deref;

use nostr::nips::nip19::{FromBech32, ToBech32};
use nostr::nips::nip19::ToBech32;
use nostr::nips::nip21::NostrURI;
use uniffi::Object;

Expand Down Expand Up @@ -40,34 +40,13 @@ impl PublicKey {
})
}

#[uniffi::constructor]
pub fn from_hex(hex: &str) -> Result<Self> {
Ok(Self {
inner: nostr::PublicKey::from_hex(hex)?,
})
}

#[uniffi::constructor]
pub fn from_bech32(bech32: &str) -> Result<Self> {
Ok(Self {
inner: nostr::PublicKey::from_bech32(bech32)?,
})
}

#[uniffi::constructor]
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
Ok(Self {
inner: nostr::PublicKey::from_slice(bytes)?,
})
}

#[uniffi::constructor]
pub fn from_nostr_uri(uri: &str) -> Result<Self> {
Ok(Self {
inner: nostr::PublicKey::from_nostr_uri(uri)?,
})
}

pub fn to_hex(&self) -> String {
self.inner.to_string()
}
Expand Down
16 changes: 1 addition & 15 deletions bindings/nostr-sdk-ffi/src/protocol/key/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::ops::Deref;

use nostr::nips::nip19::{FromBech32, ToBech32};
use nostr::nips::nip19::ToBech32;
use uniffi::Object;

use crate::error::Result;
Expand Down Expand Up @@ -40,20 +40,6 @@ impl SecretKey {
})
}

#[uniffi::constructor]
pub fn from_hex(hex: &str) -> Result<Self> {
Ok(Self {
inner: nostr::SecretKey::from_hex(hex)?,
})
}

#[uniffi::constructor]
pub fn from_bech32(bech32: &str) -> Result<Self> {
Ok(Self {
inner: nostr::SecretKey::from_bech32(bech32)?,
})
}

#[uniffi::constructor]
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
Ok(Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_PublicKey>>
abstract class PublicKey implements RustOpaqueInterface {
static PublicKey fromHex({required String publicKey}) => RustLib.instance.api
.crateApiProtocolKeyPublicKeyPublicKeyFromHex(publicKey: publicKey);

static PublicKey fromSlice({required List<int> publicKey}) =>
RustLib.instance.api
.crateApiProtocolKeyPublicKeyPublicKeyFromSlice(publicKey: publicKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_SecretKey>>
abstract class SecretKey implements RustOpaqueInterface {
static SecretKey fromHex({required String secretKey}) => RustLib.instance.api
.crateApiProtocolKeySecretKeySecretKeyFromHex(secretKey: secretKey);

static SecretKey fromSlice({required List<int> secretKey}) =>
RustLib.instance.api
.crateApiProtocolKeySecretKeySecretKeyFromSlice(secretKey: secretKey);
Expand Down
Loading

0 comments on commit 9c7339f

Please sign in to comment.