Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Mint.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * Mint.hpp
4  *
5  */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131  **************************************************************/
132 
133 #ifndef OPENTXS_CASH_MINT_HPP
134 #define OPENTXS_CASH_MINT_HPP
135 
137 #include <map>
138 #include <cstdint>
139 #include <ctime>
140 
141 namespace opentxs
142 {
143 
144 class OTAccount;
145 class OTASCIIArmor;
146 class Token;
147 
148 typedef std::map<int64_t, OTASCIIArmor*> mapOfArmor;
149 
150 class Mint : public OTContract
151 {
152 private: // Private prevents erroneous use by other classes.
153  typedef OTContract ot_super;
154 
155 protected:
156  virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader*& xml);
157 
158  void InitMint();
159 
160  mapOfArmor m_mapPrivate; // An ENVELOPE. You need to pass the Pseudonym to
161  // every method that uses this. Private.
162  // Then you have to set it into an envelope and then open it using the Nym.
163  // Encrypted.
164  mapOfArmor m_mapPublic; // An Ascii-armored string of the mint Public
165  // information. Base64-encoded only.
166 
167  OTIdentifier m_ServerID; // The Server ID, (a hash of the server contract
168  // whose public key is m_keyPublic)
169  OTIdentifier m_ServerNymID; // The Nym ID of the Server, whose public key is
170  // m_keyPublic
171 
172  OTAsymmetricKey* m_pKeyPublic; // The server's public key.
173 
174  OTIdentifier m_AssetID; // Each Asset type has its own mint.
175 
176  int32_t m_nDenominationCount; // How many denominations of the currency are
177  // issued by this Mint?
178  // (Each requires its own key pair.)
179 
180  bool m_bSavePrivateKeys; // Determines whether it serializes private keys
181  // (no if false).
182  // Set this to 'true' before signing, if you want the private keys included.
183  // (The signing process will then automatically set it back to false again.)
184 
185  // --- MINT SERIES with EXPIRATION DATES ------------------
186  int32_t m_nSeries; // Each series of the mint has a valid from and to date.
187  // Series should rotate.
188  // (That is, the new one should be introduced halfway through the validity
189  // period
190  // of the current one, and so on...)
191 
192  time64_t m_VALID_FROM; // All tokens generated by this series will have the
193  // same From and To dates.
194  time64_t m_VALID_TO; // This way they cannot be tracked by expiration date.
195 
196  time64_t m_EXPIRATION; // The Mint itself expires before the tokens do. (As
197  // the new series rotates in...)
198 
199  OTIdentifier m_CashAccountID; // The Account ID for the cash reserve
200  // account. (Pointer below.)
201 
202  OTAccount* m_pReserveAcct; // When you withdraw cash, the Mint removes X
203  // dollars from your account, then
204  // it puts those X dollars into this reserve account, and then issues you
205  // the
206  // blinded tokens. When the tokens are deposited again, the money comes back
207  // out
208  // of the same reserve account and goes into the depositor's account. This
209  // way,
210  // all tokens will have 1-for-1 funds backing them, and any funds left over
211  // after
212  // the tokens expire, is the server operator's money to keep!
213 public:
214  inline int32_t GetSeries() const
215  {
216  return m_nSeries;
217  } // The series ID
218  inline time64_t GetValidFrom() const
219  {
220  return m_VALID_FROM;
221  } // The token "valid from" date for this series
222  inline time64_t GetValidTo() const
223  {
224  return m_VALID_TO;
225  } // The token "valid until" date for this series
226  inline time64_t GetExpiration() const
227  {
228  return m_EXPIRATION;
229  } // The date the mint expires (should be halfway
230  // between the above two dates.)
231  EXPORT bool Expired() const; // true or false. Expired?
232  // Valid range is GetValidFrom() through GetExpiration().
233  // Server-side only.
235  {
236  return m_pReserveAcct;
237  }
238 
239 public:
240  // Caller is responsible to delete.
241  //
242  EXPORT static Mint* MintFactory();
243  EXPORT static Mint* MintFactory(const OTString& strServerID,
244  const OTString& strAssetTypeID);
245  EXPORT static Mint* MintFactory(const OTString& strServerID,
246  const OTString& strServerNymID,
247  const OTString& strAssetTypeID);
248 
249 protected:
250  Mint();
251  EXPORT Mint(const OTString& strServerID, const OTString& strAssetTypeID);
252  EXPORT Mint(const OTString& strServerID, const OTString& strServerNymID,
253  const OTString& strAssetTypeID);
254 
255 public:
256  EXPORT virtual ~Mint();
257  virtual void Release();
258  void Release_Mint();
259  void ReleaseDenominations();
260  EXPORT bool LoadMint(const char* szAppend = nullptr);
261  EXPORT bool SaveMint(const char* szAppend = nullptr);
262 
263  virtual bool LoadContract();
264 
265  // Will save the private keys on next serialization (not just public keys)
266  // (SignContract sets m_bSavePrivateKeys back to false again.)
267  inline void SetSavePrivateKeys(bool bDoIt = true)
268  {
269  m_bSavePrivateKeys = bDoIt;
270  }
271 
272  // The denomination indicated here is the actual denomination...1, 5, 20,
273  // 50, 100, etc
274  bool GetPrivate(OTASCIIArmor& theArmor, int64_t lDenomination);
275  bool GetPublic(OTASCIIArmor& theArmor, int64_t lDenomination);
276 
277  int64_t GetDenomination(int32_t nIndex);
278  EXPORT int64_t GetLargestDenomination(int64_t lAmount);
279  virtual bool AddDenomination(OTPseudonym& theNotary, int64_t lDenomination,
280  int32_t nPrimeLength = 1024) = 0;
281 
282  inline int32_t GetDenominationCount() const
283  {
284  return m_nDenominationCount;
285  }
286 
287  virtual bool VerifyContractID() const;
288 
289  EXPORT bool VerifyMint(const OTPseudonym& theOperator);
290 
291  virtual void UpdateContents(); // Before transmission or serialization, this
292  // is where the token saves its contents
293 
294  inline void SetAssetID(const OTIdentifier& newID)
295  {
296  m_AssetID = newID;
297  }
298 
299  // Lucre step 1: generate new mint
300  EXPORT void GenerateNewMint(int32_t nSeries, time64_t VALID_FROM,
301  time64_t VALID_TO, time64_t MINT_EXPIRATION,
302  const OTIdentifier& theAssetID,
303  const OTIdentifier& theServerID,
304  OTPseudonym& theNotary, int64_t nDenom1 = 0,
305  int64_t nDenom2 = 0, int64_t nDenom3 = 0,
306  int64_t nDenom4 = 0, int64_t nDenom5 = 0,
307  int64_t nDenom6 = 0, int64_t nDenom7 = 0,
308  int64_t nDenom8 = 0, int64_t nDenom9 = 0,
309  int64_t nDenom10 = 0);
310 
311  // step 2: (coin request is in Token)
312 
313  // Lucre step 3: mint signs token
314  EXPORT virtual bool SignToken(OTPseudonym& theNotary, Token& theToken,
315  OTString& theOutput, int32_t nTokenIndex) = 0;
316 
317  // step 4: (unblind coin is in Token)
318 
319  // Lucre step 5: mint verifies token when it is redeemed by merchant.
320  EXPORT virtual bool VerifyToken(OTPseudonym& theNotary,
321  OTString& theCleartextToken,
322  int64_t lDenomination) = 0;
323 
324  virtual bool SaveContractWallet(std::ofstream& ofs) const;
325 };
326 
327 } // namespace opentxs
328 
329 #endif // OPENTXS_CASH_MINT_HPP
int32_t m_nSeries
Definition: Mint.hpp:186
void SetAssetID(const OTIdentifier &newID)
Definition: Mint.hpp:294
void ReleaseDenominations()
Definition: Mint.cpp:237
time64_t m_EXPIRATION
Definition: Mint.hpp:196
void SetSavePrivateKeys(bool bDoIt=true)
Definition: Mint.hpp:267
static EXPORT Mint * MintFactory()
Definition: Mint.cpp:154
OTAccount * m_pReserveAcct
Definition: Mint.hpp:202
bool GetPrivate(OTASCIIArmor &theArmor, int64_t lDenomination)
Definition: Mint.cpp:557
virtual bool AddDenomination(OTPseudonym &theNotary, int64_t lDenomination, int32_t nPrimeLength=1024)=0
EXPORT bool Expired() const
Definition: Mint.cpp:227
EXPORT void GenerateNewMint(int32_t nSeries, time64_t VALID_FROM, time64_t VALID_TO, time64_t MINT_EXPIRATION, const OTIdentifier &theAssetID, const OTIdentifier &theServerID, OTPseudonym &theNotary, int64_t nDenom1=0, int64_t nDenom2=0, int64_t nDenom3=0, int64_t nDenom4=0, int64_t nDenom5=0, int64_t nDenom6=0, int64_t nDenom7=0, int64_t nDenom8=0, int64_t nDenom9=0, int64_t nDenom10=0)
Definition: Mint.cpp:879
EXPORT bool VerifyMint(const OTPseudonym &theOperator)
Definition: Mint.cpp:508
virtual bool SaveContractWallet(std::ofstream &ofs) const
Definition: Mint.cpp:969
virtual void Release()
Definition: Mint.cpp:272
virtual EXPORT bool VerifyToken(OTPseudonym &theNotary, OTString &theCleartextToken, int64_t lDenomination)=0
void Release_Mint()
Definition: Mint.cpp:260
void InitMint()
Definition: Mint.cpp:296
virtual void UpdateContents()
Definition: Mint.cpp:635
OTIdentifier m_ServerNymID
Definition: Mint.hpp:169
int64_t time64_t
Definition: Common.hpp:209
EXPORT bool SaveMint(const char *szAppend=nullptr)
Definition: Mint.cpp:440
int32_t GetSeries() const
Definition: Mint.hpp:214
virtual EXPORT ~Mint()
Definition: Mint.cpp:282
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
Definition: Mint.cpp:704
EXPORT int64_t GetLargestDenomination(int64_t lAmount)
Definition: Mint.cpp:596
virtual EXPORT bool SignToken(OTPseudonym &theNotary, Token &theToken, OTString &theOutput, int32_t nTokenIndex)=0
bool GetPublic(OTASCIIArmor &theArmor, int64_t lDenomination)
Definition: Mint.cpp:574
time64_t GetValidTo() const
Definition: Mint.hpp:222
OTIdentifier m_ServerID
Definition: Mint.hpp:167
virtual bool LoadContract()
Definition: Mint.cpp:372
OTIdentifier m_CashAccountID
Definition: Mint.hpp:199
mapOfArmor m_mapPrivate
Definition: Mint.hpp:160
int32_t GetDenominationCount() const
Definition: Mint.hpp:282
OTIdentifier m_AssetID
Definition: Mint.hpp:174
time64_t GetValidFrom() const
Definition: Mint.hpp:218
OTAsymmetricKey * m_pKeyPublic
Definition: Mint.hpp:172
int32_t m_nDenominationCount
Definition: Mint.hpp:176
std::map< int64_t, OTASCIIArmor * > mapOfArmor
Definition: Mint.hpp:146
time64_t GetExpiration() const
Definition: Mint.hpp:226
time64_t m_VALID_FROM
Definition: Mint.hpp:192
bool m_bSavePrivateKeys
Definition: Mint.hpp:180
virtual bool VerifyContractID() const
Definition: Mint.cpp:535
EXPORT bool LoadMint(const char *szAppend=nullptr)
Definition: Mint.cpp:378
mapOfArmor m_mapPublic
Definition: Mint.hpp:164
OTAccount * GetCashReserveAccount() const
Definition: Mint.hpp:234
time64_t m_VALID_TO
Definition: Mint.hpp:194
int64_t GetDenomination(int32_t nIndex)
Definition: Mint.cpp:610