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: add NIP-35 support #683

Closed
wants to merge 10 commits into from
Closed

nostr: add NIP-35 support #683

wants to merge 10 commits into from

Conversation

1wErt3r
Copy link
Contributor

@1wErt3r 1wErt3r commented Dec 19, 2024

Adds support for NIP35 (BitTorrent metadata)

  • Added Torrent and TorrentFile structs to represent torrent metadata and files.
  • Implemented to_event_builder method for Torrent to convert metadata into a Nostr event.
  • Added TorrentComment struct to represent comments on torrent events.
  • Implemented to_event_builder method for TorrentComment to convert comments into a Nostr event.
use nostr::nips::nip35::{Torrent, TorrentFile, TorrentComment};
use nostr::{EventBuilder, EventId, RelayUrl};

// Create a Torrent instance
let torrent = Torrent {
    title: "Example Torrent".to_string(),
    description: "This is an example torrent.".to_string(),
    info_hash: "abcdef1234567890".to_string(),
    files: vec![
        TorrentFile {
            name: "file1.txt".to_string(),
            size: 1024,
        },
        TorrentFile {
            name: "file2.txt".to_string(),
            size: 2048,
        },
    ],
    trackers: vec!["http://tracker.example.com".to_string()],
    categories: vec!["video".to_string(), "movie".to_string()],
    hashtags: vec!["example".to_string()],
};

// Convert to Nostr event
let event_builder = torrent.to_event_builder();

// Create a TorrentComment instance
let comment = TorrentComment {
    torrent_event: EventId::new(),
    content: "This is a comment.".to_string(),
    relay_url: Some(RelayUrl::new("http://relay.example.com/")),
};

This commit adds support for sharing BitTorrent metadata and comments through Nostr events, as specified in NIP-35.

@1wErt3r 1wErt3r force-pushed the nip-35 branch 2 times, most recently from 83ec494 to b22d0a3 Compare December 19, 2024 16:45
@1wErt3r 1wErt3r marked this pull request as ready for review December 19, 2024 16:47
- Added `Torrent` and `TorrentFile` structs to represent torrent metadata and files.
- Implemented `to_event_builder` method for `Torrent` to convert metadata into a Nostr event.
- Added `TorrentComment` struct to represent comments on torrent events.
- Implemented `to_event_builder` method for `TorrentComment` to convert comments into a Nostr event.

```rust
use nostr::nips::nip35::{Torrent, TorrentFile, TorrentComment};
use nostr::{EventBuilder, EventId, RelayUrl};

// Create a Torrent instance
let torrent = Torrent {
    title: "Example Torrent".to_string(),
    description: "This is an example torrent.".to_string(),
    info_hash: "abcdef1234567890".to_string(),
    files: vec![
        TorrentFile {
            name: "file1.txt".to_string(),
            size: 1024,
        },
        TorrentFile {
            name: "file2.txt".to_string(),
            size: 2048,
        },
    ],
    trackers: vec!["http://tracker.example.com".to_string()],
    categories: vec!["video".to_string(), "movie".to_string()],
    hashtags: vec!["example".to_string()],
};

// Convert to Nostr event
let event_builder = torrent.to_event_builder();

// Create a TorrentComment instance
let comment = TorrentComment {
    torrent_event: EventId::new(),
    content: "This is a comment.".to_string(),
    relay_url: Some(RelayUrl::new("http://relay.example.com")),
};
```

This commit adds support for sharing BitTorrent metadata and comments through Nostr events, as specified in [NIP-35](https://github.com/nostr-protocol/nips/blob/master/35.md).
Copy link
Member

@yukibtc yukibtc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I flagged some changes to do.

bindings/nostr-sdk-ffi/src/protocol/event/kind.rs Outdated Show resolved Hide resolved
bindings/nostr-sdk-ffi/src/protocol/event/tag/kind.rs Outdated Show resolved Hide resolved
bindings/nostr-sdk-ffi/src/protocol/event/tag/kind.rs Outdated Show resolved Hide resolved
crates/nostr/src/event/tag/kind.rs Outdated Show resolved Hide resolved
crates/nostr/src/nips/nip35.rs Outdated Show resolved Hide resolved
crates/nostr/src/nips/nip35.rs Outdated Show resolved Hide resolved
crates/nostr/src/nips/nip35.rs Outdated Show resolved Hide resolved
crates/nostr/src/nips/nip35.rs Outdated Show resolved Hide resolved
crates/nostr/src/nips/nip35.rs Outdated Show resolved Hide resolved
crates/nostr/src/nips/nip35.rs Outdated Show resolved Hide resolved
@yukibtc
Copy link
Member

yukibtc commented Dec 20, 2024

In the review I missed a thing. Can you add this like to the prelude module?

pub use crate::nips::nip35::{self, *};

@1wErt3r 1wErt3r requested a review from yukibtc December 21, 2024 02:00
@yukibtc yukibtc closed this in af36bba Dec 21, 2024
@yukibtc
Copy link
Member

yukibtc commented Dec 21, 2024

Thanks! During the cherry-picking I've fixed some missing thing and the torrent event building (the tags were wrong but I didn't noticed in the last review). Cherry-picked and squashed at af36bba

@1wErt3r
Copy link
Contributor Author

1wErt3r commented Dec 21, 2024

Thank you for taking the time to do such a thorough review! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants