This commit is contained in:
2026-09-17 11:13:13 +07:00
parent fd39be0eda
commit fe2d956d40
13 changed files with 507 additions and 1391 deletions
+10 -12
View File
@@ -2,12 +2,11 @@ use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
use std::fmt;
use nostr::nips::nip44::{self, Version};
use nostr_sdk::prelude::*;
use serde::{Deserialize, Serialize};
use crate::invite::{ChannelGrant, CommunityInvite};
use crate::stream::NIP44_MAX_PLAINTEXT;
use crate::stream::{self, NIP44_MAX_PLAINTEXT};
use crate::{CommunityId, Epoch, Extra};
pub const KIND_COMMUNITY_LIST: u16 = 13302;
@@ -43,6 +42,12 @@ impl fmt::Display for ListError {
impl std::error::Error for ListError {}
impl From<stream::StreamError> for ListError {
fn from(error: stream::StreamError) -> Self {
ListError::Crypto(error.to_string())
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct JoinMaterial {
pub community_id: CommunityId,
@@ -182,13 +187,7 @@ pub fn build_list_event(keys: &Keys, list: &CommunityList) -> Result<Event, List
list.fits()?;
let json = serde_json::to_string(list).map_err(json_error)?;
let content = nip44::encrypt(
keys.secret_key(),
&keys.public_key(),
json.as_bytes(),
Version::V2,
)
.map_err(crypto_error)?;
let content = stream::seal_to_self(keys, json.as_bytes())?;
EventBuilder::new(Kind::Custom(KIND_COMMUNITY_LIST), content)
.finalize(keys)
@@ -200,10 +199,9 @@ pub fn parse_list_event(keys: &Keys, event: &Event) -> Result<CommunityList, Lis
return Err(ListError::Kind(event.kind.as_u16()));
}
let json = nip44::decrypt(keys.secret_key(), &keys.public_key(), &event.content)
.map_err(crypto_error)?;
let json = stream::open_to_self(keys, &event.content)?;
serde_json::from_str(&json).map_err(json_error)
serde_json::from_slice(&json).map_err(json_error)
}
#[derive(Clone, Copy, PartialEq, Eq)]