-
Notifications
You must be signed in to change notification settings - Fork 35
/
SGXWalletServer.hpp
236 lines (159 loc) · 9.14 KB
/
SGXWalletServer.hpp
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
Copyright (C) 2019-Present SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file SGXWalletServer.hpp
@author Stan Kladko
@date 2019
*/
#ifndef SGXWALLET_SGXWALLETSERVER_HPP
#define SGXWALLET_SGXWALLETSERVER_HPP
#include "memory"
#include "mutex"
#include <jsonrpccpp/server/connectors/httpserver.h>
#include "abstractstubserver.h"
using namespace jsonrpc;
using namespace std;
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
class SGXWalletServer : public AbstractStubServer {
static shared_ptr<SGXWalletServer> server;
static shared_ptr<HttpServer> httpServer;
static map<string, string> blsRequests;
static recursive_mutex blsRequestsLock;
static map<string, string> ecdsaRequests;
static recursive_mutex ecdsaRequestsLock;
static void checkForDuplicate(map<string, string> &_map, recursive_mutex &_m,
const string &_key, const string &_value);
public:
static bool verifyCert(string &_certFileName);
static const char *getVersion() { return TOSTRING(SGXWALLET_VERSION); }
SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type);
virtual Json::Value importBLSKeyShare(const string &_keyShare,
const string &_keyShareName);
virtual Json::Value blsSignMessageHash(const string &_keyShareName,
const string &_messageHash, int _t,
int _n);
virtual Json::Value importECDSAKey(const std::string &keyShare,
const std::string &keyShareName);
virtual Json::Value generateECDSAKey();
virtual Json::Value ecdsaSignMessageHash(int _base,
const string &_keyShareName,
const string &_messageHash);
virtual Json::Value getPublicECDSAKey(const string &_keyName);
virtual Json::Value generateDKGPoly(const string &_polyName, int _t);
virtual Json::Value getVerificationVector(const string &_polynomeName,
int _t);
virtual Json::Value getSecretShare(const string &_polyName,
const Json::Value &_publicKeys, int t,
int n);
virtual Json::Value dkgVerification(const string &_publicShares,
const string ðKeyName,
const string &SecretShare, int t, int n,
int index);
virtual Json::Value createBLSPrivateKey(const string &blsKeyName,
const string ðKeyName,
const string &polyName,
const string &SecretShare, int t,
int n);
virtual Json::Value generateBLSPrivateKey(const string &blsKeyName);
virtual Json::Value getBLSPublicKeyShare(const string &blsKeyName);
virtual Json::Value calculateAllBLSPublicKeys(const Json::Value &publicShares,
int t, int n);
virtual Json::Value complaintResponse(const string &polyName, int t, int n,
int ind);
virtual Json::Value multG2(const string &x);
virtual Json::Value isPolyExists(const string &polyName);
virtual Json::Value getServerStatus();
virtual Json::Value getServerVersion();
virtual Json::Value deleteBlsKey(const std::string &name);
virtual Json::Value getSecretShareV2(const string &_polyName,
const Json::Value &_publicKeys, int t,
int n);
virtual Json::Value dkgVerificationV2(const string &_publicShares,
const string ðKeyName,
const string &SecretShare, int t, int n,
int index);
virtual Json::Value createBLSPrivateKeyV2(const std::string &blsKeyName,
const std::string ðKeyName,
const std::string &polyName,
const std::string &SecretShare,
int t, int n);
virtual Json::Value
getDecryptionShares(const std::string &blsKeyName,
const Json::Value &publicDecryptionValues);
virtual Json::Value popProve(const std::string &blsKeyName);
static shared_ptr<string> readFromDb(const string &name,
const string &prefix = "");
static shared_ptr<string> checkDataFromDb(const string &name,
const string &prefix = "");
static void writeDataToDB(const string &Name, const string &value);
static void writeKeyShare(const string &_keyShareName, const string &_value);
static Json::Value importBLSKeyShareImpl(const string &_keyShare,
const string &_keyShareName);
static Json::Value blsSignMessageHashImpl(const string &_keyShareName,
const string &_messageHash, int t,
int n);
static Json::Value importECDSAKeyImpl(const string &_keyShare,
const string &_keyShareName);
static Json::Value generateECDSAKeyImpl();
static Json::Value ecdsaSignMessageHashImpl(int _base, const string &keyName,
const string &_messageHash);
static Json::Value getPublicECDSAKeyImpl(const string &_keyName);
static Json::Value generateDKGPolyImpl(const string &_polyName, int _t);
static Json::Value getVerificationVectorImpl(const string &_polyName, int _t);
static Json::Value getSecretShareImpl(const string &_polyName,
const Json::Value &_pubKeys, int _t,
int _n);
static Json::Value dkgVerificationImpl(const string &_publicShares,
const string &_ethKeyName,
const string &_secretShare, int _t,
int _n, int _index);
static Json::Value createBLSPrivateKeyImpl(const string &_blsKeyName,
const string &_ethKeyName,
const string &_polyName,
const string &_secretShare, int _t,
int _n);
static Json::Value getBLSPublicKeyShareImpl(const string &_blsKeyName);
static Json::Value
calculateAllBLSPublicKeysImpl(const Json::Value &publicShares, int t, int n);
static Json::Value complaintResponseImpl(const string &_polyName, int t,
int n, int _ind);
static Json::Value multG2Impl(const string &_x);
static Json::Value isPolyExistsImpl(const string &_polyName);
static Json::Value getServerStatusImpl();
static Json::Value getServerVersionImpl();
static Json::Value deleteBlsKeyImpl(const std::string &name);
static Json::Value getSecretShareV2Impl(const string &_polyName,
const Json::Value &_pubKeys, int _t,
int _n);
static Json::Value dkgVerificationV2Impl(const string &_publicShares,
const string &_ethKeyName,
const string &_secretShare, int _t,
int _n, int _index);
static Json::Value createBLSPrivateKeyV2Impl(const std::string &blsKeyName,
const std::string ðKeyName,
const std::string &polyName,
const std::string &SecretShare,
int t, int n);
static Json::Value generateBLSPrivateKeyImpl(const string &blsKeyName);
static Json::Value
getDecryptionSharesImpl(const std::string &KeyName,
const Json::Value &publicDecryptionValues);
static Json::Value popProveImpl(const std::string &blsKeyName);
static void printDB();
static void initHttpServer();
static void initHttpsServer(bool _checkCerts);
static int exitServer();
static void createCertsIfNeeded();
};
#endif // SGXWALLET_SGXWALLETSERVER_HPP