oc-issuer  0.0.2
model.hpp
1 #ifndef MODEL_HPP
2 #define MODEL_HPP
3 
4 #include <chrono>
5 #include <memory>
6 #include <optional>
7 #include <string>
8 
9 #include "crow/json.h"
10 
11 #include "tl/expected.hpp"
12 #include "big_int.hpp"
13 
14 struct PublicKey {
15  BigInt modulus; //: "daaa63ddda38c189b8c49020c8276adbe0a695685a...",
16  BigInt public_exponent;//: 65537,
17 
18  crow::json::wvalue to_json() const;
19 };
20 
21 struct WeightedUrl {
22  uint32_t weight;
23  std::string url;
24 
25  crow::json::wvalue to_json() const;
26 };
27 
34 struct CDD {
35 
36  std::string additional_info;
37  time_t cdd_expiry_date;
39  std::string cdd_location;
41  size_t cdd_serial;
45  std::string currency_name;
46  std::vector<unsigned>
49 
50  std::vector<WeightedUrl> info_service;
51  /* eCipherSuite*/
52  std::string issuer_cipher_suite;
56  std::vector<WeightedUrl> mint_service;
57  std::string protocol_version; // e.g. https://opencoin.org/1.0
58  std::vector<WeightedUrl> redeem_service;
59  std::vector<WeightedUrl> renew_service;
60 
61  crow::json::wvalue to_json() const;
62 };
63 
64 struct CDDC {
65  CDD cdd;
66  std::string signature;
67 
68  crow::json::wvalue to_json() const;
69 };
70 
71 struct MintKey {
72  unsigned int cdd_serial;
73  std::string coins_expiry_date; //": "2023-10-30T15:45:53.164685",
74  unsigned int denomination; //": 1,
75  BigInt id; // "1ceb977bb531c65f133ab8b0d60862b17369d96",
76  BigInt issuer_id; //": "23ed956e629ba35f0002eaf833ea436aea7db5c2",
77  PublicKey public_mint_key;
78 
79  std::string sign_coins_not_after;
80  std::string sign_coins_not_before;
81  // "type": "mint key"
82  crow::json::wvalue to_json() const;
83 };
84 
85 struct MintKeyCert {
86  MintKey mint_key;
87  std::string signature;
88 
89  crow::json::wvalue to_json() const;
90 };
91 
92 enum class eError {
93  JSON_PARSE_ERROR,
94  JSON_MISSING_KEY,
95  JSON_WRONG_REQUEST_TYPE,
96  JSON_WRONG_VALUE_TYPE,
97  JSON_ERROR,
98  NOT_IMPLEMENTED
99 };
100 
101 struct Response {
102  unsigned int message_reference;
103  unsigned int status_code;
104  std::string status_description;
105 
106  virtual crow::json::wvalue to_json() const;
107 };
108 
110  unsigned int message_reference;
112  static tl::expected<RequestCDDCSerial, eError>
113  from_string(const std::string &str);
114 };
115 
117  unsigned int cdd_serial;
118 
119  crow::json::wvalue to_json() const override;
120 };
121 
122 struct RequestCDDC {
123  unsigned int cdd_serial;
124  unsigned int message_reference;
126  static tl::expected<RequestCDDC, eError> from_string(const std::string &str);
127 };
128 
130  CDDC cddc;
131 
132  crow::json::wvalue to_json() const override;
133 };
134 
135 struct RequestMKCs {
136  std::vector<unsigned int> denominations;
137  unsigned int message_reference;
139  std::vector<BigInt> mint_key_ids;
140  // "type": "request mint key certificates"
141  static tl::expected<RequestMKCs, eError> from_string(const std::string &str);
142 };
143 
145  std::vector<MintKeyCert> keys;
146 
147  crow::json::wvalue to_json() const override;
148 };
149 
150 struct Blind {
151  BigInt blinded_payload_hash; //bigint
152  BigInt mint_key_id; //bigint
153  std::string reference;
154  crow::json::wvalue to_json() const;
155  static tl::expected<Blind, eError> from_json(const crow::json::rvalue &json);
156 };
157 
159  BigInt blind_signature;
160  std::string reference;
161  crow::json::wvalue to_json() const;
162 };
163 
164 struct RequestMint {
165  unsigned int message_reference;
168  std::vector<Blind> blinds;
169  // "type": "request mint"
170  static tl::expected<RequestMint, eError> from_string(const std::string &str);
171 };
172 
174  std::vector<BlindSignature> blind_signatures;
175 
176  crow::json::wvalue to_json() const override;
177 };
178 
179 struct Coin {
180  struct Payload {
181  std::string cdd_location;
182  unsigned int denomination;
183  BigInt issuer_id;
184  BigInt mint_key_id;
185  std::string protocol_version;
186  BigInt serial;
187 
188  crow::json::wvalue to_json() const;
189  static tl::expected<Payload,eError> from_json(const crow::json::rvalue& json);
190  };
191 
192  Payload payload;
193  std::string signature;
194 
195  crow::json::wvalue to_json() const;
196  static tl::expected<Coin, eError> from_json(const crow::json::rvalue &json);
197 };
198 
199 struct CoinStack {
200  std::vector<Coin> coins;
201  std::string subject;
202  // "type": "coinstack"
203  crow::json::wvalue to_json() const;
204 };
205 
206 struct RequestRenew {
207  std::vector<Blind> blinds;
208  std::vector<Coin> coins;
209  unsigned int message_reference;
212  // "type": "request renew"
213  static tl::expected<RequestRenew, eError> from_string(const std::string &str);
214 };
215 
217  crow::json::wvalue to_json() const override;
218 };
219 
221  unsigned int message_reference;
224  // "type": "request resume"
225  static tl::expected<RequestResume, eError>
226  from_string(const std::string &str);
227 };
228 
230  std::vector<Coin> coins;
231  unsigned int message_reference;
233  // "type": "request redeem"
234  static tl::expected<RequestRedeem, eError>
235  from_string(const std::string &str);
236 };
237 
239  crow::json::wvalue to_json() const override;
240 };
241 
242 class Model {
243 public:
244  virtual ~Model(){};
245 
252  virtual tl::expected<CDDC *, bool> getCDDC(unsigned int cdd_serial) = 0;
253 virtual tl::expected<CDDC *, bool> getCurrentCDDC() = 0;
259 
269  virtual const std::vector<MintKeyCert>
270  getMKCs(const std::vector<unsigned int> &denominations,
271  const std::vector<BigInt> &mint_key_ids) = 0;
272 
273 
282  virtual std::vector<BlindSignature>
283  mint(std::string const& transaction_reference,
284  const std::vector<Blind> &blinds) = 0;
285 
293  virtual bool redeem(const std::vector<Coin> &coins) = 0;
294 
303  static std::unique_ptr<Model> getModel(const std::string &backend_name);
304 
305 private:
306 };
307 
308 #endif // #ifndef MODEL_HPP
Definition: model.hpp:242
virtual std::vector< BlindSignature > mint(std::string const &transaction_reference, const std::vector< Blind > &blinds)=0
virtual bool redeem(const std::vector< Coin > &coins)=0
virtual tl::expected< CDDC *, bool > getCurrentCDDC()=0
static std::unique_ptr< Model > getModel(const std::string &backend_name)
Definition: model.cpp:517
virtual tl::expected< CDDC *, bool > getCDDC(unsigned int cdd_serial)=0
virtual const std::vector< MintKeyCert > getMKCs(const std::vector< unsigned int > &denominations, const std::vector< BigInt > &mint_key_ids)=0
Definition: big_int.hpp:9
Definition: model.hpp:158
Definition: model.hpp:150
Definition: model.hpp:64
currency description document
Definition: model.hpp:34
PublicKey issuer_public_master_key
Definition: model.hpp:55
std::vector< WeightedUrl > info_service
an identity for this currency
Definition: model.hpp:50
time_t cdd_signing_date
serial number of currency description document
Definition: model.hpp:42
size_t currency_divisor
Definition: model.hpp:44
std::string currency_name
divisor used for coins of this currency
Definition: model.hpp:45
BigInt id
the available denominations of this currency
Definition: model.hpp:48
std::vector< unsigned > denominations
name of the currency (e.g. OpenCent)
Definition: model.hpp:47
size_t cdd_serial
Definition: model.hpp:41
std::string cdd_location
Definition: model.hpp:39
std::vector< WeightedUrl > mint_service
the public key of this currency
Definition: model.hpp:56
Definition: model.hpp:199
Definition: model.hpp:180
Definition: model.hpp:179
Definition: model.hpp:85
Definition: model.hpp:71
Definition: model.hpp:14
Definition: model.hpp:109
static tl::expected< RequestCDDCSerial, eError > from_string(const std::string &str)
Definition: model.cpp:116
Definition: model.hpp:122
static tl::expected< RequestCDDC, eError > from_string(const std::string &str)
Definition: model.cpp:139
unsigned int message_reference
The version of the CDD. (Int)
Definition: model.hpp:124
Definition: model.hpp:135
std::vector< BigInt > mint_key_ids
Definition: model.hpp:139
Definition: model.hpp:164
BigInt transaction_reference
Definition: model.hpp:167
Definition: model.hpp:229
static tl::expected< RequestRedeem, eError > from_string(const std::string &str)
Definition: model.cpp:439
Definition: model.hpp:206
std::string transaction_reference
Definition: model.hpp:211
Definition: model.hpp:220
BigInt transaction_reference
Definition: model.hpp:223
Definition: model.hpp:116
Definition: model.hpp:129
Definition: model.hpp:216
Definition: model.hpp:144
Definition: model.hpp:173
Definition: model.hpp:238
Definition: model.hpp:101
Definition: model.hpp:21