use anyhow::Result; use nostr::prelude::*; use signed_core::Announcement; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Nip34Kind { Initialized, Cloned, ToolingOnly, } #[derive(serde::Deserialize)] pub(crate) struct Nip34Json { pub(crate) identifier: Option, pub(crate) owner: Option, } #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] pub struct GraspSignals { pub nip34_json: bool, pub nip34_excluded: bool, pub nostr_repo_config: bool, pub nostr_remote: bool, pub grasp_remote: bool, pub nip34_grasp_remote: bool, pub nip34_state_refs: bool, pub nostr_cache: bool, pub nostr_aux_config: bool, pub maintainers_yaml: bool, } impl GraspSignals { /// Returns whether any Nostr tooling marker was found. pub fn any(&self) -> bool { *self != Self::default() } } #[derive(Debug, Clone, PartialEq)] pub struct Nip34Binding { pub kind: Nip34Kind, pub signals: GraspSignals, pub owner: Option, pub identifier: Option, pub grasp_urls: Vec, } impl Nip34Binding { /// Creates a binding from its kind, detected signals, and recovered coordinates. pub fn new( kind: Nip34Kind, signals: GraspSignals, owner: Option, identifier: Option, grasp_urls: Vec, ) -> Self { Self { kind, signals, owner, identifier, grasp_urls, } } } /// A repository's `nip34.json`, the local metadata `nak git` keeps. #[derive(serde::Serialize)] pub struct Nip34Metadata { pub identifier: String, pub name: String, pub description: String, /// The owner's public key, encoded as `npub`. pub owner: String, /// Grasp server hostnames. #[serde(rename = "grasp-servers")] pub grasp_servers: Vec, #[serde(rename = "earliest-unique-commit")] pub earliest_unique_commit: String, } impl Nip34Metadata { /// The metadata of an announced repository. pub fn from_announcement(announcement: &Announcement) -> Result { Ok(Self { identifier: announcement.id.clone(), name: announcement.name.clone().unwrap_or_default(), description: announcement.description.clone().unwrap_or_default(), owner: announcement.owner.to_bech32()?, grasp_servers: announcement .relays .iter() .filter_map(|relay| relay.domain().map(str::to_owned)) .collect(), earliest_unique_commit: announcement.euc.clone().unwrap_or_default(), }) } }