web5_rust/dwn/
traits.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
use super::Error;
use crate::common::structs::{DateTime, Url};
use crate::crypto::secp256k1::SecretKey;
use crate::crypto::structs::Hash;
use crate::dids::structs::{DidKeyPair, Did};
use super::structs::{
    CreateDMRequest,
    ReadDMRequest,
    CreateRequest,
    UpdateRequest,
    DeleteRequest,
    ReadRequest,
    DwnResponse,
    DwnItem,
    Record,
    Packet,
};
use super::permission::Permission;
use super::protocol::Protocol;
use dyn_clone::{clone_trait_object, DynClone};

pub trait P2P: DynClone + Sync + Send + std::fmt::Debug {
    fn p_to_p(&self, protocol: &Hash) -> Result<Permission, Error>;
}
clone_trait_object!(P2P);

#[async_trait::async_trait]
pub trait Router: DynClone + std::fmt::Debug + Sync + Send {
    async fn send_packet(
        &self,
        packet: Packet,
        url: Url
    ) -> Result<DwnResponse, Error>;
}
clone_trait_object!(Router);

#[async_trait::async_trait]
pub trait RequestHandler: DynClone + std::fmt::Debug + Sync + Send {
    async fn create(
        &self,
        request: &CreateRequest,
        dids: &[&Did],
    ) -> Result<(), Error>;

    async fn read(
        &mut self,
        request: &ReadRequest,
        dids: &[&Did],
    ) -> Result<Vec<DwnItem>, Error>;

    async fn delete(
        &self,
        request: &DeleteRequest,
        dids: &[&Did],
    ) -> Result<(), Error>;

    async fn update(
        &self,
        request: &UpdateRequest,
        dids: &[&Did],
    ) -> Result<(), Error>;

    async fn create_dm(
        &self,
        request: &CreateDMRequest,
        recipient: &Did
    ) -> Result<(), Error>;

    async fn read_dms(
        &self,
        request: &ReadDMRequest,
        recipient: &Did
    ) -> Result<Vec<DwnItem>, Error>;
}
clone_trait_object!(RequestHandler);

#[async_trait::async_trait]
pub trait Client: DynClone + std::fmt::Debug + Sync + Send {
    async fn create(
        &mut self,
        perms: &Permission,
        record: Record,
        dids: &[&Did]
    ) -> Result<Permission, Error>;

    async fn read(
        &mut self,
        perms: &Permission,
        dids: &[&Did],
        follow_perm: bool
    ) -> Result<Option<(Permission, Record)>, Error>;

    async fn update(
        &mut self,
        perms: &Permission,
        record: Record,
        dids: &[&Did]
    ) -> Result<Permission, Error>;

    async fn delete(
        &mut self,
        perms: &Permission,
        dids: &[&Did]
    ) -> Result<(), Error>;

    async fn create_child(
        &mut self,
        perms: &Permission,
        latest_delete: usize,
        permission: Permission,
        dids: &[&Did]
    ) -> Result<(Permission, usize), Error>;

    async fn read_child(
        &mut self,
        perms: &Permission,
        start: usize,
        end: Option<usize>,
        dids: &[&Did]
    ) -> Result<Vec<(Permission, Record)>, Error>;

    async fn delete_child(
        &mut self,
        perms: &Permission,
        index: usize,
        dids: &[&Did]
    ) -> Result<(), Error>;

    async fn configure_protocol(&mut self, protocol: Protocol) -> Result<(), Error>;
    async fn get_protocol(&mut self, protocol: &Hash) -> Result<Protocol, Error>;

    async fn create_did_msg(
        &self,
        sender: &DidKeyPair,
        recipient: &Did,
        permission: Permission,
    ) -> Result<(), Error>;

    async fn read_did_msgs(
        &self,
        recipient: (&Did, &SecretKey),
        timestamp: DateTime
    ) -> Result<Vec<(Did, Permission)>, Error>;
}
clone_trait_object!(Client);