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

nostr oracle client #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 53 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions ddk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lightning = ["dep:lightning-net-tokio"]
# oracle features
kormir = ["dep:reqwest"]
p2pderivatives = ["dep:reqwest"]
nostr-oracle = ["dep:nostr-database", "nostr", "kormir", "kormir/nostr"]

# storage features
sled = ["dep:sled"]
Expand Down Expand Up @@ -56,18 +57,19 @@ sled = { version = "0.34.7", optional = true }

# Nostr transport dependencies
base64 = { version = "0.13.0" , optional = true }
nostr-rs = { package = "nostr", version = "0.38.0", features = ["std", "nip04"], optional = true }
nostr-sdk = { version = "0.38.0", optional = true }
nostr-rs = { package = "nostr", version = "0.39.0", features = ["std", "nip04"], optional = true }
nostr-sdk = { version = "0.39.0", optional = true }

# lightning transport
lightning-net-tokio = { version = "0.0.125", optional = true }

# oracle feature
reqwest = { version = "0.12.9", features = ["json"], optional = true }
kormir = "0.4.1"
# kormir = { path = "../../kormir/kormir" }
# kormir = "0.4.1"
kormir = { path = "../../kormir/kormir" }
hmac = "0.12.1"
sha2 = "0.10"
nostr-database = { version = "0.39.0", optional = true }

[dev-dependencies]
test-log = { version = "0.2.16", features = ["trace"] }
Expand Down
2 changes: 1 addition & 1 deletion ddk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod error;
pub mod json;
/// Nostr related functions.
#[cfg(any(feature = "nostr", feature = "marketplace"))]
pub(crate) mod nostr;
pub mod nostr;
/// Oracle clients.
pub mod oracle;
/// Storage implementations.
Expand Down
2 changes: 1 addition & 1 deletion ddk/src/nostr/marketplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
let now = Timestamp::now();
let oracle_filter = super::create_oracle_message_filter(now);

client.subscribe(vec![oracle_filter], None).await?;
client.subscribe(oracle_filter, None).await?;

while let Ok(notification) = client.notifications().recv().await {
match notification {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::nostr::{DLC_MESSAGE_KIND, ORACLE_ANNOUNCMENT_KIND, ORACLE_ATTESTATION_KIND};
use crate::transport::nostr::nostr_to_bitcoin_pubkey;
use super::nostr_to_bitcoin_pubkey;
use super::{DLC_MESSAGE_KIND, ORACLE_ANNOUNCMENT_KIND, ORACLE_ATTESTATION_KIND};
use crate::util::message_variant_name;
use dlc::secp256k1_zkp::PublicKey as SecpPublicKey;
use dlc_messages::message_handler::read_dlc_message;
Expand Down
17 changes: 17 additions & 0 deletions ddk/src/nostr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
use bitcoin::secp256k1::PublicKey as BitcoinPublicKey;
use dlc_messages::oracle_msgs::{OracleAnnouncement, OracleAttestation};
use lightning::io::Cursor;
use lightning::util::ser::Readable;
use nostr_rs::key::PublicKey;
use nostr_rs::{Filter, Kind, PublicKey as NostrPublicKey, Timestamp};

/// Nostr [dlc_messages::oracle_msgs::OracleAnnouncement] marketplace.
#[cfg(feature = "marketplace")]
pub mod marketplace;
pub mod messages;

pub const DLC_MESSAGE_KIND: Kind = Kind::Custom(8_888);
pub const ORACLE_ANNOUNCMENT_KIND: Kind = Kind::Custom(88);
pub const ORACLE_ATTESTATION_KIND: Kind = Kind::Custom(89);

pub fn bitcoin_to_nostr_pubkey(bitcoin_pk: &BitcoinPublicKey) -> PublicKey {
// Convert to XOnlyPublicKey first
let (xonly, _parity) = bitcoin_pk.x_only_public_key();

// Create nostr public key from the x-only bytes
PublicKey::from_slice(xonly.serialize().as_slice())
.expect("Could not convert Bitcoin key to nostr key.")
}

pub fn nostr_to_bitcoin_pubkey(nostr_pk: &PublicKey) -> BitcoinPublicKey {
BitcoinPublicKey::from_slice(nostr_pk.as_bytes())
.expect("Should not fail converting nostr key to bitcoin key.")
}

pub fn create_dlc_message_filter(since: Timestamp, public_key: NostrPublicKey) -> Filter {
Filter::new()
.kind(DLC_MESSAGE_KIND)
Expand Down
2 changes: 2 additions & 0 deletions ddk/src/oracle/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "kormir")]
pub mod kormir;
pub mod memory;
#[cfg(any(feature = "nostr-oracle", feature = "nostr"))]
pub mod nostr;
#[cfg(feature = "p2pderivatives")]
pub mod p2p_derivatives;
Loading
Loading