forked from MarcKloter/blch-data-mgmt-layer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.java
137 lines (124 loc) · 6.27 KB
/
Core.java
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
package bdml.services.api;
import bdml.services.api.exceptions.AuthenticationException;
import bdml.services.api.exceptions.NotAuthorizedException;
import bdml.services.api.helper.DataListener;
import bdml.services.api.types.Account;
import bdml.services.api.types.Data;
import bdml.services.api.types.Identifier;
import java.util.Set;
public interface Core {
/**
* Creates a new account to store and receive data as, secured by the given password.
*
* @param password password for the new account
* @return 20 bytes identifier of the new account in hex string representation.
*/
String createAccount(String password);
/**
* Stores data in the connected blockchain.
* The {@link Account#getIdentifier()} of {@code account} is implicitly added to the {@code subjects}.
* The data is being encrypted using the public keys related to the {@code subjects}.
*
* @param data data to store
* @param attachments set of data identifiers to attach to the data
* @param account {@link Account} to interact as
* @param subjects set of 20 byte account identifiers to authorize.
* @return 32 bytes data identifier in hex string representation.
* @throws NotAuthorizedException if {@code attachments} cannot be accessed by {@code account}.
* @throws AuthenticationException if the {@link Account#getIdentifier()} and {@link Account#getPassword()}
* combination do not correspond to an existing account.
*/
String storeData(String data, Set<String> attachments, Account account, Set<String> subjects) throws AuthenticationException;
/**
* {@code attachments} defaults to {@code null}.
*
* @see Core#storeData(String, Set, Account, Set)
*/
String storeData(String data, Account account, Set<String> subjects) throws AuthenticationException;
/**
* {@code attachments} defaults to {@code null}.
* {@code subjects} defaults to {@code null}.
*
* @see Core#storeData(String, Set, Account, Set)
*/
String storeData(String data, Account account) throws AuthenticationException;
/**
* {@code data} is set to {@link Data#getData()}.
* {@code attachments} is set to {@link Data#getAttachments()}.
*
* @see Core#storeData(String, Set, Account, Set)
*/
String storeData(Data data, Account account, Set<String> subjects) throws AuthenticationException;
/**
* {@code data} is set to {@link Data#getData()}.
* {@code attachments} is set to {@link Data#getAttachments()}.
* {@code subjects} defaults to {@code null}.
*
* @see Core#storeData(String, Set, Account, Set)
*/
String storeData(Data data, Account account) throws AuthenticationException;
/**
* Lists the data identifiers of data that can directly be accessed by {@code account}.
* Direct accessible data are entries where the {@link Account#getIdentifier()} of {@code account} is either creator or recipient of.
* Attachments will not be included in the result.
*
* @param account {@link Account} to interact as
* @return Set of 32 byte data identifiers in hex string representation.
* @throws AuthenticationException if the {@link Account#getIdentifier()} and {@link Account#getPassword()}
* combination do not correspond to an existing account.
*/
Set<String> listData(Account account) throws AuthenticationException;
/**
* Lists data identifiers of data that can directly be accessed by the provided account since the last time this method was called.
* Direct accessible data are entries where the {@link Account#getIdentifier()} of {@code account} is either creator or recipient of.
* Attachments will not be included in the result.
*
* @param account {@link Account} to interact as
* @return Set of 32 byte data identifiers in hex string representation.
* @throws AuthenticationException if the {@link Account#getIdentifier()} and {@link Account#getPassword()}
* combination do not correspond to an existing account.
*/
Set<String> listDataChanges(Account account) throws AuthenticationException;
/**
* Lists the data identifiers of the referenced entry {@code id} and all attachments recursively.
*
* @param id 32 byte data identifier in hex string representation
* @param account {@link Account} to interact as
* @return {@link Identifier} object that recursively contains all linked attachments {@link Identifier#getAttachments()}.
* @throws AuthenticationException if the {@link Account#getIdentifier()} and {@link Account#getPassword()}
* combination do not correspond to an existing account.
*/
Identifier listAttachments(String id, Account account) throws AuthenticationException;
/**
* Returns data stored in the connected blockchain referenced by {@code id}.
*
* @param id 32 byte data identifier in hex string representation
* @param account {@link Account} to interact as
* @return {@link Data} object identified by {@code id} or {@code null}.
* @throws NotAuthorizedException if the data referenced by {@code id} cannot be accessed by {@code account}.
* @throws AuthenticationException if the {@link Account#getIdentifier()} and {@link Account#getPassword()}
* combination do not correspond to an existing account.
*/
Data getData(String id, Account account) throws AuthenticationException;
/**
* Registers the given {@link DataListener} for {@code account}.
* The {@link DataListener#update(String)} method will be called whenever the connected blockchain client received
* data where {@code account} was a recipient of.
*
* @param account {@link Account} to interact as
* @param dataListener {@link DataListener} object to subscribe
* @return 8 bytes subscription handle in hex string representation.
* @throws AuthenticationException if the {@link Account#getIdentifier()} and {@link Account#getPassword()}
* combination do not correspond to an existing account.
*/
String registerDataListener(Account account, DataListener dataListener) throws AuthenticationException;
/**
* Unregisters the previously registered {@link DataListener} of {@code account} under {@code handle}.
*
* @param account {@link Account} to interact as
* @param handle 8 bytes subscription handle in hex string representation
* @throws AuthenticationException if the {@link Account#getIdentifier()} and {@link Account#getPassword()}
* combination do not correspond to an existing account.
*/
void unregisterDataListener(Account account, String handle) throws AuthenticationException;
}