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 NIP90 support #187

Merged
merged 1 commit into from
Nov 3, 2023
Merged
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
6 changes: 6 additions & 0 deletions bindings/nostr-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ impl From<nostr::nips::nip46::Error> for NostrError {
}
}

impl From<nostr::nips::nip90::Error> for NostrError {
fn from(e: nostr::nips::nip90::Error) -> NostrError {
Self::Generic { err: e.to_string() }
}
}

impl From<nostr::secp256k1::Error> for NostrError {
fn from(e: nostr::secp256k1::Error) -> NostrError {
Self::Generic { err: e.to_string() }
Expand Down
46 changes: 39 additions & 7 deletions bindings/nostr-ffi/src/event/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use nostr::event::tag::{
use nostr::hashes::sha256::Hash as Sha256Hash;
use nostr::nips::nip26::Conditions;
use nostr::nips::nip48::Protocol;
use nostr::nips::nip90::DataVendingMachineStatus;
use nostr::secp256k1::schnorr::Signature;
use nostr::secp256k1::XOnlyPublicKey;
use nostr::{EventId, Kind, RelayMetadata, Timestamp, UncheckedUrl, Url};
use nostr::{Event, EventId, JsonUtil, Kind, RelayMetadata, Timestamp, UncheckedUrl, Url};

use crate::error::{NostrError, Result};

Expand Down Expand Up @@ -115,6 +116,7 @@ pub enum TagKindKnown {
Anon,
Proxy,
Emoji,
Request,
}

impl From<tag::TagKind> for TagKind {
Expand Down Expand Up @@ -264,6 +266,9 @@ impl From<tag::TagKind> for TagKind {
tag::TagKind::Emoji => Self::Known {
known: TagKindKnown::Emoji,
},
tag::TagKind::Request => Self::Known {
known: TagKindKnown::Request,
},
tag::TagKind::Custom(unknown) => Self::Unknown { unknown },
}
}
Expand Down Expand Up @@ -321,6 +326,7 @@ impl From<TagKind> for tag::TagKind {
TagKindKnown::Anon => Self::Anon,
TagKindKnown::Proxy => Self::Proxy,
TagKindKnown::Emoji => Self::Emoji,
TagKindKnown::Request => Self::Request,
},
TagKind::Unknown { unknown } => Self::Custom(unknown),
}
Expand Down Expand Up @@ -437,7 +443,8 @@ pub enum TagEnum {
urls: Vec<String>,
},
Amount {
amount: u64,
millisats: u64,
bolt11: Option<String>,
},
Lnurl {
lnurl: String,
Expand Down Expand Up @@ -485,7 +492,7 @@ pub enum TagEnum {
Ends {
timestamp: u64,
},
Status {
LiveEventStatus {
status: String,
},
CurrentParticipants {
Expand Down Expand Up @@ -514,6 +521,13 @@ pub enum TagEnum {
shortcode: String,
url: String,
},
Request {
event: String,
},
DataVendingMachineStatus {
status: String,
extra_info: Option<String>,
},
}

impl From<tag::Tag> for TagEnum {
Expand Down Expand Up @@ -624,7 +638,7 @@ impl From<tag::Tag> for TagEnum {
tag::Tag::Relays(relays) => Self::Relays {
urls: relays.into_iter().map(|r| r.to_string()).collect(),
},
tag::Tag::Amount(amount) => Self::Amount { amount },
tag::Tag::Amount { millisats, bolt11 } => Self::Amount { millisats, bolt11 },
tag::Tag::Name(name) => Self::Name { name },
tag::Tag::Lnurl(lnurl) => Self::Lnurl { lnurl },
tag::Tag::Url(url) => Self::Url {
Expand Down Expand Up @@ -653,7 +667,7 @@ impl From<tag::Tag> for TagEnum {
tag::Tag::Ends(timestamp) => Self::Ends {
timestamp: timestamp.as_u64(),
},
tag::Tag::Status(s) => Self::Status {
tag::Tag::LiveEventStatus(s) => Self::LiveEventStatus {
status: s.to_string(),
},
tag::Tag::CurrentParticipants(num) => Self::CurrentParticipants { num },
Expand All @@ -676,6 +690,15 @@ impl From<tag::Tag> for TagEnum {
shortcode,
url: url.to_string(),
},
tag::Tag::Request(event) => Self::Request {
event: event.as_json(),
},
tag::Tag::DataVendingMachineStatus { status, extra_info } => {
Self::DataVendingMachineStatus {
status: status.to_string(),
extra_info,
}
}
}
}
}
Expand Down Expand Up @@ -797,7 +820,7 @@ impl TryFrom<TagEnum> for tag::Tag {
TagEnum::Relays { urls } => Ok(Self::Relays(
urls.into_iter().map(UncheckedUrl::from).collect(),
)),
TagEnum::Amount { amount } => Ok(Self::Amount(amount)),
TagEnum::Amount { millisats, bolt11 } => Ok(Self::Amount { millisats, bolt11 }),
TagEnum::Lnurl { lnurl } => Ok(Self::Lnurl(lnurl)),
TagEnum::Name { name } => Ok(Self::Name(name)),
TagEnum::PublishedAt { timestamp } => Ok(Self::PublishedAt(Timestamp::from(timestamp))),
Expand All @@ -813,7 +836,9 @@ impl TryFrom<TagEnum> for tag::Tag {
TagEnum::Recording { url } => Ok(Self::Recording(UncheckedUrl::from(url))),
TagEnum::Starts { timestamp } => Ok(Self::Starts(Timestamp::from(timestamp))),
TagEnum::Ends { timestamp } => Ok(Self::Ends(Timestamp::from(timestamp))),
TagEnum::Status { status } => Ok(Self::Status(LiveEventStatus::from(status))),
TagEnum::LiveEventStatus { status } => {
Ok(Self::LiveEventStatus(LiveEventStatus::from(status)))
}
TagEnum::CurrentParticipants { num } => Ok(Self::CurrentParticipants(num)),
TagEnum::TotalParticipants { num } => Ok(Self::CurrentParticipants(num)),
TagEnum::AbsoluteURL { url } => Ok(Self::AbsoluteURL(UncheckedUrl::from(url))),
Expand All @@ -828,6 +853,13 @@ impl TryFrom<TagEnum> for tag::Tag {
shortcode,
url: UncheckedUrl::from(url),
}),
TagEnum::Request { event } => Ok(Self::Request(Event::from_json(event)?)),
TagEnum::DataVendingMachineStatus { status, extra_info } => {
Ok(Self::DataVendingMachineStatus {
status: DataVendingMachineStatus::from_str(&status)?,
extra_info,
})
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions bindings/nostr-ffi/src/nostr.udl
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ enum TagKindKnown {
"Anon",
"Proxy",
"Emoji",
"Request",
};

[Enum]
Expand Down Expand Up @@ -475,7 +476,7 @@ interface TagEnum {
Bolt11(string bolt11);
Preimage(string preimage);
Relays(sequence<string> urls);
Amount(u64 amount);
Amount(u64 millisats, string? bolt11);
Lnurl(string lnurl);
Name(string name);
PublishedAt(u64 timestamp);
Expand All @@ -491,7 +492,7 @@ interface TagEnum {
Recording(string url);
Starts(u64 timestamp);
Ends(u64 timestamp);
Status(string status);
LiveEventStatus(string status);
CurrentParticipants(u64 num);
TotalParticipants(u64 num);
AbsoluteURL(string url);
Expand All @@ -500,6 +501,8 @@ interface TagEnum {
Anon(string? msg);
Proxy(string id, string protocol);
Emoji(string shortcode, string url);
Request(string event);
DataVendingMachineStatus(string status, string? extra_info);
};

interface Tag {
Expand Down
9 changes: 6 additions & 3 deletions bindings/nostr-sdk-ffi/src/nostr_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ enum TagKindKnown {
"Anon",
"Proxy",
"Emoji",
"Request",
};

[Enum]
Expand Down Expand Up @@ -495,7 +496,7 @@ interface TagEnum {
Bolt11(string bolt11);
Preimage(string preimage);
Relays(sequence<string> urls);
Amount(u64 amount);
Amount(u64 millisats, string? bolt11);
Lnurl(string lnurl);
Name(string name);
PublishedAt(u64 timestamp);
Expand All @@ -511,7 +512,7 @@ interface TagEnum {
Recording(string url);
Starts(u64 timestamp);
Ends(u64 timestamp);
Status(string status);
LiveEventStatus(string status);
CurrentParticipants(u64 num);
TotalParticipants(u64 num);
AbsoluteURL(string url);
Expand All @@ -520,7 +521,9 @@ interface TagEnum {
Anon(string? msg);
Proxy(string id, string protocol);
Emoji(string shortcode, string url);
};
Request(string event);
DataVendingMachineStatus(string status, string? extra_info);
};

interface Tag {
[Throws=NostrError, Name=parse]
Expand Down
1 change: 1 addition & 0 deletions crates/nostr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ The following crate feature flags are available:
| ✅ | [65 - Relay List Metadata](https://github.com/nostr-protocol/nips/blob/master/65.md) |
| ✅ | [78 - Arbitrary custom app data](https://github.com/nostr-protocol/nips/blob/master/78.md) |
| ❌ | [89 - Recommended Application Handlers](https://github.com/nostr-protocol/nips/blob/master/89.md) |
| ✅ | [90 - Data Vending Machine](https://github.com/nostr-protocol/nips/blob/master/90.md) |
| ✅ | [94 - File Metadata](https://github.com/nostr-protocol/nips/blob/master/94.md) |
| ✅ | [98 - HTTP Auth](https://github.com/nostr-protocol/nips/blob/master/98.md) |
| ❌ | [99 - Classified Listings](https://github.com/nostr-protocol/nips/blob/master/99.md) |
Expand Down
Loading