rust_nostr_server/msgapi/
challange.rs1use chrono::{Duration, Utc};
2use nostr::event::Event;
3use nostr::Kind;
4
5pub struct Challenge {
6 pub challenge_event: Event,
7}
8
9impl Challenge {
10 pub async fn new(challenge_event: Event) -> Self {
11 Challenge { challenge_event }
12 }
13 pub async fn time_check(&self) -> bool {
14 let crate_time: nostr::Timestamp = self.challenge_event.created_at;
15 let now = Utc::now();
16 let ten_minutes = Duration::try_minutes(10);
17 let ten_minutes_ago = now - ten_minutes.unwrap();
18 let ten_minutes_ago_timestamp = nostr::Timestamp::from(ten_minutes_ago.timestamp() as u64);
19 if crate_time < ten_minutes_ago_timestamp {
20 return false;
21 }
22 true
23 }
24 pub async fn signature_check(&self) -> bool {
25 let certified = self.challenge_event.verify_signature().is_err();
26 if certified {
27 return false;
28 }
29 true
30 }
31 pub async fn ClientAuthentication(&self) -> bool {
32 let kind: nostr::Kind = self.challenge_event.kind;
33 match kind {
34 Kind::Authentication => {
35 return true;
36 }
37 _ => {
38 return false;
39 }
40 }
41 }
42 pub async fn relay_check(&self) -> bool {
43 false
44 }
45}