Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTWallet.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTWallet.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_CLIENT_OTWALLET_HPP
134 #define OPENTXS_CLIENT_OTWALLET_HPP
135 
136 #include "opentxs/core/OTString.hpp"
137 
138 #include <map>
139 #include <memory>
140 #include <set>
141 #include <string>
142 
143 namespace opentxs
144 {
145 
146 class OTAccount;
147 class OTAssetContract;
148 class OTContract;
149 class OTIdentifier;
150 class OTMessage;
151 class OTPassword;
152 class OTPasswordData;
153 class OTPseudonym;
154 class Purse;
155 class OTServerContract;
156 class OTString;
158 
159 typedef std::map<std::string, OTAccount*> mapOfAccounts;
160 typedef std::map<std::string, OTAssetContract*> mapOfContracts;
161 typedef std::map<std::string, OTPseudonym*> mapOfNyms;
162 typedef std::map<std::string, OTServerContract*> mapOfServers;
163 typedef std::map<std::string, std::shared_ptr<OTSymmetricKey>>
165 typedef std::set<OTIdentifier> setOfIdentifiers;
166 
167 class OTWallet
168 {
169 public:
170  EXPORT OTWallet();
171  ~OTWallet();
172 
173  EXPORT bool IsNymOnCachedKey(const OTIdentifier& needle) const; // needle
174  // and
175  // haystack.
176  EXPORT bool ConvertNymToCachedKey(OTPseudonym& theNym);
177 
178  EXPORT OTPseudonym* GetOrLoadNym(const OTIdentifier& NYM_ID,
179  bool bChecking = false,
180  const char* szFuncName = nullptr,
181  const OTPasswordData* pPWData = nullptr);
182  EXPORT OTPseudonym* GetOrLoadPublicNym(const OTIdentifier& NYM_ID,
183  const char* szFuncName = nullptr);
185  const OTIdentifier& NYM_ID, bool bChecking = false,
186  const char* szFuncName = nullptr,
187  const OTPasswordData* pPWData = nullptr,
188  const OTPassword* pImportPassword = nullptr);
189 
190  EXPORT OTAccount* LoadAccount(const OTPseudonym& theNym,
191  const OTIdentifier& ACCT_ID,
192  const OTIdentifier& SERVER_ID,
193  const char* szFuncName = nullptr);
194 
195  EXPORT OTAccount* GetOrLoadAccount(const OTPseudonym& theNym,
196  const OTIdentifier& ACCT_ID,
197  const OTIdentifier& SERVER_ID,
198  const char* szFuncName = nullptr);
199  // Used by high-level wrapper.
200 
201  EXPORT int32_t GetNymCount();
202  EXPORT int32_t GetServerCount();
203  EXPORT int32_t GetAssetTypeCount();
204  EXPORT int32_t GetAccountCount();
205 
206  EXPORT bool GetNym(int32_t iIndex, OTIdentifier& NYM_ID,
207  OTString& NYM_NAME);
208  EXPORT bool GetServer(int32_t iIndex, OTIdentifier& THE_ID,
209  OTString& THE_NAME);
210  EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier& THE_ID,
211  OTString& THE_NAME);
212  EXPORT bool GetAccount(int32_t iIndex, OTIdentifier& THE_ID,
213  OTString& THE_NAME);
214 
215  EXPORT void DisplayStatistics(OTString& strOutput);
216 
217  EXPORT OTPseudonym* GetNymByID(const OTIdentifier& NYM_ID);
219  std::string PARTIAL_ID); // wallet name for nym also accepted.
220 
221  EXPORT void AddServerContract(const OTServerContract& theContract);
222  EXPORT OTServerContract* GetServerContract(const OTIdentifier& SERVER_ID);
224  std::string PARTIAL_ID); // wallet name for server also accepted.
225 
226  EXPORT void AddNym(const OTPseudonym& theNym);
227  EXPORT void AddAccount(const OTAccount& theAcct);
228 
229  EXPORT void AddAssetContract(const OTAssetContract& theContract);
230  EXPORT OTAssetContract* GetAssetContract(const OTIdentifier& theContractID);
232  std::string PARTIAL_ID); // wallet name for asset also accepted.
233  bool VerifyAssetAccount(const OTPseudonym& theNym, OTAccount& theAcct,
234  const OTIdentifier& SERVER_ID,
235  const OTString& strAcctID,
236  const char* szFuncName = nullptr);
237  EXPORT OTAccount* GetAccount(const OTIdentifier& theAccountID);
239  std::string PARTIAL_ID); // wallet name for account also accepted.
240  EXPORT OTAccount* GetIssuerAccount(const OTIdentifier& theAssetTypeID);
241  // While waiting on server response to a withdrawal, we keep the private
242  // coin
243  // data here so we can unblind the response.
244  // This information is so important (as important as the digital cash token
245  // itself, until the unblinding is done) that we need to save the file right
246  // away.
247  EXPORT void AddPendingWithdrawal(const Purse& thePurse);
249  inline Purse* GetPendingWithdrawal() const
250  {
251  return m_pWithdrawalPurse;
252  }
253  EXPORT bool LoadWallet(const char* szFilename = nullptr);
254  EXPORT bool SaveWallet(const char* szFilename = nullptr);
255  bool SaveContract(OTString& strContract); // For saving the wallet to a
256  // string.
257 
258  EXPORT bool SignContractWithFirstNymOnList(
259  OTContract& theContract); // todo : follow-up on this and see what it's
260  // about.
261  // When the wallet's master passphrase changes, the extra symmetric keys
262  // need to be updated to reflect that.
263  EXPORT bool ChangePassphrasesOnExtraKeys(const OTPassword& oldPassphrase,
264  const OTPassword& newPassphrase);
265  // These allow the client application to encrypt its own sensitive data.
266  // For example, let's say the client application is storing your Bitmessage
267  // username and password in its database. It can't store those in the clear,
268  // so it encrypts the DB's sensitive data using Encrypt_ByKeyID("sql_db")
269  // and accesses the data using Decrypt_ByKeyID("sql_db").
270  // The string acts as a key to look up a symmetric key which is normally
271  // stored in encrypted form, using the wallet's master key. Whenever the
272  // wallet's master key is available (until it times out) the client app will
273  // thus be able to use these symmetric keys without having to ask the user
274  // to type a passphrase.
275  // (We do this for Nyms already. These methods basically give us the same
276  // functionality for symmetric keys as we already had for the wallet's
277  // Nyms.)
278  //
279  EXPORT bool Encrypt_ByKeyID(const std::string& key_id,
280  const OTString& strPlaintext,
281  OTString& strOutput,
282  const OTString* pstrDisplay = nullptr,
283  bool bBookends = true);
284 
285  EXPORT bool Decrypt_ByKeyID(const std::string& key_id,
286  const OTString& strCiphertext,
287  OTString& strOutput,
288  const OTString* pstrDisplay = nullptr);
289  EXPORT std::shared_ptr<OTSymmetricKey> getOrCreateExtraKey(
290  const std::string& str_KeyID,
291  const std::string* pReason = nullptr); // Use this one.
292  EXPORT std::shared_ptr<OTSymmetricKey> getExtraKey(
293  const std::string& str_id); // Low level.
294  EXPORT bool addExtraKey(const std::string& str_id,
295  std::shared_ptr<OTSymmetricKey> pKey); // Low level.
296  // These functions are low-level. They don't check for dependent data before
297  // deleting,
298  // and they don't save the wallet after they do.
299  //
300  // (You have to handle that at a higher level.)
301 
302  EXPORT bool RemoveAssetContract(const OTIdentifier& theTargetID);
303  EXPORT bool RemoveServerContract(const OTIdentifier& theTargetID);
304 
305  // higher level version of these two will require a server message,
306  // in addition to removing from wallet. (To delete them on server side.)
307  //
308  EXPORT bool RemoveAccount(const OTIdentifier& theTargetID);
309  EXPORT bool RemoveNym(const OTIdentifier& theTargetID);
310 
311 private:
312  void Release();
313 
314 private:
315  mapOfNyms m_mapNyms;
316  mapOfContracts m_mapContracts;
317  mapOfServers m_mapServers;
318  mapOfAccounts m_mapAccounts;
319 
320  setOfIdentifiers m_setNymsOnCachedKey; // All the Nyms that use the Master
321  // key are listed here (makes it easy
322  // to see which ones are converted
323  // already.)
324 
325  OTString m_strName;
326  OTString m_strVersion;
327 
328  // Let's say you have some private data that you want to store safely.
329  // For example, your Bitmessage user/pass. Perhaps you want to throw
330  // your Bitmessage connect string into your client-side sql*lite DB.
331  // But you can't leave the password there in plaintext form! So instead,
332  // you create a symmetric key to encrypt it with (stored here on this
333  // map.)
334  // Therefore your data, such as your Bitmessage password, is stored in
335  // encrypted form to a symmetric key stored in the wallet. Then that
336  // symmetric key is encrypted to the master password in the wallet.
337  // If the master password ever changes, the symmetric keys on this map
338  // can be re-encrypted to the new master password. Meanwhile the Bitmessage
339  // connection string ITSELF, in your sql*lite DB, doesn't need to be re-
340  // encrypted at all, since it's encrypted to the symmetric key, which,
341  // though itself may be re-encrypted to another master password, the actual
342  // contents of the symmetric key haven't changed.
343  //
344  // (This way you can change the wallet master passphrase, WITHOUT having
345  // to go through your sql*lite database re-encrypting all the crap in there
346  // that you might have encrypted previously before you changed your wallet
347  // password.)
348  //
349  // That's why these are "extra" keys -- because you can create as many of
350  // them as you want, and just use them for encrypting various data on the
351  // client side.
352  //
353  mapOfSymmetricKeys m_mapExtraKeys;
354 
355  // While waiting on server response to withdrawal,
356  // store private coin data here for unblinding
357  Purse* m_pWithdrawalPurse;
358 
359 public:
362 };
363 
364 } // namespace opentxs
365 
366 #endif // OPENTXS_CLIENT_OTWALLET_HPP
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME)
Definition: OTWallet.cpp:352
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTWallet.cpp:956
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr)
Definition: OTWallet.cpp:822
EXPORT int32_t GetAccountCount()
Definition: OTWallet.cpp:346
EXPORT bool IsNymOnCachedKey(const OTIdentifier &needle) const
Definition: OTWallet.cpp:2147
EXPORT bool Encrypt_ByKeyID(const std::string &key_id, const OTString &strPlaintext, OTString &strOutput, const OTString *pstrDisplay=nullptr, bool bBookends=true)
Definition: OTWallet.cpp:1482
EXPORT bool ChangePassphrasesOnExtraKeys(const OTPassword &oldPassphrase, const OTPassword &newPassphrase)
Definition: OTWallet.cpp:1427
EXPORT std::shared_ptr< OTSymmetricKey > getOrCreateExtraKey(const std::string &str_KeyID, const std::string *pReason=nullptr)
Definition: OTWallet.cpp:1368
EXPORT OTAccount * GetAccountPartialMatch(std::string PARTIAL_ID)
Definition: OTWallet.cpp:613
std::map< std::string, std::shared_ptr< OTSymmetricKey > > mapOfSymmetricKeys
Definition: OTWallet.hpp:164
EXPORT OTAssetContract * GetAssetContract(const OTIdentifier &theContractID)
Definition: OTWallet.cpp:1203
OTString m_strDataFolder
Definition: OTWallet.hpp:361
EXPORT void AddServerContract(const OTServerContract &theContract)
Definition: OTWallet.cpp:725
Purse * GetPendingWithdrawal() const
Definition: OTWallet.hpp:249
EXPORT void AddPendingWithdrawal(const Purse &thePurse)
Definition: OTWallet.cpp:232
bool VerifyAssetAccount(const OTPseudonym &theNym, OTAccount &theAcct, const OTIdentifier &SERVER_ID, const OTString &strAcctID, const char *szFuncName=nullptr)
Definition: OTWallet.cpp:777
EXPORT OTPseudonym * GetNymByIDPartialMatch(std::string PARTIAL_ID)
Definition: OTWallet.cpp:291
EXPORT void AddAssetContract(const OTAssetContract &theContract)
Definition: OTWallet.cpp:752
std::map< std::string, OTAssetContract * > mapOfContracts
Definition: OTWallet.hpp:160
std::map< std::string, OTPseudonym * > mapOfNyms
Definition: OTWallet.hpp:161
EXPORT OTPseudonym * GetOrLoadNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr)
Definition: OTWallet.cpp:1073
EXPORT void DisplayStatistics(OTString &strOutput)
Definition: OTWallet.cpp:457
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME)
Definition: OTWallet.cpp:431
EXPORT OTAccount * GetIssuerAccount(const OTIdentifier &theAssetTypeID)
Definition: OTWallet.cpp:649
EXPORT int32_t GetAssetTypeCount()
Definition: OTWallet.cpp:341
EXPORT bool SignContractWithFirstNymOnList(OTContract &theContract)
Definition: OTWallet.cpp:252
std::map< std::string, OTServerContract * > mapOfServers
Definition: OTWallet.hpp:162
EXPORT bool RemoveAssetContract(const OTIdentifier &theTargetID)
Definition: OTWallet.cpp:1131
EXPORT bool RemoveNym(const OTIdentifier &theTargetID)
Definition: OTWallet.cpp:1101
EXPORT std::shared_ptr< OTSymmetricKey > getExtraKey(const std::string &str_id)
Definition: OTWallet.cpp:1530
void RemovePendingWithdrawal()
Definition: OTWallet.cpp:245
EXPORT bool addExtraKey(const std::string &str_id, std::shared_ptr< OTSymmetricKey > pKey)
Definition: OTWallet.cpp:1546
EXPORT bool ConvertNymToCachedKey(OTPseudonym &theNym)
Definition: OTWallet.cpp:2066
EXPORT int32_t GetServerCount()
Definition: OTWallet.cpp:336
EXPORT OTPseudonym * GetNymByID(const OTIdentifier &NYM_ID)
Definition: OTWallet.cpp:275
EXPORT bool LoadWallet(const char *szFilename=nullptr)
Definition: OTWallet.cpp:1617
EXPORT bool RemoveAccount(const OTIdentifier &theTargetID)
Definition: OTWallet.cpp:1182
EXPORT bool Decrypt_ByKeyID(const std::string &key_id, const OTString &strCiphertext, OTString &strOutput, const OTString *pstrDisplay=nullptr)
Definition: OTWallet.cpp:1508
EXPORT OTAssetContract * GetAssetContractPartialMatch(std::string PARTIAL_ID)
Definition: OTWallet.cpp:1218
std::map< std::string, OTAccount * > mapOfAccounts
Definition: OTWallet.hpp:157
EXPORT OTAccount * LoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr)
Definition: OTWallet.cpp:863
EXPORT bool SaveWallet(const char *szFilename=nullptr)
Definition: OTWallet.cpp:1566
OTString m_strFilename
Definition: OTWallet.hpp:360
EXPORT OTWallet()
Definition: OTWallet.cpp:157
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME)
Definition: OTWallet.cpp:377
EXPORT OTServerContract * GetServerContractPartialMatch(std::string PARTIAL_ID)
Definition: OTWallet.cpp:685
std::set< OTIdentifier > setOfIdentifiers
Definition: OTWallet.hpp:165
EXPORT OTServerContract * GetServerContract(const OTIdentifier &SERVER_ID)
Definition: OTWallet.cpp:667
EXPORT int32_t GetNymCount()
Definition: OTWallet.cpp:331
EXPORT void AddNym(const OTPseudonym &theNym)
Definition: OTWallet.cpp:523
bool SaveContract(OTString &strContract)
Definition: OTWallet.cpp:1252
EXPORT void AddAccount(const OTAccount &theAcct)
Definition: OTWallet.cpp:561
EXPORT OTPseudonym * GetOrLoadPublicNym(const OTIdentifier &NYM_ID, const char *szFuncName=nullptr)
Definition: OTWallet.cpp:910
EXPORT bool RemoveServerContract(const OTIdentifier &theTargetID)
Definition: OTWallet.cpp:1155
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME)
Definition: OTWallet.cpp:404