-
Notifications
You must be signed in to change notification settings - Fork 100
/
OTAPI.hpp
3956 lines (3505 loc) · 178 KB
/
OTAPI.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************
*
* OTAPI.hpp
*
*/
/************************************************************
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
* OPEN TRANSACTIONS
*
* Financial Cryptography and Digital Cash
* Library, Protocol, API, Server, CLI, GUI
*
* -- Anonymous Numbered Accounts.
* -- Untraceable Digital Cash.
* -- Triple-Signed Receipts.
* -- Cheques, Vouchers, Transfers, Inboxes.
* -- Basket Currencies, Markets, Payment Plans.
* -- Signed, XML, Ricardian-style Contracts.
* -- Scripted smart contracts.
*
* Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
*
* EMAIL:
* FellowTraveler@rayservers.net
*
* BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
*
* KEY FINGERPRINT (PGP Key in license file):
* 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
*
* OFFICIAL PROJECT WIKI(s):
* https://github.com/FellowTraveler/Moneychanger
* https://github.com/FellowTraveler/Open-Transactions/wiki
*
* WEBSITE:
* http://www.OpenTransactions.org/
*
* Components and licensing:
* -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
* -- otlib.........A class library.......LICENSE:...LAGPLv3
* -- otapi.........A client API..........LICENSE:...LAGPLv3
* -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
* -- otserver......Server Application....LICENSE:....AGPLv3
* Github.com/FellowTraveler/Open-Transactions/wiki/Components
*
* All of the above OT components were designed and written by
* Fellow Traveler, with the exception of Moneychanger, which
* was contracted out to Vicky C (bitcointrader4@gmail.com).
* The open-source community has since actively contributed.
*
* -----------------------------------------------------
*
* LICENSE:
* This program 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.
*
* ADDITIONAL PERMISSION under the GNU Affero GPL version 3
* section 7: (This paragraph applies only to the LAGPLv3
* components listed above.) If you modify this Program, or
* any covered work, by linking or combining it with other
* code, such other code is not for that reason alone subject
* to any of the requirements of the GNU Affero GPL version 3.
* (==> This means if you are only using the OT API, then you
* don't have to open-source your code--only your changes to
* Open-Transactions itself must be open source. Similar to
* LGPLv3, except it applies to software-as-a-service, not
* just to distributing binaries.)
*
* Extra WAIVER for OpenSSL, Lucre, and all other libraries
* used by Open Transactions: This program is released under
* the AGPL with the additional exemption that compiling,
* linking, and/or using OpenSSL is allowed. The same is true
* for any other open source libraries included in this
* project: complete waiver from the AGPL is hereby granted to
* compile, link, and/or use them with Open-Transactions,
* according to their own terms, as long as the rest of the
* Open-Transactions terms remain respected, with regard to
* the Open-Transactions code itself.
*
* Lucre License:
* This code is also "dual-license", meaning that Ben Lau-
* rie's license must also be included and respected, since
* the code for Lucre is also included with Open Transactions.
* See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
* The Laurie requirements are light, but if there is any
* problem with his license, simply remove the Lucre code.
* Although there are no other blind token algorithms in Open
* Transactions (yet. credlib is coming), the other functions
* will continue to operate.
* See Lucre on Github: https://github.com/benlaurie/lucre
* -----------------------------------------------------
* You should have received a copy of the GNU Affero General
* Public License along with this program. If not, see:
* http://www.gnu.org/licenses/
*
* If you would like to use this software outside of the free
* software license, please contact FellowTraveler.
* (Unfortunately many will run anonymously and untraceably,
* so who could really stop them?)
*
* DISCLAIMER:
* This program 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.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
kamH0Y/n11lCvo1oQxM+
=uSzz
-----END PGP SIGNATURE-----
**************************************************************/
#ifndef OPENTXS_CLIENT_OTAPI_HPP
#define OPENTXS_CLIENT_OTAPI_HPP
#include <opentxs/core/util/Common.hpp>
namespace opentxs
{
class OT_API;
class OTAPI_Exec;
class OTAPI_Wrap
{
public:
EXPORT static OTAPI_Exec* SetExecutor(OTAPI_Exec* exec);
EXPORT static OTAPI_Exec* Exec();
EXPORT static OTAPI_Exec* It();
EXPORT static OT_API* OTAPI();
EXPORT static int64_t StringToLong(const std::string& strNumber);
EXPORT static std::string LongToString(const int64_t& lNumber);
EXPORT static uint64_t StringToUlong(const std::string& strNumber);
EXPORT static std::string UlongToString(const uint64_t& lNumber);
/**
INITIALIZE the OTAPI library
Call this once per run of the application.
*/
EXPORT static bool AppInit(); // Call this ONLY ONCE, when your App first
// starts up.
EXPORT static bool AppCleanup(); // Call this ONLY ONCE, when your App is
// shutting down.
// SetAppBinaryFolder
// OPTIONAL. Used in Android and Qt.
//
// Certain platforms use this to override the Prefix folder.
// Basically /usr/local is the prefix folder by default, meaning
// /usr/local/lib/opentxs will be the location of the scripts. But
// if you override AppBinary folder to, say, "res/raw"
// (Android does something like that) then even though the prefix remains
// as /usr/local, the scripts folder will be res/raw
//
EXPORT static void SetAppBinaryFolder(const std::string& strFolder);
// SetHomeFolder
// OPTIONAL. Used in Android.
//
// The AppDataFolder, such as /Users/au/.ot, is constructed from the home
// folder, such as /Users/au.
//
// Normally the home folder is auto-detected, but certain platforms, such as
// Android, require us to explicitly set this folder from the Java code.
// Then
// the AppDataFolder is constructed from it. (It's the only way it can be
// done.)
//
// In Android, you would SetAppBinaryFolder to the path to
// "/data/app/packagename/res/raw",
// and you would SetHomeFolder to "/data/data/[app package]/files/"
//
EXPORT static void SetHomeFolder(const std::string& strFolder);
// Then:
/**
INITIALIZE an OTAPI context.
Call this once per context.
If the configuration value doesn't exist, it will be created.
Something like this: bool bInit = Init();
If this function fails, you can call it multiple times until it succeeds.
EXPORT static bool Cleanup(); // Call this before you delete OTAPI
*/
/**
SET WALLET (optional)
This command will set the wallet filename in the configuration.
Use this command to change what wallet will be loaded with the
"LOAD WALLET" command.
e.g. SetWallet("wallet2.xml");
*/
EXPORT static bool SetWallet(const std::string& strWalletFilename);
/**
WALLET EXISTS
Just Checks if the m_pWallet pointer is not null.
WalletExists();
*/
EXPORT static bool WalletExists();
/**
LOAD WALLET
Next you'll want to load your wallet up. It needs to be in the data_folder.
The filename is set in the configuration. Use "SET WALLET FILENAME" to
change it.
The Default Filename is "wallet.xml"
LoadWallet();
*/
EXPORT static bool LoadWallet();
/**
SWITCH WALLET (experimental)
Experimental.
Set the new wallet with the "SET WALLET FILENAME" function.
Then call this function to switch to the new wallet.
*/
EXPORT static bool SwitchWallet();
/** Output to the screen (stderr.)
(This is so stdout can be left clean for the ACTUAL output.)
Log level is 0 (least verbose) to 5 (most verbose.)
*/
EXPORT static void Output(const int32_t& nLogLevel,
const std::string& strOutput);
/** TIME (in seconds)
This will return the current time in seconds, as a string.
Returns nullptr if failure.
Todo: consider making this available on the server side as well,
so the smart contracts can see what time it is.
*/
EXPORT static time64_t GetTime();
/**
These 2 functions aren't in the OT_API proper, but are only available inside
the OTScripts on the client side. (They're not available in server-side
scripts, and they're not available in, for example, the OTAPI Java
programmable
interface. You would use Java functions at that point.)
Shown here only for reference.
*/
// const std::string& OT_CLI_ReadLine(); // Reads from cin until
// Newline.
// const std::string& OT_CLI_ReadUntilEOF(); // Reads from cin until
// EOF.
// OTNumList is a class that encapsulates working with a comma-separated
// list
// of int64_t integers, stored in a std::set and easily serializable in/out
// of a string.
// (It's useful.)
//
EXPORT static std::string NumList_Add(const std::string& strNumList,
const std::string& strNumbers);
EXPORT static std::string NumList_Remove(const std::string& strNumList,
const std::string& strNumbers);
EXPORT static bool NumList_VerifyQuery(const std::string& strNumList,
const std::string& strNumbers);
EXPORT static bool NumList_VerifyAll(const std::string& strNumList,
const std::string& strNumbers);
EXPORT static int32_t NumList_Count(const std::string& strNumList);
/** OT-encode a plainext string.
This will pack, compress, and base64-encode a plain string.
Returns the base64-encoded string, or nullptr.
internally:
OTString strPlain(strPlaintext);
OTASCIIArmor ascEncoded(thePlaintext); // ascEncoded now contains the
OT-encoded string.
return ascEncoded.Get(); // We return it.
*/
EXPORT static std::string Encode(const std::string& strPlaintext,
const bool& bLineBreaks);
/** Decode an OT-encoded string (back to plainext.)
EXPORT static std::string Decode(const std::string& strEncoded);
This will base64-decode, uncompress, and unpack an OT-encoded string.
Returns the plainext string, or nullptr.
internally:
OTASCIIArmor ascEncoded(strEncoded);
OTString strPlain(ascEncoded); // strPlain now contains the decoded
plainext string.
return strPlain.Get(); // We return it.
*/
EXPORT static std::string Decode(const std::string& strEncoded,
const bool& bLineBreaks);
/** OT-ENCRYPT a plainext string. (ASYMMETRIC)
EXPORT static std::string Encrypt(const std::string& RECIPIENT_NYM_ID,
const std::string& strPlaintext);
This will encode, ENCRYPT, and encode a plain string.
Returns the base64-encoded ciphertext, or nullptr.
internally the C++ code is:
OTString strPlain(strPlaintext);
OTEnvelope theEnvelope;
if (theEnvelope.Seal(RECIPIENT_NYM, strPlain)) { // Now it's encrypted
(in binary form, inside the envelope), to the recipient's nym.
OTASCIIArmor ascCiphertext(theEnvelope); // ascCiphertext now
contains the base64-encoded ciphertext (as a string.)
return ascCiphertext.Get();
}
*/
EXPORT static std::string Encrypt(const std::string& RECIPIENT_NYM_ID,
const std::string& strPlaintext);
/** OT-DECRYPT an OT-encrypted string back to plainext. (ASYMMETRIC)
EXPORT static std::string Decrypt(const std::string& RECIPIENT_NYM_ID,
const std::string& strCiphertext);
Decrypts the base64-encoded ciphertext back into a normal string plainext.
Returns the plainext string, or nullptr.
internally the C++ code is:
OTEnvelope theEnvelope; // Here is the envelope object. (The
ciphertext IS the data for an OTEnvelope.)
OTASCIIArmor ascCiphertext(strCiphertext); // The base64-encoded
ciphertext passed in. Next we'll try to attach it to envelope object...
if (theEnvelope.SetAsciiArmoredData(ascCiphertext)) { // ...so that we
can open it using the appropriate Nym, into a plain string object:
OTString strServerReply; // This will contain the output when
we're done.
const bool bOpened = // Now we try to decrypt:
theEnvelope.Open(RECIPIENT_NYM, strServerReply);
if (bOpened)
{
return strServerReply.Get();
}
}
*/
EXPORT static std::string Decrypt(const std::string& RECIPIENT_NYM_ID,
const std::string& strCiphertext);
// Generates a new symmetric key, based on a passphrase,
// and returns it (or nullptr.)
//
EXPORT static std::string CreateSymmetricKey();
EXPORT static std::string SymmetricEncrypt(const std::string& SYMMETRIC_KEY,
const std::string& PLAINTEXT);
EXPORT static std::string SymmetricDecrypt(
const std::string& SYMMETRIC_KEY,
const std::string& CIPHERTEXT_ENVELOPE);
/** OT-Sign a CONTRACT. (First signature)
EXPORT static std::string SignContract(const std::string& SIGNER_NYM_ID,
const std::string& THE_CONTRACT);
Tries to instantiate the contract object, based on the string passed in.
Releases all signatures, and then signs the contract.
Returns the signed contract, or nullptr if failure.
NOTE: The actual OT functionality (Use Cases) NEVER requires you to sign via
this function. Why not? because, anytime a signature is needed on something,
the relevant OT API call will require you to pass in the Nym, and the API
already
signs internally wherever it deems appropriate. Thus, this function is only
for
advanced uses, for OT-Scripts, server operators, etc.
*/
EXPORT static std::string SignContract(const std::string& SIGNER_NYM_ID,
const std::string& THE_CONTRACT);
// Instead of signing an existing contract, this is for just signing a flat
// message.
// Or, for example, for signing a new contract that has no signature yet.
// Let's say you
// have a ledger, for example, with no signatures yet. Pass "LEDGER" as the
// CONTRACT_TYPE
// and the resulting output will start like this: -----BEGIN OT SIGNED
// LEDGER----- ...
// Returns the signed output, or nullptr.
//
EXPORT static std::string FlatSign(const std::string& SIGNER_NYM_ID,
const std::string& THE_INPUT,
const std::string& CONTRACT_TYPE);
/** OT-Sign a CONTRACT. (Add a signature)
EXPORT static std::string AddSignature(const std::string& SIGNER_NYM_ID,
const std::string& THE_CONTRACT);
Tries to instantiate the contract object, based on the string passed in.
Signs the contract, without releasing any signatures that are already there.
Returns the signed contract, or nullptr if failure.
NOTE: The actual OT functionality (Use Cases) NEVER requires you to sign via
this function. Why not? because, anytime a signature is needed on something,
the relevant OT API call will require you to pass in the Nym, and the API
already
signs internally wherever it deems appropriate. Thus, this function is only
for
advanced uses, for OT-Scripts, server operators, etc.
*/
EXPORT static std::string AddSignature(const std::string& SIGNER_NYM_ID,
const std::string& THE_CONTRACT);
/** OT-Verify the signature on a CONTRACT.
Returns OT_BOOL -- OT_TRUE (1) or OT_FALSE (0)
*/
EXPORT static bool VerifySignature(const std::string& SIGNER_NYM_ID,
const std::string& THE_CONTRACT);
/** Verify and Retrieve XML Contents.
//
// Pass in a contract and a user ID, and this function will:
// -- Load the contract up and verify it. (Most classes in OT
// are derived in some way from OTContract.)
// -- Verify the user's signature on it.
// -- Remove the PGP-style bookends (the signatures, etc)
// and return the XML contents of the contract in string form. <==
*/
EXPORT static std::string VerifyAndRetrieveXMLContents(
const std::string& THE_CONTRACT, const std::string& SIGNER_ID);
/** The below functions are for retrieving log data programatically.
*/
EXPORT static int32_t GetMemlogSize();
EXPORT static std::string GetMemlogAtIndex(const int32_t& nIndex);
EXPORT static std::string PeekMemlogFront();
EXPORT static std::string PeekMemlogBack();
EXPORT static bool PopMemlogFront();
EXPORT static bool PopMemlogBack();
/** CREATE NYM -- Create new User
//
// Creates a new Nym and adds it to the wallet.
// (Including PUBLIC and PRIVATE KEYS.)
//
// Returns a new User ID (with files already created)
// or nullptr upon failure.
//
// Once it exists, use createUserAccount() to
// register your new Nym at any given Server. (Nearly all
// server requests require this...)
//
// nKeySize must be 1024, 2048, 4096, or 8192.
// NYM_ID_SOURCE can be empty (it will just generate a keypair
// and use the public key as the source.) Otherwise you can pass
// another source string in here, such as a URL, but the Nym will
// not verify against its own source unless the credential IDs for
// that Nym can be found posted at that same URL. Whereas if the
// source is just a public key, then the only verification requirement
// is that master credentials be signed by the corresponding private key.
*/
EXPORT static std::string CreateNym(
const int32_t& nKeySize, const std::string& NYM_ID_SOURCE,
const std::string& ALT_LOCATION); // source and location can be empty.
// (OT will generate a Nym with a
// public key as the source.)
EXPORT static std::string GetNym_ActiveCronItemIDs(
const std::string& NYM_ID, const std::string& SERVER_ID);
EXPORT static std::string GetActiveCronItem(const std::string& SERVER_ID,
int64_t lTransNum);
EXPORT static std::string GetNym_SourceForID(const std::string& NYM_ID);
EXPORT static std::string GetNym_AltSourceLocation(
const std::string& NYM_ID);
EXPORT static int32_t GetNym_CredentialCount(const std::string& NYM_ID);
EXPORT static std::string GetNym_CredentialID(const std::string& NYM_ID,
const int32_t& nIndex);
EXPORT static std::string GetNym_CredentialContents(
const std::string& NYM_ID, const std::string& CREDENTIAL_ID);
EXPORT static int32_t GetNym_RevokedCredCount(const std::string& NYM_ID);
EXPORT static std::string GetNym_RevokedCredID(const std::string& NYM_ID,
const int32_t& nIndex);
EXPORT static std::string GetNym_RevokedCredContents(
const std::string& NYM_ID, const std::string& CREDENTIAL_ID);
EXPORT static int32_t GetNym_SubcredentialCount(
const std::string& NYM_ID, const std::string& MASTER_CRED_ID);
EXPORT static std::string GetNym_SubCredentialID(
const std::string& NYM_ID, const std::string& MASTER_CRED_ID,
const int32_t& nIndex);
EXPORT static std::string GetNym_SubCredentialContents(
const std::string& NYM_ID, const std::string& MASTER_CRED_ID,
const std::string& SUB_CRED_ID);
EXPORT static std::string AddSubcredential(
const std::string& NYM_ID, const std::string& MASTER_CRED_ID,
const int32_t& nKeySize);
EXPORT static bool RevokeSubcredential(const std::string& NYM_ID,
const std::string& MASTER_CRED_ID,
const std::string& SUB_CRED_ID);
/** Creates a contract based on the contents passed in,
// then sets the contract key based on the NymID,
// and signs it with that Nym.
// This function will also ADD the contract to the wallet.
// Returns: the new contract ID, or nullptr if failure.
*/
EXPORT static std::string CreateServerContract(
const std::string& NYM_ID, const std::string& strXMLcontents);
EXPORT static std::string CreateAssetContract(
const std::string& NYM_ID, const std::string& strXMLcontents);
EXPORT static std::string CalculateAssetContractID(
const std::string& str_Contract);
EXPORT static std::string CalculateServerContractID(
const std::string& str_Contract);
// Use these below functions to get the new contract ITSELF, using its ID
// that was returned by the above two functions:
//
// EXPORT std::string GetServer_Contract(const std::string& SERVER_ID); //
// Return's Server's contract (based on server ID)
// EXPORT std::string GetAssetType_Contract(const std::string&
// ASSET_TYPE_ID); // Returns currency contract based on Asset Type ID
/*
---------------------------------
ASSET CONTRACTS will want to make sure they put something like this at the
top:
<?xml version="1.0"?>
<digitalAssetContract version="1.0">
<entity shortname="Just testing"
longname="I need user feedback to help design the contract tags the server
must support..."
email="F3llowTraveler (at) gmail.com"/>
<issue company="Chuck-E-Cheese, Inc"
email="games@chuckecheese.com"
contractUrl="https://chuckecheese.com/games/contract/"
type="currency"/>
<currency name="game tokens" tla="TOKEN" symbol="tks" type="decimal"
factor="1" decimal_power="0" fraction="mg"/>
---------------------------------
SERVER CONTRACTS will want to make sure they put something like this at the
top:
<?xml version="1.0"?>
<notaryProviderContract version="1.0">
<entity shortname="Transactions.com"
longname="Transactions.com, LLC"
email="serverfarm@cloudcomputing.com"
serverURL="https://transactions.com/vers/1/"/>
<notaryServer hostname="localhost"
port="7085"
URL="https://transactions.com/vers/1/" />
---------------------------------
NEITHER has to worry about THIS, which is added automatically:
<key name="contract">
- -----BEGIN CERTIFICATE-----
MIICZjCCAc+gAwIBAgIJAO14L19TJgzcMA0GCSqGSIb3DQEBBQUAMFcxCzAJBgNV
BAYTAlVTMREwDwYDVQQIEwhWaXJnaW5pYTEQMA4GA1UEBxMHRmFpcmZheDERMA8G
A1UEChMIWm9yay5vcmcxEDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTAwOTI5MDUyMzAx
WhcNMjAwOTI2MDUyMzAxWjBeMQswCQYDVQQGEwJVUzERMA8GA1UECBMIVmlyZ2lu
aWExEDAOBgNVBAcTB0ZhaXJmYXgxETAPBgNVBAoTCFpvcmsub3JnMRcwFQYDVQQD
Ew5zaGVsbC56b3JrLm9yZzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA3vD9
fO4ov4854L8wXrgfv2tltDz0ieVrTNSLuy1xuQyb//+MwZ0EYwu8jMMQrqbUaYG6
y8zJu32yBKrBNPPwJ+fJE+tfgVg860dGVbwMd4KhpkKtppJXmZaGqLqvELaXa4Uw
9N3qg/faj0NMEDIBhv/tD/B5U65vH+U0JlRJ07kCAwEAAaMzMDEwCQYDVR0TBAIw
ADAkBgNVHREEHTAbgg5zaGVsbC56b3JrLm9yZ4IJbG9jYWxob3N0MA0GCSqGSIb3
DQEBBQUAA4GBALLXPa/naWsiXsw0JwlSiG7aOmvMF2romUkcr6uObhN7sghd38M0
l2kKTiptnA8txrri8RhqmQgOgiyKFCKBkxY7/XGot62cE8Y1+lqGXlhu2UHm6NjA
pRKvng75J2HTjmmsbCHy+nexn4t44wssfPYlGPD8sGwmO24u9tRfdzJE
- -----END CERTIFICATE-----
</key>
*/
/*
EXPORT static std::string Contract_AddTag(const std::string& NYM_ID, const
std::string& THE_CONTRACT,
const std::string& TAG_NAME, const std::string& SUBTAG_NAME,
const std::string& SUBTAG_VALUE, const std::string& TAG_VALUE);
key == TAG_NAME
name == SUBTAG_NAME
"contract" == SUBTAG_VALUE
<the cert> == TAG_VALUE
*/
/** --------------------------------------------------
// ADD SERVER CONTRACT (to wallet)
//
// If you have a server contract that you'd like to add
// to your wallet, call this function.
*/
EXPORT static int32_t AddServerContract(
const std::string& strContract); // returns OT_TRUE (1) or OT_FALSE(0)
/** --------------------------------------------------
// ADD ASSET CONTRACT (to wallet)
//
// If you have an asset contract that you'd like to add
// to your wallet, call this function.
*/
EXPORT static int32_t AddAssetContract(
const std::string& strContract); // returns OT_TRUE (1) or OT_FALSE(0)
/** --------------------------------------------------
// NOTE: THE BELOW FUNCTIONS *DO NOT* SEND ANY MESSAGE TO THE SERVER,
// BUT RATHER, THEY ONLY QUERY FOR DATA FROM LOCAL STORAGE.
//
// Often a server response will cause a change to the data in local storage.
// These functions allow you to re-load that data so your GUI can reflect
// the updates to those files.
*/
EXPORT static int32_t GetServerCount();
EXPORT static int32_t GetAssetTypeCount();
EXPORT static int32_t GetAccountCount();
EXPORT static int32_t GetNymCount();
EXPORT static std::string GetServer_ID(const int32_t& nIndex); // based on
// Index
// (above 4
// functions)
// this
// returns
// the
// Server's
// ID
EXPORT static std::string GetServer_Name(
const std::string& SERVER_ID); // Return's Server's name (based on
// server ID)
EXPORT static std::string GetServer_Contract(
const std::string& SERVER_ID); // Return's Server's contract (based on
// server ID)
/** FormatAmount:
// Input: currency contract, amount. (And locale, internally.)
// Output: 545 becomes (for example) "$5.45"
//
// Returns formatted string for output, for a given amount, based on
currency contract and locale.
*/
EXPORT static std::string FormatAmount(const std::string& ASSET_TYPE_ID,
const int64_t& THE_AMOUNT);
/** StringToAmount:
// Input: currency contract, formatted string. (And locale, internally.)
// Output: "$5.45" becomes 545 (for example.)
//
// Returns amount from formatted string, based on currency contract and
locale.
*/
EXPORT static int64_t StringToAmount(const std::string& ASSET_TYPE_ID,
const std::string& str_input);
EXPORT static std::string GetAssetType_ID(
const int32_t& nIndex); // returns Asset Type ID (based on index from
// GetAssetTypeCount)
EXPORT static std::string GetAssetType_Name(
const std::string& ASSET_TYPE_ID); // Returns asset type name based on
// Asset Type ID
EXPORT static std::string GetAssetType_TLA(
const std::string& ASSET_TYPE_ID); // Returns asset type TLA based on
// Asset Type ID
EXPORT static std::string GetAssetType_Contract(
const std::string& ASSET_TYPE_ID); // Returns currency contract based on
// Asset Type ID
/** You already have accounts in your wallet (without any server
communications)
// and these functions allow you to query the data members of those
accounts.
// Thus, "AccountWallet" denotes that you are examining copies of your
accounts that
// are sitting in your wallet. Originally the purpose was to eliminate
confusion with
// a different set of similarly-named functions.
*/
EXPORT static std::string GetAccountWallet_ID(
const int32_t& nIndex); // returns a string containing the account ID,
// based on index.
EXPORT static std::string GetAccountWallet_Name(
const std::string& ACCOUNT_ID); // returns the account name, based on
// account ID.
EXPORT static int64_t GetAccountWallet_Balance(
const std::string& ACCOUNT_ID); // returns the account balance, based on
// account ID.
EXPORT static std::string GetAccountWallet_Type(
const std::string& ACCOUNT_ID); // returns the account type (simple,
// issuer, etc)
EXPORT static std::string GetAccountWallet_AssetTypeID(
const std::string& ACCOUNT_ID); // returns asset type ID of the account
EXPORT static std::string GetAccountWallet_ServerID(
const std::string& ACCOUNT_ID); // returns Server ID of the account
EXPORT static std::string GetAccountWallet_NymID(
const std::string& ACCOUNT_ID); // returns Nym ID of the account
EXPORT static std::string GetAccountWallet_InboxHash(
const std::string& ACCOUNT_ID); // returns latest InboxHash according to
// the account file. (Usually more
// recent than: GetNym_InboxHash)
EXPORT static std::string GetAccountWallet_OutboxHash(
const std::string& ACCOUNT_ID); // returns latest OutboxHash according
// to the account file. (Usually more
// recent than: GetNym_OutboxHash)
/** Returns OT_BOOL. Verifies any asset account (intermediary files) against
its own last signed receipt.
// Obviously this will fail for any new account that hasn't done any
transactions yet, and thus has no receipts.
*/
EXPORT static bool VerifyAccountReceipt(const std::string& SERVER_ID,
const std::string& NYM_ID,
const std::string& ACCT_ID);
/**----------------------------------------------------------
// GET NYM TRANSACTION NUM COUNT
// How many transaction numbers does the Nym have (for a given server?)
//
// This function returns the count of numbers available. If 0, then no
// transactions will work until you call getTransactionNumber()
// to replenish your Nym's supply for that ServerID...
//
// Returns a count (0 through N numbers available),
// or -1 for error (no nym found.)
*/
EXPORT static int32_t GetNym_TransactionNumCount(
const std::string& SERVER_ID, const std::string& NYM_ID);
EXPORT static std::string GetNym_ID(const int32_t& nIndex); // based on
// Index (above
// 4 functions)
// this returns
// the Nym's ID
EXPORT static std::string GetNym_Name(
const std::string& NYM_ID); // Returns Nym Name (based on NymID)
EXPORT static std::string GetNym_Stats(
const std::string& NYM_ID); // Returns Nym Statistics (based on NymID)
EXPORT static std::string GetNym_NymboxHash(
const std::string& SERVER_ID,
const std::string& NYM_ID); // NymboxHash for "most recently DOWNLOADED"
// Nymbox (by ServerID)
EXPORT static std::string GetNym_RecentHash(
const std::string& SERVER_ID,
const std::string& NYM_ID); // "Most recent NymboxHash according to the
// SERVER's records" (Which is often sent as
// an 'FYI' with various server replies to
// my messages.)
EXPORT static std::string GetNym_InboxHash(
const std::string& ACCOUNT_ID,
const std::string& NYM_ID); // InboxHash for "most recently DOWNLOADED"
// Inbox (by AccountID). Often contains
// older value than
// GetAccountWallet_InboxHash.
EXPORT static std::string GetNym_OutboxHash(
const std::string& ACCOUNT_ID,
const std::string& NYM_ID); // OutboxHash for "most recently DOWNLOADED"
// Outbox (by AccountID) Often contains
// older value than
// GetAccountWallet_OutboxHash
EXPORT static bool IsNym_RegisteredAtServer(const std::string& NYM_ID,
const std::string& SERVER_ID);
/** Each Nym has mail messages, they can come from different servers.
// This allows you to peruse the mail for a given Nym, and erase messages.
//
So how would you actually USE this to browse a Nym's mail?
-- Call GetNym_MailCount() to find out how many mail items there are.
-- Then LOOP through them, and use GetNym_MailSenderIDByIndex and
GetNym_MailServerIDByIndex to populate the list.
-- If you want to add a subject display, you'll have to call
GetNym_MailContentsByIndex()
and check for a first line beginning in Subject: (there may not be one.)
-- GetNym_MailContentsByIndex returns the body of the mail regardless.
-- Use Nym_VerifyMailByIndex() to verify the signature on the mail,
-- and use Nym_RemoveMailByIndex() to erase mail (when you want to.)
*/
EXPORT static int32_t GetNym_MailCount(const std::string& NYM_ID);
EXPORT static std::string GetNym_MailContentsByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // returns the message itself (Subject:
// optionally as first line)
EXPORT static std::string GetNym_MailSenderIDByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // returns the NymID of the sender.
EXPORT static std::string GetNym_MailServerIDByIndex(
const std::string& NYM_ID, const int32_t& nIndex); // returns the
// ServerID where the
// message came from.
EXPORT static bool Nym_RemoveMailByIndex(const std::string& NYM_ID,
const int32_t& nIndex); // (1 or
// 0.)
EXPORT static bool Nym_VerifyMailByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // true if signature verifies. (Sender Nym MUST
// be in my wallet for this to work.)
EXPORT static int32_t GetNym_OutmailCount(const std::string& NYM_ID);
EXPORT static std::string GetNym_OutmailContentsByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // returns the message itself (Subject:
// optionally as first line)
EXPORT static std::string GetNym_OutmailRecipientIDByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // returns the NymID of the recipient.
EXPORT static std::string GetNym_OutmailServerIDByIndex(
const std::string& NYM_ID, const int32_t& nIndex); // returns the
// ServerID where the
// message came from.
EXPORT static bool Nym_RemoveOutmailByIndex(const std::string& NYM_ID,
const int32_t& nIndex); // (1 or
// 0.)
EXPORT static bool Nym_VerifyOutmailByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // true if signature verifies. (Sender Nym MUST
// be in my wallet for this to work.)
EXPORT static int32_t GetNym_OutpaymentsCount(const std::string& NYM_ID);
EXPORT static std::string GetNym_OutpaymentsContentsByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // returns the message itself
EXPORT static std::string GetNym_OutpaymentsRecipientIDByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // returns the NymID of the recipient.
EXPORT static std::string GetNym_OutpaymentsServerIDByIndex(
const std::string& NYM_ID, const int32_t& nIndex); // returns the
// ServerID where the
// message came from.
EXPORT static bool Nym_RemoveOutpaymentsByIndex(
const std::string& NYM_ID, const int32_t& nIndex); // (1 or 0.)
EXPORT static bool Nym_VerifyOutpaymentsByIndex(
const std::string& NYM_ID,
const int32_t& nIndex); // true if signature verifies. (Sender Nym MUST
// be in my wallet for this to work.)
/**---------------------------------------------------------
// *** FUNCTIONS FOR REMOVING VARIOUS CONTRACTS AND NYMS FROM THE WALLET ***
// Can I remove this server contract from my wallet?
//
// You cannot remove the server contract from your wallet if there are
accounts in there using it.
// This function tells you whether you can remove the server contract or
not. (Whether there are accounts...)
// returns OT_BOOL
*/
EXPORT static bool Wallet_CanRemoveServer(const std::string& SERVER_ID);
/** Remove this server contract from my wallet!
//
// Try to remove the server contract from the wallet.
// This will not work if there are any accounts in the wallet for the same
server ID.
// returns OT_BOOL
*/
EXPORT static bool Wallet_RemoveServer(const std::string& SERVER_ID);
/** Can I remove this asset contract from my wallet?
//
// You cannot remove the asset contract from your wallet if there are
accounts in there using it.
// This function tells you whether you can remove the asset contract or not.
(Whether there are accounts...)
// returns OT_BOOL
*/
EXPORT static bool Wallet_CanRemoveAssetType(const std::string& ASSET_ID);
/** Remove this asset contract from my wallet!
//
// Try to remove the asset contract from the wallet.
// This will not work if there are any accounts in the wallet for the same
asset type ID.
// returns OT_BOOL
*/
EXPORT static bool Wallet_RemoveAssetType(const std::string& ASSET_ID);
/** Can I remove this Nym from my wallet?
//
// You cannot remove the Nym from your wallet if there are accounts in there
using it.
// This function tells you whether you can remove the Nym or not. (Whether
there are accounts...)
// returns OT_BOOL
*/
EXPORT static bool Wallet_CanRemoveNym(const std::string& NYM_ID);
/** Remove this Nym from my wallet!
//
// Try to remove the Nym from the wallet.
// This will not work if there are any nyms in the wallet for the same
server ID.
// returns OT_BOOL
*/
EXPORT static bool Wallet_RemoveNym(const std::string& NYM_ID);
/** Can I remove this Account from my wallet?
//
// You cannot remove the Account from your wallet if there are transactions
still open.
// This function tells you whether you can remove the Account or not.
(Whether there are transactions...)
// returns OT_BOOL
*/
EXPORT static bool Wallet_CanRemoveAccount(const std::string& ACCOUNT_ID);
// See deleteAssetAccount(), a server message, for deleting asset accounts.
// (You can't just delete them out of the wallet without first deleting them
// off of the server.)
//
/**
CHANGE MASTER KEY and PASSWORD.