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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
use {ErrorCode, IndyHandle};

use std::ffi::CString;
use std::time::Duration;
use std::ptr::null;

use utils::callbacks::ClosureHandler;
use utils::results::ResultHandler;

use ffi::anoncreds;
use ffi::{ResponseStringStringCB,
          ResponseI32UsizeCB,
          ResponseStringStringStringCB,
          ResponseStringCB,
          ResponseI32CB,
          ResponseEmptyCB,
          ResponseBoolCB};

pub struct Issuer {}

impl Issuer {
    /// Create credential schema entity that describes credential attributes list and allows credentials
    /// interoperability.
    ///
    /// Schema is public and intended to be shared with all anoncreds workflow actors usually by publishing SCHEMA transaction
    /// to Indy distributed ledger.
    ///
    /// It is IMPORTANT for current version POST Schema in Ledger and after that GET it from Ledger
    /// with correct seq_no to save compatibility with Ledger.
    /// After that can call Issuer::create_and_store_credential_def to build corresponding Credential Definition.
    ///
    /// # Arguments
    /// * `pool_handle` - pool handle (created by Pool::open_ledger).
    /// * `issuer_did`: DID of schema issuer
    /// * `name`: a name the schema
    /// * `version`: a version of the schema
    /// * `attrs`: a list of schema attributes descriptions
    ///
    /// # Returns
    /// * `schema_id`: identifier of created schema
    /// * `schema_json`: schema as json
    pub fn create_schema(issuer_did: &str, name: &str, version: &str, attrs: &str) -> Result<(String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();

        let err = Issuer::_create_schema(command_handle, issuer_did, name, version, attrs, cb);

        ResultHandler::two(err, receiver)
    }

    /// Create credential schema entity that describes credential attributes list and allows credentials
    /// interoperability.
    ///
    /// Schema is public and intended to be shared with all anoncreds workflow actors usually by publishing SCHEMA transaction
    /// to Indy distributed ledger.
    ///
    /// It is IMPORTANT for current version POST Schema in Ledger and after that GET it from Ledger
    /// with correct seq_no to save compatibility with Ledger.
    /// After that can call Issuer::create_and_store_credential_def to build corresponding Credential Definition.
    ///
    /// # Arguments
    /// * `pool_handle` - pool handle (created by Pool::open_ledger).
    /// * `issuer_did`: DID of schema issuer
    /// * `name`: a name the schema
    /// * `version`: a version of the schema
    /// * `attrs`: a list of schema attributes descriptions
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `schema_id`: identifier of created schema
    /// * `schema_json`: schema as json
    pub fn create_schema_timeout(issuer_did: &str, name: &str, version: &str, attrs: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();

        let err = Issuer::_create_schema(command_handle, issuer_did, name, version, attrs, cb);

        ResultHandler::two_timeout(err, receiver, timeout)
    }

    /// Create credential schema entity that describes credential attributes list and allows credentials
    /// interoperability.
    ///
    /// Schema is public and intended to be shared with all anoncreds workflow actors usually by publishing SCHEMA transaction
    /// to Indy distributed ledger.
    ///
    /// It is IMPORTANT for current version POST Schema in Ledger and after that GET it from Ledger
    /// with correct seq_no to save compatibility with Ledger.
    /// After that can call Issuer::create_and_store_credential_def to build corresponding Credential Definition.
    ///
    /// # Arguments
    /// * `pool_handle` - pool handle (created by Pool::open_ledger).
    /// * `issuer_did`: DID of schema issuer
    /// * `name`: a name the schema
    /// * `version`: a version of the schema
    /// * `attrs`: a list of schema attributes descriptions
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_schema_async<F: 'static>(issuer_did: &str, name: &str, version: &str, attrs: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));

        Issuer::_create_schema(command_handle, issuer_did, name, version, attrs, cb)
    }

    fn _create_schema(command_handle: IndyHandle, issuer_did: &str, name: &str, version: &str, attrs: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
        let issuer_did = c_str!(issuer_did);
        let name = c_str!(name);
        let version = c_str!(version);
        let attrs = c_str!(attrs);

        ErrorCode::from(unsafe {
          anoncreds::indy_issuer_create_schema(command_handle, issuer_did.as_ptr(), name.as_ptr(), version.as_ptr(), attrs.as_ptr(), cb)
        })
    }

    /// Create credential definition entity that encapsulates credentials issuer DID, credential schema, secrets used for signing credentials
    /// and secrets used for credentials revocation.
    ///
    /// Credential definition entity contains private and public parts. Private part will be stored in the wallet. Public part
    /// will be returned as json intended to be shared with all anoncreds workflow actors usually by publishing CRED_DEF transaction
    /// to Indy distributed ledger.
    ///
    /// It is IMPORTANT for current version GET Schema from Ledger with correct seq_no to save compatibility with Ledger.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `issuer_did`: a DID of the issuer signing cred_def transaction to the Ledger
    /// * `schema_json`: credential schema as a json
    /// * `tag`: allows to distinct between credential definitions for the same issuer and schema
    /// * `signature_type`: credential definition type (optional, 'CL' by default) that defines credentials signature and revocation math. Supported types are:
    ///     - 'CL': Camenisch-Lysyanskaya credential signature type
    /// * `config_json`: (optional) type-specific configuration of credential definition as json:
    ///     - 'CL':
    ///         - support_revocation: whether to request non-revocation credential (optional, default false)
    ///
    /// # Returns
    /// * `cred_def_id`: identifier of created credential definition
    /// * `cred_def_json`: public part of created credential definition
    pub fn create_and_store_credential_def(wallet_handle: IndyHandle, issuer_did: &str, schema_json: &str, tag: &str, signature_type: Option<&str>, config_json: &str) -> Result<(String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();

        let err = Issuer::_create_and_store_credential_def(command_handle, wallet_handle, issuer_did, schema_json, tag, signature_type, config_json, cb);

        ResultHandler::two(err, receiver)
    }

    /// Create credential definition entity that encapsulates credentials issuer DID, credential schema, secrets used for signing credentials
    /// and secrets used for credentials revocation.
    ///
    /// Credential definition entity contains private and public parts. Private part will be stored in the wallet. Public part
    /// will be returned as json intended to be shared with all anoncreds workflow actors usually by publishing CRED_DEF transaction
    /// to Indy distributed ledger.
    ///
    /// It is IMPORTANT for current version GET Schema from Ledger with correct seq_no to save compatibility with Ledger.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `issuer_did`: a DID of the issuer signing cred_def transaction to the Ledger
    /// * `schema_json`: credential schema as a json
    /// * `tag`: allows to distinct between credential definitions for the same issuer and schema
    /// * `signature_type`: credential definition type (optional, 'CL' by default) that defines credentials signature and revocation math. Supported types are:
    ///     - 'CL': Camenisch-Lysyanskaya credential signature type
    /// * `config_json`: (optional) type-specific configuration of credential definition as json:
    ///     - 'CL':
    ///         - support_revocation: whether to request non-revocation credential (optional, default false)
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `cred_def_id`: identifier of created credential definition
    /// * `cred_def_json`: public part of created credential definition
    pub fn create_and_store_credential_def_timeout(wallet_handle: IndyHandle, issuer_did: &str, schema_json: &str, tag: &str, signature_type: Option<&str>, config_json: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();

        let err = Issuer::_create_and_store_credential_def(command_handle, wallet_handle, issuer_did, schema_json, tag, signature_type, config_json, cb);

        ResultHandler::two_timeout(err, receiver, timeout)
    }

    /// Create credential definition entity that encapsulates credentials issuer DID, credential schema, secrets used for signing credentials
    /// and secrets used for credentials revocation.
    ///
    /// Credential definition entity contains private and public parts. Private part will be stored in the wallet. Public part
    /// will be returned as json intended to be shared with all anoncreds workflow actors usually by publishing CRED_DEF transaction
    /// to Indy distributed ledger.
    ///
    /// It is IMPORTANT for current version GET Schema from Ledger with correct seq_no to save compatibility with Ledger.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `issuer_did`: a DID of the issuer signing cred_def transaction to the Ledger
    /// * `schema_json`: credential schema as a json
    /// * `tag`: allows to distinct between credential definitions for the same issuer and schema
    /// * `signature_type`: credential definition type (optional, 'CL' by default) that defines credentials signature and revocation math. Supported types are:
    ///     - 'CL': Camenisch-Lysyanskaya credential signature type
    /// * `config_json`: (optional) type-specific configuration of credential definition as json:
    ///     - 'CL':
    ///         - support_revocation: whether to request non-revocation credential (optional, default false)
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_and_store_credential_def_async<F: 'static>(wallet_handle: IndyHandle, issuer_did: &str, schema_json: &str, tag: &str, signature_type: Option<&str>, config_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));

        Issuer::_create_and_store_credential_def(command_handle, wallet_handle, issuer_did, schema_json, tag, signature_type, config_json, cb)
    }

    fn _create_and_store_credential_def(command_handle: IndyHandle, wallet_handle: IndyHandle, issuer_did: &str, schema_json: &str, tag: &str, signature_type: Option<&str>, config_json: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
        let issuer_did = c_str!(issuer_did);
        let schema_json = c_str!(schema_json);
        let tag = c_str!(tag);
        let signature_type_str = opt_c_str!(signature_type);
        let config_json = c_str!(config_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_issuer_create_and_store_credential_def(command_handle, wallet_handle, issuer_did.as_ptr(), schema_json.as_ptr(), tag.as_ptr(), opt_c_ptr!(signature_type, signature_type_str), config_json.as_ptr(), cb)
        })
    }

    /// Create a new revocation registry for the given credential definition as tuple of entities
    /// - Revocation registry definition that encapsulates credentials definition reference, revocation type specific configuration and
    ///   secrets used for credentials revocation
    /// - Revocation registry state that stores the information about revoked entities in a non-disclosing way. The state can be
    ///   represented as ordered list of revocation registry entries were each entry represents the list of revocation or issuance operations.
    ///
    /// Revocation registry definition entity contains private and public parts. Private part will be stored in the wallet. Public part
    /// will be returned as json intended to be shared with all anoncreds workflow actors usually by publishing REVOC_REG_DEF transaction
    /// to Indy distributed ledger.
    ///
    /// Revocation registry state is stored on the wallet and also intended to be shared as the ordered list of REVOC_REG_ENTRY transactions.
    /// This call initializes the state in the wallet and returns the initial entry.
    ///
    /// Some revocation registry types (for example, 'CL_ACCUM') can require generation of binary blob called tails used to hide information about revoked credentials in public
    /// revocation registry and intended to be distributed out of leger (REVOC_REG_DEF transaction will still contain uri and hash of tails).
    /// This call requires access to pre-configured blob storage writer instance handle that will allow to write generated tails.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `issuer_did`: a DID of the issuer signing transaction to the Ledger
    /// * `revoc_def_type`: revocation registry type (optional, default value depends on credential definition type). Supported types are:
    ///     - 'CL_ACCUM': Type-3 pairing based accumulator. Default for 'CL' credential definition type
    /// * `tag`: allows to distinct between revocation registries for the same issuer and credential definition
    /// * `cred_def_id`: id of stored in ledger credential definition
    /// * `config_json`: type-specific configuration of revocation registry as json:
    ///     - 'CL_ACCUM': {
    ///         "issuance_type": (optional) type of issuance. Currently supported:
    ///             1) ISSUANCE_BY_DEFAULT: all indices are assumed to be issued and initial accumulator is calculated over all indices;
    ///             Revocation Registry is updated only during revocation.
    ///             2) ISSUANCE_ON_DEMAND: nothing is issued initially accumulator is 1 (used by default);
    ///         "max_cred_num": maximum number of credentials the new registry can process (optional, default 100000)
    ///     }
    /// * `tails_writer_handle`: handle of blob storage to store tails
    ///
    /// # Returns
    /// * `revoc_reg_id`: identifier of created revocation registry definition
    /// * `revoc_reg_def_json`: public part of revocation registry definition
    /// * `revoc_reg_entry_json`: revocation registry entry that defines initial state of revocation registry
    pub fn create_and_store_revoc_reg(wallet_handle: IndyHandle, issuer_did: &str, revoc_def_type: Option<&str>, tag: &str, cred_def_id: &str, config_json: &str, tails_writer_handle: IndyHandle) -> Result<(String, String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string_string();

        let err = Issuer::_create_and_store_revoc_reg(command_handle, wallet_handle, issuer_did, revoc_def_type, tag, cred_def_id, config_json, tails_writer_handle, cb);

        ResultHandler::three(err, receiver)
    }

    /// Create a new revocation registry for the given credential definition as tuple of entities
    /// - Revocation registry definition that encapsulates credentials definition reference, revocation type specific configuration and
    ///   secrets used for credentials revocation
    /// - Revocation registry state that stores the information about revoked entities in a non-disclosing way. The state can be
    ///   represented as ordered list of revocation registry entries were each entry represents the list of revocation or issuance operations.
    ///
    /// Revocation registry definition entity contains private and public parts. Private part will be stored in the wallet. Public part
    /// will be returned as json intended to be shared with all anoncreds workflow actors usually by publishing REVOC_REG_DEF transaction
    /// to Indy distributed ledger.
    ///
    /// Revocation registry state is stored on the wallet and also intended to be shared as the ordered list of REVOC_REG_ENTRY transactions.
    /// This call initializes the state in the wallet and returns the initial entry.
    ///
    /// Some revocation registry types (for example, 'CL_ACCUM') can require generation of binary blob called tails used to hide information about revoked credentials in public
    /// revocation registry and intended to be distributed out of leger (REVOC_REG_DEF transaction will still contain uri and hash of tails).
    /// This call requires access to pre-configured blob storage writer instance handle that will allow to write generated tails.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `issuer_did`: a DID of the issuer signing transaction to the Ledger
    /// * `revoc_def_type`: revocation registry type (optional, default value depends on credential definition type). Supported types are:
    ///     - 'CL_ACCUM': Type-3 pairing based accumulator. Default for 'CL' credential definition type
    /// * `tag`: allows to distinct between revocation registries for the same issuer and credential definition
    /// * `cred_def_id`: id of stored in ledger credential definition
    /// * `config_json`: type-specific configuration of revocation registry as json:
    ///     - 'CL_ACCUM': {
    ///         "issuance_type": (optional) type of issuance. Currently supported:
    ///             1) ISSUANCE_BY_DEFAULT: all indices are assumed to be issued and initial accumulator is calculated over all indices;
    ///             Revocation Registry is updated only during revocation.
    ///             2) ISSUANCE_ON_DEMAND: nothing is issued initially accumulator is 1 (used by default);
    ///         "max_cred_num": maximum number of credentials the new registry can process (optional, default 100000)
    ///     }
    /// * `tails_writer_handle`: handle of blob storage to store tails
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `revoc_reg_id`: identifier of created revocation registry definition
    /// * `revoc_reg_def_json`: public part of revocation registry definition
    /// * `revoc_reg_entry_json`: revocation registry entry that defines initial state of revocation registry
    pub fn create_and_store_revoc_reg_timeout(wallet_handle: IndyHandle, issuer_did: &str, revoc_def_type: Option<&str>, tag: &str, cred_def_id: &str, config_json: &str, tails_writer_handle: IndyHandle, timeout: Duration) -> Result<(String, String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string_string();

        let err = Issuer::_create_and_store_revoc_reg(command_handle, wallet_handle, issuer_did, revoc_def_type, tag, cred_def_id, config_json, tails_writer_handle, cb);

        ResultHandler::three_timeout(err, receiver, timeout)
    }

    /// Create a new revocation registry for the given credential definition as tuple of entities
    /// - Revocation registry definition that encapsulates credentials definition reference, revocation type specific configuration and
    ///   secrets used for credentials revocation
    /// - Revocation registry state that stores the information about revoked entities in a non-disclosing way. The state can be
    ///   represented as ordered list of revocation registry entries were each entry represents the list of revocation or issuance operations.
    ///
    /// Revocation registry definition entity contains private and public parts. Private part will be stored in the wallet. Public part
    /// will be returned as json intended to be shared with all anoncreds workflow actors usually by publishing REVOC_REG_DEF transaction
    /// to Indy distributed ledger.
    ///
    /// Revocation registry state is stored on the wallet and also intended to be shared as the ordered list of REVOC_REG_ENTRY transactions.
    /// This call initializes the state in the wallet and returns the initial entry.
    ///
    /// Some revocation registry types (for example, 'CL_ACCUM') can require generation of binary blob called tails used to hide information about revoked credentials in public
    /// revocation registry and intended to be distributed out of leger (REVOC_REG_DEF transaction will still contain uri and hash of tails).
    /// This call requires access to pre-configured blob storage writer instance handle that will allow to write generated tails.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `issuer_did`: a DID of the issuer signing transaction to the Ledger
    /// * `revoc_def_type`: revocation registry type (optional, default value depends on credential definition type). Supported types are:
    ///     - 'CL_ACCUM': Type-3 pairing based accumulator. Default for 'CL' credential definition type
    /// * `tag`: allows to distinct between revocation registries for the same issuer and credential definition
    /// * `cred_def_id`: id of stored in ledger credential definition
    /// * `config_json`: type-specific configuration of revocation registry as json:
    ///     - 'CL_ACCUM': {
    ///         "issuance_type": (optional) type of issuance. Currently supported:
    ///             1) ISSUANCE_BY_DEFAULT: all indices are assumed to be issued and initial accumulator is calculated over all indices;
    ///             Revocation Registry is updated only during revocation.
    ///             2) ISSUANCE_ON_DEMAND: nothing is issued initially accumulator is 1 (used by default);
    ///         "max_cred_num": maximum number of credentials the new registry can process (optional, default 100000)
    ///     }
    /// * `tails_writer_handle`: handle of blob storage to store tails
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_and_store_revoc_reg_async<F: 'static>(wallet_handle: IndyHandle, issuer_did: &str, revoc_def_type: Option<&str>, tag: &str, cred_def_id: &str, config_json: &str, tails_writer_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string_string(Box::new(closure));

        Issuer::_create_and_store_revoc_reg(command_handle, wallet_handle, issuer_did, revoc_def_type, tag, cred_def_id, config_json, tails_writer_handle, cb)
    }

    fn _create_and_store_revoc_reg(command_handle: IndyHandle, wallet_handle: IndyHandle, issuer_did: &str, revoc_def_type: Option<&str>, tag: &str, cred_def_id: &str, config_json: &str, tails_writer_handle: IndyHandle, cb: Option<ResponseStringStringStringCB>) -> ErrorCode {
        let issuer_did = c_str!(issuer_did);
        let revoc_def_type_str = opt_c_str!(revoc_def_type);
        let tag = c_str!(tag);
        let cred_def_id = c_str!(cred_def_id);
        let config_json = c_str!(config_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_issuer_create_and_store_revoc_reg(command_handle, wallet_handle, issuer_did.as_ptr(), opt_c_ptr!(revoc_def_type, revoc_def_type_str), tag.as_ptr(), cred_def_id.as_ptr(), config_json.as_ptr(), tails_writer_handle, cb)
        })
    }

    /// Create credential offer that will be used by Prover for
    /// credential request creation. Offer includes nonce and key correctness proof
    /// for authentication between protocol steps and integrity checking.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet)
    /// * `cred_def_id`: id of credential definition stored in the wallet
    ///
    /// # Returns
    /// * `credential_offer_json` - {
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     // Fields below can depend on Cred Def type
    ///     "nonce": string,
    ///     "key_correctness_proof" : <key_correctness_proof>
    /// }
    pub fn create_credential_offer(wallet_handle: IndyHandle, cred_def_id: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Issuer::_create_credential_offer(command_handle, wallet_handle, cred_def_id, cb);

        ResultHandler::one(err, receiver)
    }

    /// Create credential offer that will be used by Prover for
    /// credential request creation. Offer includes nonce and key correctness proof
    /// for authentication between protocol steps and integrity checking.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet)
    /// * `cred_def_id`: id of credential definition stored in the wallet
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `credential_offer_json` - {
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     // Fields below can depend on Cred Def type
    ///     "nonce": string,
    ///     "key_correctness_proof" : <key_correctness_proof>
    /// }
    pub fn create_credential_offer_timeout(wallet_handle: IndyHandle, cred_def_id: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Issuer::_create_credential_offer(command_handle, wallet_handle, cred_def_id, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Create credential offer that will be used by Prover for
    /// credential request creation. Offer includes nonce and key correctness proof
    /// for authentication between protocol steps and integrity checking.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet)
    /// * `cred_def_id`: id of credential definition stored in the wallet
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_credential_offer_async<F: 'static>(wallet_handle: IndyHandle, cred_def_id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Issuer::_create_credential_offer(command_handle, wallet_handle, cred_def_id, cb)
    }

    fn _create_credential_offer(command_handle: IndyHandle, wallet_handle: IndyHandle, cred_def_id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let cred_def_id = c_str!(cred_def_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_issuer_create_credential_offer(command_handle, wallet_handle, cred_def_id.as_ptr(), cb)
        })
    }

    /// Check Cred Request for the given Cred Offer and issue Credential for the given Cred Request.
    ///
    /// Cred Request must match Cred Offer. The credential definition and revocation registry definition
    /// referenced in Cred Offer and Cred Request must be already created and stored into the wallet.
    ///
    /// Information for this credential revocation will be store in the wallet as part of revocation registry under
    /// generated cred_revoc_id local for this wallet.
    ///
    /// This call returns revoc registry delta as json file intended to be shared as REVOC_REG_ENTRY transaction.
    /// Note that it is possible to accumulate deltas to reduce ledger load.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `cred_offer_json`: a cred offer created by Issuer::create_credential_offer
    /// * `cred_req_json`: a credential request created by Prover::store_credential
    /// * `cred_values_json`: a credential containing attribute values for each of requested attribute names.
    ///     Example:
    ///     {
    ///      "attr1" : {"raw": "value1", "encoded": "value1_as_int" },
    ///      "attr2" : {"raw": "value1", "encoded": "value1_as_int" }
    ///     }
    /// * `rev_reg_id`: id of revocation registry stored in the wallet
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    ///
    /// # Returns
    /// * `cred_json`: Credential json containing signed credential values
    ///     {
    ///         "schema_id": string,
    ///         "cred_def_id": string,
    ///         "rev_reg_def_id", Optional<string>,
    ///         "values": <see cred_values_json above>,
    ///         // Fields below can depend on Cred Def type
    ///         "signature": <signature>,
    ///         "signature_correctness_proof": <signature_correctness_proof>
    ///     }
    /// * `cred_revoc_id`: local id for revocation info (Can be used for revocation of this credential)
    /// * `revoc_reg_delta_json`: Revocation registry delta json with a newly issued credential
    pub fn create_credential(wallet_handle: IndyHandle, cred_offer_json: &str, cred_req_json: &str, cred_values_json: &str, rev_reg_id: Option<&str>, blob_storage_reader_handle: IndyHandle) -> Result<(String, Option<String>, Option<String>), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_opt_string_opt_string();

        let err = Issuer::_create_credential(command_handle, wallet_handle, cred_offer_json, cred_req_json, cred_values_json, rev_reg_id, blob_storage_reader_handle, cb);

        ResultHandler::three(err, receiver)
    }

    /// Check Cred Request for the given Cred Offer and issue Credential for the given Cred Request.
    ///
    /// Cred Request must match Cred Offer. The credential definition and revocation registry definition
    /// referenced in Cred Offer and Cred Request must be already created and stored into the wallet.
    ///
    /// Information for this credential revocation will be store in the wallet as part of revocation registry under
    /// generated cred_revoc_id local for this wallet.
    ///
    /// This call returns revoc registry delta as json file intended to be shared as REVOC_REG_ENTRY transaction.
    /// Note that it is possible to accumulate deltas to reduce ledger load.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `cred_offer_json`: a cred offer created by Issuer::create_credential_offer
    /// * `cred_req_json`: a credential request created by Prover::store_credential
    /// * `cred_values_json`: a credential containing attribute values for each of requested attribute names.
    ///     Example:
    ///     {
    ///      "attr1" : {"raw": "value1", "encoded": "value1_as_int" },
    ///      "attr2" : {"raw": "value1", "encoded": "value1_as_int" }
    ///     }
    /// * `rev_reg_id`: id of revocation registry stored in the wallet
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `cred_json`: Credential json containing signed credential values
    ///     {
    ///         "schema_id": string,
    ///         "cred_def_id": string,
    ///         "rev_reg_def_id", Optional<string>,
    ///         "values": <see cred_values_json above>,
    ///         // Fields below can depend on Cred Def type
    ///         "signature": <signature>,
    ///         "signature_correctness_proof": <signature_correctness_proof>
    ///     }
    /// * `cred_revoc_id`: local id for revocation info (Can be used for revocation of this credential)
    /// * `revoc_reg_delta_json`: Revocation registry delta json with a newly issued credential
    pub fn create_credential_timeout(wallet_handle: IndyHandle, cred_offer_json: &str, cred_req_json: &str, cred_values_json: &str, rev_reg_id: Option<&str>, blob_storage_reader_handle: IndyHandle, timeout: Duration) -> Result<(String, Option<String>, Option<String>), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_opt_string_opt_string();

        let err = Issuer::_create_credential(command_handle, wallet_handle, cred_offer_json, cred_req_json, cred_values_json, rev_reg_id, blob_storage_reader_handle, cb);

        ResultHandler::three_timeout(err, receiver, timeout)
    }

    /// Check Cred Request for the given Cred Offer and issue Credential for the given Cred Request.
    ///
    /// Cred Request must match Cred Offer. The credential definition and revocation registry definition
    /// referenced in Cred Offer and Cred Request must be already created and stored into the wallet.
    ///
    /// Information for this credential revocation will be store in the wallet as part of revocation registry under
    /// generated cred_revoc_id local for this wallet.
    ///
    /// This call returns revoc registry delta as json file intended to be shared as REVOC_REG_ENTRY transaction.
    /// Note that it is possible to accumulate deltas to reduce ledger load.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `cred_offer_json`: a cred offer created by Issuer::create_credential_offer
    /// * `cred_req_json`: a credential request created by Prover::store_credential
    /// * `cred_values_json`: a credential containing attribute values for each of requested attribute names.
    ///     Example:
    ///     {
    ///      "attr1" : {"raw": "value1", "encoded": "value1_as_int" },
    ///      "attr2" : {"raw": "value1", "encoded": "value1_as_int" }
    ///     }
    /// * `rev_reg_id`: id of revocation registry stored in the wallet
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_credential_async<F: 'static>(wallet_handle: IndyHandle, cred_offer_json: &str, cred_req_json: &str, cred_values_json: &str, rev_reg_id: Option<&str>, blob_storage_reader_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, Option<String>, Option<String>) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_opt_string_opt_string(Box::new(closure));

        Issuer::_create_credential(command_handle, wallet_handle, cred_offer_json, cred_req_json, cred_values_json, rev_reg_id, blob_storage_reader_handle, cb)
    }

    fn _create_credential(command_handle: IndyHandle, wallet_handle: IndyHandle, cred_offer_json: &str, cred_req_json: &str, cred_values_json: &str, rev_reg_id: Option<&str>, blob_storage_reader_handle: IndyHandle, cb: Option<ResponseStringStringStringCB>) -> ErrorCode {
        let cred_offer_json = c_str!(cred_offer_json);
        let cred_req_json = c_str!(cred_req_json);
        let cred_values_json = c_str!(cred_values_json);
        let rev_reg_id_str = opt_c_str!(rev_reg_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_issuer_create_credential(command_handle, wallet_handle, cred_offer_json.as_ptr(), cred_req_json.as_ptr(), cred_values_json.as_ptr(), opt_c_ptr!(rev_reg_id, rev_reg_id_str), blob_storage_reader_handle, cb)
        })
    }

    /// Revoke a credential identified by a cred_revoc_id (returned by indy_issuer_create_credential).
    ///
    /// The corresponding credential definition and revocation registry must be already
    /// created an stored into the wallet.
    ///
    /// This call returns revoc registry delta as json file intended to be shared as REVOC_REG_ENTRY transaction.
    /// Note that it is possible to accumulate deltas to reduce ledger load.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `blob_storage_reader_cfg_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_reg_id: id of revocation` registry stored in wallet
    /// * `cred_revoc_id`: local id for revocation info
    ///
    /// # Returns
    /// * `revoc_reg_delta_json`: Revocation registry delta json with a revoked credential
    pub fn revoke_credential(wallet_handle: IndyHandle, blob_storage_reader_cfg_handle: IndyHandle, rev_reg_id: &str, cred_revoc_id: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Issuer::_revoke_credential(command_handle, wallet_handle, blob_storage_reader_cfg_handle, rev_reg_id, cred_revoc_id, cb);

        ResultHandler::one(err, receiver)
    }

    /// Revoke a credential identified by a cred_revoc_id (returned by indy_issuer_create_credential).
    ///
    /// The corresponding credential definition and revocation registry must be already
    /// created an stored into the wallet.
    ///
    /// This call returns revoc registry delta as json file intended to be shared as REVOC_REG_ENTRY transaction.
    /// Note that it is possible to accumulate deltas to reduce ledger load.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `blob_storage_reader_cfg_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_reg_id: id of revocation` registry stored in wallet
    /// * `cred_revoc_id`: local id for revocation info
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `revoc_reg_delta_json`: Revocation registry delta json with a revoked credential
    pub fn revoke_credential_timeout(wallet_handle: IndyHandle, blob_storage_reader_cfg_handle: IndyHandle, rev_reg_id: &str, cred_revoc_id: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Issuer::_revoke_credential(command_handle, wallet_handle, blob_storage_reader_cfg_handle, rev_reg_id, cred_revoc_id, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Revoke a credential identified by a cred_revoc_id (returned by indy_issuer_create_credential).
    ///
    /// The corresponding credential definition and revocation registry must be already
    /// created an stored into the wallet.
    ///
    /// This call returns revoc registry delta as json file intended to be shared as REVOC_REG_ENTRY transaction.
    /// Note that it is possible to accumulate deltas to reduce ledger load.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `blob_storage_reader_cfg_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_reg_id: id of revocation` registry stored in wallet
    /// * `cred_revoc_id`: local id for revocation info
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn revoke_credential_async<F: 'static>(wallet_handle: IndyHandle, blob_storage_reader_cfg_handle: IndyHandle, rev_reg_id: &str, cred_revoc_id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Issuer::_revoke_credential(command_handle, wallet_handle, blob_storage_reader_cfg_handle, rev_reg_id, cred_revoc_id, cb)
    }

    fn _revoke_credential(command_handle: IndyHandle, wallet_handle: IndyHandle, blob_storage_reader_cfg_handle: IndyHandle, rev_reg_id: &str, cred_revoc_id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let rev_reg_id = c_str!(rev_reg_id);
        let cred_revoc_id = c_str!(cred_revoc_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_issuer_revoke_credential(command_handle, wallet_handle, blob_storage_reader_cfg_handle, rev_reg_id.as_ptr(), cred_revoc_id.as_ptr(), cb)
        })
    }

    /// Merge two revocation registry deltas (returned by Issuer::create_credential or Issuer::revoke_credential) to accumulate common delta.
    /// Send common delta to ledger to reduce the load.
    ///
    /// # Arguments
    /// * `rev_reg_delta_json`: revocation registry delta.
    /// * `other_rev_reg_delta_json`: revocation registry delta for which PrevAccum value  is equal to current accum value of rev_reg_delta_json.
    ///
    /// # Returns
    /// * `merged_rev_reg_delta` - Merged revocation registry delta
    pub fn merge_revocation_registry_deltas(rev_reg_delta_json: &str, other_rev_reg_delta_json: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Issuer::_merge_revocation_registry_deltas(command_handle, rev_reg_delta_json, other_rev_reg_delta_json, cb);

        ResultHandler::one(err, receiver)
    }

    /// Merge two revocation registry deltas (returned by Issuer::create_credential or Issuer::revoke_credential) to accumulate common delta.
    /// Send common delta to ledger to reduce the load.
    ///
    /// # Arguments
    /// * `rev_reg_delta_json`: revocation registry delta.
    /// * `other_rev_reg_delta_json`: revocation registry delta for which PrevAccum value  is equal to current accum value of rev_reg_delta_json.
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `merged_rev_reg_delta` - Merged revocation registry delta
    pub fn merge_revocation_registry_deltas_timeout(rev_reg_delta_json: &str, other_rev_reg_delta_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Issuer::_merge_revocation_registry_deltas(command_handle, rev_reg_delta_json, other_rev_reg_delta_json, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Merge two revocation registry deltas (returned by Issuer::create_credential or Issuer::revoke_credential) to accumulate common delta.
    /// Send common delta to ledger to reduce the load.
    ///
    /// # Arguments
    /// * `rev_reg_delta_json`: revocation registry delta.
    /// * `other_rev_reg_delta_json`: revocation registry delta for which PrevAccum value  is equal to current accum value of rev_reg_delta_json.
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn merge_revocation_registry_deltas_async<F: 'static>(rev_reg_delta_json: &str, other_rev_reg_delta_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Issuer::_merge_revocation_registry_deltas(command_handle, rev_reg_delta_json, other_rev_reg_delta_json, cb)
    }

    fn _merge_revocation_registry_deltas(command_handle: IndyHandle, rev_reg_delta_json: &str, other_rev_reg_delta_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let rev_reg_delta_json = c_str!(rev_reg_delta_json);
        let other_rev_reg_delta_json = c_str!(other_rev_reg_delta_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_issuer_merge_revocation_registry_deltas(command_handle, rev_reg_delta_json.as_ptr(), other_rev_reg_delta_json.as_ptr(), cb)
        })
    }
}

pub struct Prover {}

impl Prover {
    /// Creates a master secret with a given id and stores it in the wallet.
    /// The id must be unique.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `master_secret_id`: (optional, if not present random one will be generated) new master id
    ///
    /// # Returns
    /// * `out_master_secret_id` - Id of generated master secret
    pub fn create_master_secret(wallet_handle: IndyHandle, master_secret_id: Option<&str>) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_create_master_secret(command_handle, wallet_handle, master_secret_id, cb);

        ResultHandler::one(err, receiver)
    }

    /// Creates a master secret with a given id and stores it in the wallet.
    /// The id must be unique.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `master_secret_id`: (optional, if not present random one will be generated) new master id
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `out_master_secret_id` - Id of generated master secret
    pub fn create_master_secret_timeout(wallet_handle: IndyHandle, master_secret_id: Option<&str>, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_create_master_secret(command_handle, wallet_handle, master_secret_id, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Creates a master secret with a given id and stores it in the wallet.
    /// The id must be unique.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `master_secret_id`: (optional, if not present random one will be generated) new master id
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_master_secret_async<F: 'static>(wallet_handle: IndyHandle, master_secret_id: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::_create_master_secret(command_handle, wallet_handle, master_secret_id, cb)
    }

    fn _create_master_secret(command_handle: IndyHandle, wallet_handle: IndyHandle, master_secret_id: Option<&str>, cb: Option<ResponseStringCB>) -> ErrorCode {
        let master_secret_id_str = opt_c_str!(master_secret_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_create_master_secret(command_handle, wallet_handle, opt_c_ptr!(master_secret_id, master_secret_id_str), cb)
        })
    }

    /// Gets human readable credential by the given id.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `cred_id`: Identifier by which requested credential is stored in the wallet
    ///
    /// # Returns
    /// * `credential_json` - {
    ///     "referent": string, // cred_id in the wallet
    ///     "attrs": {"key1":"raw_value1", "key2":"raw_value2"},
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     "rev_reg_id": Optional<string>,
    ///     "cred_rev_id": Optional<string>
    /// }
    pub fn get_credential(wallet_handle: IndyHandle, cred_id: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_get_credential(command_handle, wallet_handle, cred_id, cb);

        ResultHandler::one(err, receiver)
    }

    /// Gets human readable credential by the given id.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `cred_id`: Identifier by which requested credential is stored in the wallet
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `credential_json` - {
    ///     "referent": string, // cred_id in the wallet
    ///     "attrs": {"key1":"raw_value1", "key2":"raw_value2"},
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     "rev_reg_id": Optional<string>,
    ///     "cred_rev_id": Optional<string>
    /// }
    pub fn get_credential_timeout(wallet_handle: IndyHandle, cred_id: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_get_credential(command_handle, wallet_handle, cred_id, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Gets human readable credential by the given id.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `cred_id`: Identifier by which requested credential is stored in the wallet
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn get_credential_async<F: 'static>(wallet_handle: IndyHandle, cred_id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::_get_credential(command_handle, wallet_handle, cred_id, cb)
    }

    fn _get_credential(command_handle: IndyHandle, wallet_handle: IndyHandle, cred_id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let cred_id = c_str!(cred_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_get_credential(command_handle, wallet_handle, cred_id.as_ptr(), cb)
        })
    }

    /// Creates a credential request for the given credential offer.
    ///
    /// The method creates a blinded master secret for a master secret identified by a provided name.
    /// The master secret identified by the name must be already stored in the secure wallet (see Prover::create_master_secret)
    /// The blinded master secret is a part of the credential request.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet)
    /// * `prover_did`: a DID of the prover
    /// * `cred_offer_json`: credential offer as a json containing information about the issuer and a credential
    /// * `cred_def_json`: credential definition json related to <cred_def_id> in <cred_offer_json>
    /// * `master_secret_id`: the id of the master secret stored in the wallet
    ///
    /// # Returns
    /// * `cred_req_json`: Credential request json for creation of credential by Issuer
    ///     {
    ///      "prover_did" : string,
    ///      "cred_def_id" : string,
    ///         // Fields below can depend on Cred Def type
    ///      "blinded_ms" : <blinded_master_secret>,
    ///      "blinded_ms_correctness_proof" : <blinded_ms_correctness_proof>,
    ///      "nonce": string
    ///    }
    /// * `cred_req_metadata_json`: Credential request metadata json for further processing of received form Issuer credential.
    pub fn create_credential_req(wallet_handle: IndyHandle, prover_did: &str, cred_offer_json: &str, cred_def_json: &str, master_secret_id: &str) -> Result<(String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();

        let err = Prover::_create_credential_req(command_handle, wallet_handle, prover_did, cred_offer_json, cred_def_json, master_secret_id, cb);

        ResultHandler::two(err, receiver)
    }

    /// Creates a credential request for the given credential offer.
    ///
    /// The method creates a blinded master secret for a master secret identified by a provided name.
    /// The master secret identified by the name must be already stored in the secure wallet (see Prover::create_master_secret)
    /// The blinded master secret is a part of the credential request.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet)
    /// * `prover_did`: a DID of the prover
    /// * `cred_offer_json`: credential offer as a json containing information about the issuer and a credential
    /// * `cred_def_json`: credential definition json related to <cred_def_id> in <cred_offer_json>
    /// * `master_secret_id`: the id of the master secret stored in the wallet
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `cred_req_json`: Credential request json for creation of credential by Issuer
    ///     {
    ///      "prover_did" : string,
    ///      "cred_def_id" : string,
    ///         // Fields below can depend on Cred Def type
    ///      "blinded_ms" : <blinded_master_secret>,
    ///      "blinded_ms_correctness_proof" : <blinded_ms_correctness_proof>,
    ///      "nonce": string
    ///    }
    /// * `cred_req_metadata_json`: Credential request metadata json for further processing of received form Issuer credential.
    pub fn create_credential_req_timeout(wallet_handle: IndyHandle, prover_did: &str, cred_offer_json: &str, cred_def_json: &str, master_secret_id: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();

        let err = Prover::_create_credential_req(command_handle, wallet_handle, prover_did, cred_offer_json, cred_def_json, master_secret_id, cb);

        ResultHandler::two_timeout(err, receiver, timeout)
    }

    /// Creates a credential request for the given credential offer.
    ///
    /// The method creates a blinded master secret for a master secret identified by a provided name.
    /// The master secret identified by the name must be already stored in the secure wallet (see Prover::create_master_secret)
    /// The blinded master secret is a part of the credential request.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet)
    /// * `prover_did`: a DID of the prover
    /// * `cred_offer_json`: credential offer as a json containing information about the issuer and a credential
    /// * `cred_def_json`: credential definition json related to <cred_def_id> in <cred_offer_json>
    /// * `master_secret_id`: the id of the master secret stored in the wallet
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_credential_req_async<F: 'static>(wallet_handle: IndyHandle, prover_did: &str, cred_offer_json: &str, cred_def_json: &str, master_secret_id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));

        Prover::_create_credential_req(command_handle, wallet_handle, prover_did, cred_offer_json, cred_def_json, master_secret_id, cb)
    }

    fn _create_credential_req(command_handle: IndyHandle, wallet_handle: IndyHandle, prover_did: &str, cred_offer_json: &str, cred_def_json: &str, master_secret_id: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
        let prover_did = c_str!(prover_did);
        let cred_offer_json = c_str!(cred_offer_json);
        let cred_def_json = c_str!(cred_def_json);
        let master_secret_id = c_str!(master_secret_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_create_credential_req(command_handle, wallet_handle, prover_did.as_ptr(), cred_offer_json.as_ptr(), cred_def_json.as_ptr(), master_secret_id.as_ptr(), cb)
        })
    }

    /// Check credential provided by Issuer for the given credential request,
    /// updates the credential by a master secret and stores in a secure wallet.
    ///
    /// To support efficient and flexible search the following tags will be created for stored credential:
    ///     {
    ///         "schema_id": <credential schema id>,
    ///         "schema_issuer_did": <credential schema issuer did>,
    ///         "schema_name": <credential schema name>,
    ///         "schema_version": <credential schema version>,
    ///         "issuer_did": <credential issuer did>,
    ///         "cred_def_id": <credential definition id>,
    ///         "rev_reg_id": <credential revocation registry id>, // "None" as string if not present
    ///         // for every attribute in <credential values>
    ///         "attr::<attribute name>::marker": "1",
    ///         "attr::<attribute name>::value": <attribute raw value>,
    ///     }
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet).
    /// * `cred_id`: (optional, default is a random one) identifier by which credential will be stored in the wallet
    /// * `cred_req_metadata_json`: a credential request metadata created by Prover::create_credential_req
    /// * `cred_json`: credential json received from issuer
    /// * `cred_def_json`: credential definition json related to <cred_def_id> in <cred_json>
    /// * `rev_reg_def_json`: revocation registry definition json related to <rev_reg_def_id> in <cred_json>
    ///
    /// # Returns
    /// * `out_cred_id` - identifier by which credential is stored in the wallet
    pub fn store_credential(wallet_handle: IndyHandle, cred_id: Option<&str>, cred_req_metadata_json: &str, cred_json: &str, cred_def_json: &str, rev_reg_def_json: Option<&str>) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_store_credential(command_handle, wallet_handle, cred_id, cred_req_metadata_json, cred_json, cred_def_json, rev_reg_def_json, cb);

        ResultHandler::one(err, receiver)
    }

    /// Check credential provided by Issuer for the given credential request,
    /// updates the credential by a master secret and stores in a secure wallet.
    ///
    /// To support efficient and flexible search the following tags will be created for stored credential:
    ///     {
    ///         "schema_id": <credential schema id>,
    ///         "schema_issuer_did": <credential schema issuer did>,
    ///         "schema_name": <credential schema name>,
    ///         "schema_version": <credential schema version>,
    ///         "issuer_did": <credential issuer did>,
    ///         "cred_def_id": <credential definition id>,
    ///         "rev_reg_id": <credential revocation registry id>, // "None" as string if not present
    ///         // for every attribute in <credential values>
    ///         "attr::<attribute name>::marker": "1",
    ///         "attr::<attribute name>::value": <attribute raw value>,
    ///     }
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet).
    /// * `cred_id`: (optional, default is a random one) identifier by which credential will be stored in the wallet
    /// * `cred_req_metadata_json`: a credential request metadata created by Prover::create_credential_req
    /// * `cred_json`: credential json received from issuer
    /// * `cred_def_json`: credential definition json related to <cred_def_id> in <cred_json>
    /// * `rev_reg_def_json`: revocation registry definition json related to <rev_reg_def_id> in <cred_json>
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `out_cred_id` - identifier by which credential is stored in the wallet
    pub fn store_credential_timeout(wallet_handle: IndyHandle, cred_id: Option<&str>, cred_req_metadata_json: &str, cred_json: &str, cred_def_json: &str, rev_reg_def_json: Option<&str>, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_store_credential(command_handle, wallet_handle, cred_id, cred_req_metadata_json, cred_json, cred_def_json, rev_reg_def_json, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Check credential provided by Issuer for the given credential request,
    /// updates the credential by a master secret and stores in a secure wallet.
    ///
    /// To support efficient and flexible search the following tags will be created for stored credential:
    ///     {
    ///         "schema_id": <credential schema id>,
    ///         "schema_issuer_did": <credential schema issuer did>,
    ///         "schema_name": <credential schema name>,
    ///         "schema_version": <credential schema version>,
    ///         "issuer_did": <credential issuer did>,
    ///         "cred_def_id": <credential definition id>,
    ///         "rev_reg_id": <credential revocation registry id>, // "None" as string if not present
    ///         // for every attribute in <credential values>
    ///         "attr::<attribute name>::marker": "1",
    ///         "attr::<attribute name>::value": <attribute raw value>,
    ///     }
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet).
    /// * `cred_id`: (optional, default is a random one) identifier by which credential will be stored in the wallet
    /// * `cred_req_metadata_json`: a credential request metadata created by Prover::create_credential_req
    /// * `cred_json`: credential json received from issuer
    /// * `cred_def_json`: credential definition json related to <cred_def_id> in <cred_json>
    /// * `rev_reg_def_json`: revocation registry definition json related to <rev_reg_def_id> in <cred_json>
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn store_credential_async<F: 'static>(wallet_handle: IndyHandle, cred_id: Option<&str>, cred_req_metadata_json: &str, cred_json: &str, cred_def_json: &str, rev_reg_def_json: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::_store_credential(command_handle, wallet_handle, cred_id, cred_req_metadata_json, cred_json, cred_def_json, rev_reg_def_json, cb)
    }

    fn _store_credential(command_handle: IndyHandle, wallet_handle: IndyHandle, cred_id: Option<&str>, cred_req_metadata_json: &str, cred_json: &str, cred_def_json: &str, rev_reg_def_json: Option<&str>, cb: Option<ResponseStringCB>) -> ErrorCode {
        let cred_id_str = opt_c_str!(cred_id);
        let cred_req_metadata_json = c_str!(cred_req_metadata_json);
        let cred_json = c_str!(cred_json);
        let cred_def_json = c_str!(cred_def_json);
        let rev_reg_def_json_str = opt_c_str!(rev_reg_def_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_store_credential(command_handle, wallet_handle, opt_c_ptr!(cred_id, cred_id_str), cred_req_metadata_json.as_ptr(), cred_json.as_ptr(), cred_def_json.as_ptr(), opt_c_ptr!(rev_reg_def_json, rev_reg_def_json_str), cb)
        })
    }

    /// Gets human readable credentials according to the filter.
    /// If filter is NULL, then all credentials are returned.
    /// Credentials can be filtered by Issuer, credential_def and/or Schema.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet).
    /// * `filter_json`: filter for credentials {
    ///    "schema_id": string, (Optional)
    ///    "schema_issuer_did": string, (Optional)
    ///    "schema_name": string, (Optional)
    ///    "schema_version": string, (Optional)
    ///    "issuer_did": string, (Optional)
    ///    "cred_def_id": string, (Optional)
    ///  }
    ///
    /// # Returns
    /// * `credentials_json` - [{
    ///     "referent": string, // cred_id in the wallet
    ///     "attrs": {"key1":"raw_value1", "key2":"raw_value2"},
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     "rev_reg_id": Optional<string>,
    ///     "cred_rev_id": Optional<string>
    /// }]
    pub fn get_credentials(wallet_handle: IndyHandle, filter_json: Option<&str>) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_get_credentials(command_handle, wallet_handle, filter_json, cb);

        ResultHandler::one(err, receiver)
    }

    /// Gets human readable credentials according to the filter.
    /// If filter is NULL, then all credentials are returned.
    /// Credentials can be filtered by Issuer, credential_def and/or Schema.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet).
    /// * `filter_json`: filter for credentials {
    ///    "schema_id": string, (Optional)
    ///    "schema_issuer_did": string, (Optional)
    ///    "schema_name": string, (Optional)
    ///    "schema_version": string, (Optional)
    ///    "issuer_did": string, (Optional)
    ///    "cred_def_id": string, (Optional)
    ///  }
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `credentials_json` - [{
    ///     "referent": string, // cred_id in the wallet
    ///     "attrs": {"key1":"raw_value1", "key2":"raw_value2"},
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     "rev_reg_id": Optional<string>,
    ///     "cred_rev_id": Optional<string>
    /// }]
    pub fn get_credentials_timeout(wallet_handle: IndyHandle, filter_json: Option<&str>, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_get_credentials(command_handle, wallet_handle, filter_json, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Gets human readable credentials according to the filter.
    /// If filter is NULL, then all credentials are returned.
    /// Credentials can be filtered by Issuer, credential_def and/or Schema.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by open_wallet).
    /// * `filter_json`: filter for credentials {
    ///    "schema_id": string, (Optional)
    ///    "schema_issuer_did": string, (Optional)
    ///    "schema_name": string, (Optional)
    ///    "schema_version": string, (Optional)
    ///    "issuer_did": string, (Optional)
    ///    "cred_def_id": string, (Optional)
    ///  }
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn get_credentials_async<F: 'static>(wallet_handle: IndyHandle, filter_json: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::_get_credentials(command_handle, wallet_handle, filter_json, cb)
    }

    fn _get_credentials(command_handle: IndyHandle, wallet_handle: IndyHandle, filter_json: Option<&str>, cb: Option<ResponseStringCB>) -> ErrorCode {
        let filter_json_str = opt_c_str!(filter_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_get_credentials(command_handle, wallet_handle, opt_c_ptr!(filter_json, filter_json_str), cb)
        })
    }

    /// Search for credentials stored in wallet.
    /// Credentials can be filtered by tags created during saving of credential.
    ///
    /// Instead of immediately returning of fetched credentials
    /// this call returns search_handle that can be used later
    /// to fetch records by small batches (with Prover::fetch_credentials).
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `query_json`: Wql query filter for credentials searching based on tags.
    ///     where query: indy-sdk/doc/design/011-wallet-query-language/README.md
    ///
    /// # Returns
    /// * `search_handle`: Search handle that can be used later to fetch records by small batches (with Prover::fetch_credentials)
    /// * `total_count`: Total count of records
    pub fn search_credentials(wallet_handle: IndyHandle, query_json: Option<&str>) -> Result<(i32, usize), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32_usize();

        let err = Prover::_search_credentials(command_handle, wallet_handle, query_json, cb);

        ResultHandler::two(err, receiver)
    }

    /// Search for credentials stored in wallet.
    /// Credentials can be filtered by tags created during saving of credential.
    ///
    /// Instead of immediately returning of fetched credentials
    /// this call returns search_handle that can be used later
    /// to fetch records by small batches (with Prover::fetch_credentials).
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `query_json`: Wql query filter for credentials searching based on tags.
    ///     where query: indy-sdk/doc/design/011-wallet-query-language/README.md
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `search_handle`: Search handle that can be used later to fetch records by small batches (with Prover::fetch_credentials)
    /// * `total_count`: Total count of records
    pub fn search_credentials_timeout(wallet_handle: IndyHandle, query_json: Option<&str>, timeout: Duration) -> Result<(i32, usize), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32_usize();

        let err = Prover::_search_credentials(command_handle, wallet_handle, query_json, cb);

        ResultHandler::two_timeout(err, receiver, timeout)
    }

    /// Search for credentials stored in wallet.
    /// Credentials can be filtered by tags created during saving of credential.
    ///
    /// Instead of immediately returning of fetched credentials
    /// this call returns search_handle that can be used later
    /// to fetch records by small batches (with Prover::fetch_credentials).
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `query_json`: Wql query filter for credentials searching based on tags.
    ///     where query: indy-sdk/doc/design/011-wallet-query-language/README.md
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn search_credentials_async<F: 'static>(wallet_handle: IndyHandle, query_json: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, i32, usize) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_i32_usize(Box::new(closure));

        Prover::_search_credentials(command_handle, wallet_handle, query_json, cb)
    }

    fn _search_credentials(command_handle: IndyHandle, wallet_handle: IndyHandle, query_json: Option<&str>, cb: Option<ResponseI32UsizeCB>) -> ErrorCode {
        let query_json_str = opt_c_str!(query_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_search_credentials(command_handle, wallet_handle, opt_c_ptr!(query_json, query_json_str), cb)
        })
    }

    /// Fetch next credentials for search.
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials)
    /// * `count`: Count of credentials to fetch
    ///
    /// # Returns
    /// * `credentials_json`: List of human readable credentials:
    ///  [{
    ///     "referent": string, // cred_id in the wallet
    ///     "attrs": {"key1":"raw_value1", "key2":"raw_value2"},
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     "rev_reg_id": Optional<string>,
    ///     "cred_rev_id": Optional<string>
    ///  }]
    pub fn fetch_credentials(search_handle: IndyHandle, count: usize) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_fetch_credentials(command_handle, search_handle, count, cb);

        ResultHandler::one(err, receiver)
    }

    /// Fetch next credentials for search.
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials)
    /// * `count`: Count of credentials to fetch
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `credentials_json`: List of human readable credentials:
    ///  [{
    ///     "referent": string, // cred_id in the wallet
    ///     "attrs": {"key1":"raw_value1", "key2":"raw_value2"},
    ///     "schema_id": string,
    ///     "cred_def_id": string,
    ///     "rev_reg_id": Optional<string>,
    ///     "cred_rev_id": Optional<string>
    ///  }]
    pub fn fetch_credentials_timeout(search_handle: IndyHandle, count: usize, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_fetch_credentials(command_handle, search_handle, count, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Fetch next credentials for search.
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials)
    /// * `count`: Count of credentials to fetch
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn fetch_credentials_async<F: 'static>(search_handle: IndyHandle, count: usize, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::_fetch_credentials(command_handle, search_handle, count, cb)
    }

    fn _fetch_credentials(command_handle: IndyHandle, search_handle: IndyHandle, count: usize, cb: Option<ResponseStringCB>) -> ErrorCode {

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_fetch_credentials(command_handle, search_handle, count, cb)
        })
    }

    /// Close credentials search (make search handle invalid)
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials)
    pub fn close_credentials_search(search_handle: IndyHandle) -> Result<(), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();

        let err = Prover::_close_credentials_search(command_handle, search_handle, cb);

        ResultHandler::empty(err, receiver)
    }

    /// Close credentials search (make search handle invalid)
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials)
    /// * `timeout` - the maximum time this function waits for a response
    pub fn close_credentials_search_timeout(search_handle: IndyHandle, timeout: Duration) -> Result<(), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();

        let err = Prover::_close_credentials_search(command_handle, search_handle, cb);

        ResultHandler::empty_timeout(err, receiver, timeout)
    }

    /// Close credentials search (make search handle invalid)
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials)
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn close_credentials_search_async<F: 'static>(search_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));

        Prover::_close_credentials_search(command_handle, search_handle, cb)
    }

    fn _close_credentials_search(command_handle: IndyHandle, search_handle: IndyHandle, cb: Option<ResponseEmptyCB>) -> ErrorCode {

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_close_credentials_search(command_handle, search_handle, cb)
        })
    }

    /// Gets human readable credentials matching the given proof request.
    ///
    /// NOTE: This method is deprecated because immediately returns all fetched credentials.
    /// Use <Prover::search_credentials_for_proof_req> to fetch records by small batches.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    ///
    /// where
    /// `attr_referent`: Proof-request local identifier of requested attribute
    /// `attr_info`: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `predicate_referent`: Proof-request local identifier of requested attribute predicate
    /// `predicate_info`: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently ">=" only)
    ///         "p_value": int predicate value
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `non_revoc_interval`: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `credentials_json`: json with credentials for the given proof request.
    ///     {
    ///         "requested_attrs": {
    ///             "<attr_referent>": [{ cred_info: <credential_info>, interval: Optional<non_revoc_interval> }],
    ///             ...,
    ///         },
    ///         "requested_predicates": {
    ///             "requested_predicates": [{ cred_info: <credential_info>, timestamp: Optional<integer> }, { cred_info: <credential_2_info>, timestamp: Optional<integer> }],
    ///             "requested_predicate_2_referent": [{ cred_info: <credential_2_info>, timestamp: Optional<integer> }]
    ///         }
    ///     }, where credential is
    ///     {
    ///         "referent": <string>,
    ///         "attrs": {"attr_name" : "attr_raw_value"},
    ///         "schema_id": string,
    ///         "cred_def_id": string,
    ///         "rev_reg_id": Optional<int>,
    ///         "cred_rev_id": Optional<int>,
    ///     }
    pub fn get_credentials_for_proof_req(wallet_handle: IndyHandle, proof_request_json: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_get_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json, cb);

        ResultHandler::one(err, receiver)
    }

    /// Gets human readable credentials matching the given proof request.
    ///
    /// NOTE: This method is deprecated because immediately returns all fetched credentials.
    /// Use <Prover::search_credentials_for_proof_req> to fetch records by small batches.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// where
    /// `attr_referent`: Proof-request local identifier of requested attribute
    /// `attr_info`: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `predicate_referent`: Proof-request local identifier of requested attribute predicate
    /// `predicate_info`: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently ">=" only)
    ///         "p_value": int predicate value
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `non_revoc_interval`: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `credentials_json`: json with credentials for the given proof request.
    ///     {
    ///         "requested_attrs": {
    ///             "<attr_referent>": [{ cred_info: <credential_info>, interval: Optional<non_revoc_interval> }],
    ///             ...,
    ///         },
    ///         "requested_predicates": {
    ///             "requested_predicates": [{ cred_info: <credential_info>, timestamp: Optional<integer> }, { cred_info: <credential_2_info>, timestamp: Optional<integer> }],
    ///             "requested_predicate_2_referent": [{ cred_info: <credential_2_info>, timestamp: Optional<integer> }]
    ///         }
    ///     }, where credential is
    ///     {
    ///         "referent": <string>,
    ///         "attrs": {"attr_name" : "attr_raw_value"},
    ///         "schema_id": string,
    ///         "cred_def_id": string,
    ///         "rev_reg_id": Optional<int>,
    ///         "cred_rev_id": Optional<int>,
    ///     }
    pub fn get_credentials_for_proof_req_timeout(wallet_handle: IndyHandle, proof_request_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_get_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Gets human readable credentials matching the given proof request.
    ///
    /// NOTE: This method is deprecated because immediately returns all fetched credentials.
    /// Use <Prover::search_credentials_for_proof_req> to fetch records by small batches.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `closure` - the closure that is called when finished
    ///
    /// where
    /// `attr_referent`: Proof-request local identifier of requested attribute
    /// `attr_info`: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `predicate_referent`: Proof-request local identifier of requested attribute predicate
    /// `predicate_info`: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently ">=" only)
    ///         "p_value": int predicate value
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `non_revoc_interval`: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn get_credentials_for_proof_req_async<F: 'static>(wallet_handle: IndyHandle, proof_request_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::_get_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json, cb)
    }

    fn _get_credentials_for_proof_req(command_handle: IndyHandle, wallet_handle: IndyHandle, proof_request_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let proof_request_json = c_str!(proof_request_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_get_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json.as_ptr(), cb)
        })
    }

    /// Search for credentials matching the given proof request.
    ///
    /// Instead of immediately returning of fetched credentials
    /// this call returns search_handle that can be used later
    /// to fetch records by small batches (with Prover::fetch_credentials_for_proof_req).
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `extra_query_json`: (Optional) List of extra queries that will be applied to correspondent attribute/predicate:
    ///     {
    ///         "<attr_referent>": <wql query>,
    ///         "<predicate_referent>": <wql query>,
    ///     }
    /// where wql query: indy-sdk/doc/design/011-wallet-query-language/README.md
    ///
    /// where
    /// `attr_referent`: Proof-request local identifier of requested attribute
    /// `attr_info`: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `predicate_referent`: Proof-request local identifier of requested attribute predicate
    /// `predicate_info`: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently ">=" only)
    ///         "p_value": int predicate value
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `non_revoc_interval`: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `search_handle`: Search handle that can be used later to fetch records by small batches (with Prover::fetch_credentials_for_proof_req)
    pub fn search_credentials_for_proof_req(wallet_handle: IndyHandle, proof_request_json: &str, extra_query_json: Option<&str>) -> Result<i32, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();

        let err = Prover::_search_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json, extra_query_json, cb);

        ResultHandler::one(err, receiver)
    }

    /// Search for credentials matching the given proof request.
    ///
    /// Instead of immediately returning of fetched credentials
    /// this call returns search_handle that can be used later
    /// to fetch records by small batches (with Prover::fetch_credentials_for_proof_req).
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `extra_query_json`: (Optional) List of extra queries that will be applied to correspondent attribute/predicate:
    ///     {
    ///         "<attr_referent>": <wql query>,
    ///         "<predicate_referent>": <wql query>,
    ///     }
    /// where wql query: indy-sdk/doc/design/011-wallet-query-language/README.md
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// where
    /// `attr_referent`: Proof-request local identifier of requested attribute
    /// `attr_info`: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `predicate_referent`: Proof-request local identifier of requested attribute predicate
    /// `predicate_info`: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently ">=" only)
    ///         "p_value": int predicate value
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `non_revoc_interval`: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `search_handle`: Search handle that can be used later to fetch records by small batches (with Prover::fetch_credentials_for_proof_req)
    pub fn search_credentials_for_proof_req_timeout(wallet_handle: IndyHandle, proof_request_json: &str, extra_query_json: Option<&str>, timeout: Duration) -> Result<i32, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_i32();

        let err = Prover::_search_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json, extra_query_json, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Search for credentials matching the given proof request.
    ///
    /// Instead of immediately returning of fetched credentials
    /// this call returns search_handle that can be used later
    /// to fetch records by small batches (with Prover::fetch_credentials_for_proof_req).
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `extra_query_json`: (Optional) List of extra queries that will be applied to correspondent attribute/predicate:
    ///     {
    ///         "<attr_referent>": <wql query>,
    ///         "<predicate_referent>": <wql query>,
    ///     }
    /// where wql query: indy-sdk/doc/design/011-wallet-query-language/README.md
    /// * `closure` - the closure that is called when finished
    ///
    /// where
    /// `attr_referent`: Proof-request local identifier of requested attribute
    /// `attr_info`: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `predicate_referent`: Proof-request local identifier of requested attribute predicate
    /// `predicate_info`: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently ">=" only)
    ///         "p_value": int predicate value
    ///         "restrictions": Optional<filter_json>, // see above
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// `non_revoc_interval`: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn search_credentials_for_proof_req_async<F: 'static>(wallet_handle: IndyHandle, proof_request_json: &str, extra_query_json: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, i32) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_i32(Box::new(closure));

        Prover::_search_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json, extra_query_json, cb)
    }

    fn _search_credentials_for_proof_req(command_handle: IndyHandle, wallet_handle: IndyHandle, proof_request_json: &str, extra_query_json: Option<&str>, cb: Option<ResponseI32CB>) -> ErrorCode {
        let proof_request_json = c_str!(proof_request_json);
        let extra_query_json_str = opt_c_str!(extra_query_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_search_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json.as_ptr(), opt_c_ptr!(extra_query_json, extra_query_json_str), cb)
        })
    }

    /// Fetch next credentials for the requested item using proof request search
    /// handle (created by Prover::search_credentials_for_proof_req).
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials_for_proof_req)
    /// * `item_referent`: Referent of attribute/predicate in the proof request
    /// * `count`: Count of credentials to fetch
    ///
    /// # Returns
    /// * `credentials_json`: List of credentials for the given proof request.
    ///     [{
    ///         cred_info: <credential_info>,
    ///         interval: Optional<non_revoc_interval>
    ///     }]
    /// where
    /// `credential_info`:
    ///     {
    ///         "referent": <string>,
    ///         "attrs": {"attr_name" : "attr_raw_value"},
    ///         "schema_id": string,
    ///         "cred_def_id": string,
    ///         "rev_reg_id": Optional<int>,
    ///         "cred_rev_id": Optional<int>,
    ///     }
    /// `non_revoc_interval`:
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    /// NOTE: The list of length less than the requested count means that search iterator
    /// correspondent to the requested <item_referent> is completed.
    pub fn _fetch_credentials_for_proof_req(search_handle: IndyHandle, item_referent: &str, count: usize) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::__fetch_credentials_for_proof_req(command_handle, search_handle, item_referent, count, cb);

        ResultHandler::one(err, receiver)
    }

    /// Fetch next credentials for the requested item using proof request search
    /// handle (created by Prover::search_credentials_for_proof_req).
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials_for_proof_req)
    /// * `item_referent`: Referent of attribute/predicate in the proof request
    /// * `count`: Count of credentials to fetch
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `credentials_json`: List of credentials for the given proof request.
    ///     [{
    ///         cred_info: <credential_info>,
    ///         interval: Optional<non_revoc_interval>
    ///     }]
    /// where
    /// `credential_info`:
    ///     {
    ///         "referent": <string>,
    ///         "attrs": {"attr_name" : "attr_raw_value"},
    ///         "schema_id": string,
    ///         "cred_def_id": string,
    ///         "rev_reg_id": Optional<int>,
    ///         "cred_rev_id": Optional<int>,
    ///     }
    /// `non_revoc_interval`:
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    /// NOTE: The list of length less than the requested count means that search iterator
    /// correspondent to the requested <item_referent> is completed.
    pub fn _fetch_credentials_for_proof_req_timeout(search_handle: IndyHandle, item_referent: &str, count: usize, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::__fetch_credentials_for_proof_req(command_handle, search_handle, item_referent, count, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Fetch next credentials for the requested item using proof request search
    /// handle (created by Prover::search_credentials_for_proof_req).
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials_for_proof_req)
    /// * `item_referent`: Referent of attribute/predicate in the proof request
    /// * `count`: Count of credentials to fetch
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn _fetch_credentials_for_proof_req_async<F: 'static>(search_handle: IndyHandle, item_referent: &str, count: usize, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::__fetch_credentials_for_proof_req(command_handle, search_handle, item_referent, count, cb)
    }

    fn __fetch_credentials_for_proof_req(command_handle: IndyHandle, search_handle: IndyHandle, item_referent: &str, count: usize, cb: Option<ResponseStringCB>) -> ErrorCode {
        let item_referent = c_str!(item_referent);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_fetch_credentials_for_proof_req(command_handle, search_handle, item_referent.as_ptr(), count, cb)
        })
    }

    /// Close credentials search for proof request (make search handle invalid)
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials_for_proof_req)
    pub fn _close_credentials_search_for_proof_req(search_handle: IndyHandle) -> Result<(), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();

        let err = Prover::__close_credentials_search_for_proof_req(command_handle, search_handle, cb);

        ResultHandler::empty(err, receiver)
    }

    /// Close credentials search for proof request (make search handle invalid)
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials_for_proof_req)
    /// * `timeout` - the maximum time this function waits for a response
    pub fn _close_credentials_search_for_proof_req_timeout(search_handle: IndyHandle, timeout: Duration) -> Result<(), ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec();

        let err = Prover::__close_credentials_search_for_proof_req(command_handle, search_handle, cb);

        ResultHandler::empty_timeout(err, receiver, timeout)
    }

    /// Close credentials search for proof request (make search handle invalid)
    ///
    /// # Arguments
    /// * `search_handle`: Search handle (created by Prover::search_credentials_for_proof_req)
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn _close_credentials_search_for_proof_req_async<F: 'static>(search_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));

        Prover::__close_credentials_search_for_proof_req(command_handle, search_handle, cb)
    }

    fn __close_credentials_search_for_proof_req(command_handle: IndyHandle, search_handle: IndyHandle, cb: Option<ResponseEmptyCB>) -> ErrorCode {

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_close_credentials_search_for_proof_req(command_handle, search_handle, cb)
        })
    }

    /// Creates a proof according to the given proof request
    /// Either a corresponding credential with optionally revealed attributes or self-attested attribute must be provided
    /// for each requested attribute (see indy_prover_get_credentials_for_pool_req).
    /// A proof request may request multiple credentials from different schemas and different issuers.
    /// All required schemas, public keys and revocation registries must be provided.
    /// The proof request also contains nonce.
    /// The proof contains either proof or self-attested attribute value for each requested attribute.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `requested_credentials_json`: either a credential or self-attested attribute for each requested attribute
    ///     {
    ///         "self_attested_attributes": {
    ///             "self_attested_attribute_referent": string
    ///         },
    ///         "requested_attributes": {
    ///             "requested_attribute_referent_1": {"cred_id": string, "timestamp": Optional<number>, revealed: <bool> }},
    ///             "requested_attribute_referent_2": {"cred_id": string, "timestamp": Optional<number>, revealed: <bool> }}
    ///         },
    ///         "requested_predicates": {
    ///             "requested_predicates_referent_1": {"cred_id": string, "timestamp": Optional<number> }},
    ///         }
    ///     }
    /// * `master_secret_id`: the id of the master secret stored in the wallet
    /// * `schemas_json`: all schemas json participating in the proof request
    ///     {
    ///         <schema1_id>: <schema1_json>,
    ///         <schema2_id>: <schema2_json>,
    ///         <schema3_id>: <schema3_json>,
    ///     }
    /// * `credential_defs_json`: all credential definitions json participating in the proof request
    ///     {
    ///         "cred_def1_id": <credential_def1_json>,
    ///         "cred_def2_id": <credential_def2_json>,
    ///         "cred_def3_id": <credential_def3_json>,
    ///     }
    /// * `rev_states_json`: all revocation states json participating in the proof request
    ///     {
    ///         "rev_reg_def1_id": {
    ///             "timestamp1": <rev_state1>,
    ///             "timestamp2": <rev_state2>,
    ///         },
    ///         "rev_reg_def2_id": {
    ///             "timestamp3": <rev_state3>
    ///         },
    ///         "rev_reg_def3_id": {
    ///             "timestamp4": <rev_state4>
    ///         },
    ///     }
    ///
    /// where
    /// where wql query: indy-sdk/doc/design/011-wallet-query-language/README.md
    /// attr_referent: Proof-request local identifier of requested attribute
    /// attr_info: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<wql query>,
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// predicate_referent: Proof-request local identifier of requested attribute predicate
    /// predicate_info: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently >= only)
    ///         "p_value": predicate value
    ///         "restrictions": Optional<wql query>,
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// non_revoc_interval: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `proof_json` - proof json
    /// For each requested attribute either a proof (with optionally revealed attribute value) or
    /// self-attested attribute value is provided.
    /// Each proof is associated with a credential and corresponding schema_id, cred_def_id, rev_reg_id and timestamp.
    /// There is also aggregated proof part common for all credential proofs.
    ///     {
    ///         "requested": {
    ///             "revealed_attrs": {
    ///                 "requested_attr1_id": {sub_proof_index: number, raw: string, encoded: string},
    ///                 "requested_attr4_id": {sub_proof_index: number: string, encoded: string},
    ///             },
    ///             "unrevealed_attrs": {
    ///                 "requested_attr3_id": {sub_proof_index: number}
    ///             },
    ///             "self_attested_attrs": {
    ///                 "requested_attr2_id": self_attested_value,
    ///             },
    ///             "requested_predicates": {
    ///                 "requested_predicate_1_referent": {sub_proof_index: int},
    ///                 "requested_predicate_2_referent": {sub_proof_index: int},
    ///             }
    ///         }
    ///         "proof": {
    ///             "proofs": [ <credential_proof>, <credential_proof>, <credential_proof> ],
    ///             "aggregated_proof": <aggregated_proof>
    ///         }
    ///         "identifiers": [{schema_id, cred_def_id, Optional<rev_reg_id>, Optional<timestamp>}]
    ///     }
    pub fn create_proof(wallet_handle: IndyHandle, proof_req_json: &str, requested_credentials_json: &str, master_secret_id: &str, schemas_json: &str, credential_defs_json: &str, rev_states_json: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_create_proof(command_handle, wallet_handle, proof_req_json, requested_credentials_json, master_secret_id, schemas_json, credential_defs_json, rev_states_json, cb);

        ResultHandler::one(err, receiver)
    }

    /// Creates a proof according to the given proof request
    /// Either a corresponding credential with optionally revealed attributes or self-attested attribute must be provided
    /// for each requested attribute (see indy_prover_get_credentials_for_pool_req).
    /// A proof request may request multiple credentials from different schemas and different issuers.
    /// All required schemas, public keys and revocation registries must be provided.
    /// The proof request also contains nonce.
    /// The proof contains either proof or self-attested attribute value for each requested attribute.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `requested_credentials_json`: either a credential or self-attested attribute for each requested attribute
    ///     {
    ///         "self_attested_attributes": {
    ///             "self_attested_attribute_referent": string
    ///         },
    ///         "requested_attributes": {
    ///             "requested_attribute_referent_1": {"cred_id": string, "timestamp": Optional<number>, revealed: <bool> }},
    ///             "requested_attribute_referent_2": {"cred_id": string, "timestamp": Optional<number>, revealed: <bool> }}
    ///         },
    ///         "requested_predicates": {
    ///             "requested_predicates_referent_1": {"cred_id": string, "timestamp": Optional<number> }},
    ///         }
    ///     }
    /// * `master_secret_id`: the id of the master secret stored in the wallet
    /// * `schemas_json`: all schemas json participating in the proof request
    ///     {
    ///         <schema1_id>: <schema1_json>,
    ///         <schema2_id>: <schema2_json>,
    ///         <schema3_id>: <schema3_json>,
    ///     }
    /// * `credential_defs_json`: all credential definitions json participating in the proof request
    ///     {
    ///         "cred_def1_id": <credential_def1_json>,
    ///         "cred_def2_id": <credential_def2_json>,
    ///         "cred_def3_id": <credential_def3_json>,
    ///     }
    /// * `rev_states_json`: all revocation states json participating in the proof request
    ///     {
    ///         "rev_reg_def1_id": {
    ///             "timestamp1": <rev_state1>,
    ///             "timestamp2": <rev_state2>,
    ///         },
    ///         "rev_reg_def2_id": {
    ///             "timestamp3": <rev_state3>
    ///         },
    ///         "rev_reg_def3_id": {
    ///             "timestamp4": <rev_state4>
    ///         },
    ///     }
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// where
    /// where wql query: indy-sdk/doc/design/011-wallet-query-language/README.md
    /// attr_referent: Proof-request local identifier of requested attribute
    /// attr_info: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<wql query>,
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// predicate_referent: Proof-request local identifier of requested attribute predicate
    /// predicate_info: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently >= only)
    ///         "p_value": predicate value
    ///         "restrictions": Optional<wql query>,
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// non_revoc_interval: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `proof_json` - proof json
    /// For each requested attribute either a proof (with optionally revealed attribute value) or
    /// self-attested attribute value is provided.
    /// Each proof is associated with a credential and corresponding schema_id, cred_def_id, rev_reg_id and timestamp.
    /// There is also aggregated proof part common for all credential proofs.
    ///     {
    ///         "requested": {
    ///             "revealed_attrs": {
    ///                 "requested_attr1_id": {sub_proof_index: number, raw: string, encoded: string},
    ///                 "requested_attr4_id": {sub_proof_index: number: string, encoded: string},
    ///             },
    ///             "unrevealed_attrs": {
    ///                 "requested_attr3_id": {sub_proof_index: number}
    ///             },
    ///             "self_attested_attrs": {
    ///                 "requested_attr2_id": self_attested_value,
    ///             },
    ///             "requested_predicates": {
    ///                 "requested_predicate_1_referent": {sub_proof_index: int},
    ///                 "requested_predicate_2_referent": {sub_proof_index: int},
    ///             }
    ///         }
    ///         "proof": {
    ///             "proofs": [ <credential_proof>, <credential_proof>, <credential_proof> ],
    ///             "aggregated_proof": <aggregated_proof>
    ///         }
    ///         "identifiers": [{schema_id, cred_def_id, Optional<rev_reg_id>, Optional<timestamp>}]
    ///     }
    pub fn create_proof_timeout(wallet_handle: IndyHandle, proof_req_json: &str, requested_credentials_json: &str, master_secret_id: &str, schemas_json: &str, credential_defs_json: &str, rev_states_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = Prover::_create_proof(command_handle, wallet_handle, proof_req_json, requested_credentials_json, master_secret_id, schemas_json, credential_defs_json, rev_states_json, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Creates a proof according to the given proof request
    /// Either a corresponding credential with optionally revealed attributes or self-attested attribute must be provided
    /// for each requested attribute (see indy_prover_get_credentials_for_pool_req).
    /// A proof request may request multiple credentials from different schemas and different issuers.
    /// All required schemas, public keys and revocation registries must be provided.
    /// The proof request also contains nonce.
    /// The proof contains either proof or self-attested attribute value for each requested attribute.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `requested_credentials_json`: either a credential or self-attested attribute for each requested attribute
    ///     {
    ///         "self_attested_attributes": {
    ///             "self_attested_attribute_referent": string
    ///         },
    ///         "requested_attributes": {
    ///             "requested_attribute_referent_1": {"cred_id": string, "timestamp": Optional<number>, revealed: <bool> }},
    ///             "requested_attribute_referent_2": {"cred_id": string, "timestamp": Optional<number>, revealed: <bool> }}
    ///         },
    ///         "requested_predicates": {
    ///             "requested_predicates_referent_1": {"cred_id": string, "timestamp": Optional<number> }},
    ///         }
    ///     }
    /// * `master_secret_id`: the id of the master secret stored in the wallet
    /// * `schemas_json`: all schemas json participating in the proof request
    ///     {
    ///         <schema1_id>: <schema1_json>,
    ///         <schema2_id>: <schema2_json>,
    ///         <schema3_id>: <schema3_json>,
    ///     }
    /// * `credential_defs_json`: all credential definitions json participating in the proof request
    ///     {
    ///         "cred_def1_id": <credential_def1_json>,
    ///         "cred_def2_id": <credential_def2_json>,
    ///         "cred_def3_id": <credential_def3_json>,
    ///     }
    /// * `rev_states_json`: all revocation states json participating in the proof request
    ///     {
    ///         "rev_reg_def1_id": {
    ///             "timestamp1": <rev_state1>,
    ///             "timestamp2": <rev_state2>,
    ///         },
    ///         "rev_reg_def2_id": {
    ///             "timestamp3": <rev_state3>
    ///         },
    ///         "rev_reg_def3_id": {
    ///             "timestamp4": <rev_state4>
    ///         },
    ///     }
    /// * `closure` - the closure that is called when finished
    ///
    /// where
    /// where wql query: indy-sdk/doc/design/011-wallet-query-language/README.md
    /// attr_referent: Proof-request local identifier of requested attribute
    /// attr_info: Describes requested attribute
    ///     {
    ///         "name": string, // attribute name, (case insensitive and ignore spaces)
    ///         "restrictions": Optional<wql query>,
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// predicate_referent: Proof-request local identifier of requested attribute predicate
    /// predicate_info: Describes requested attribute predicate
    ///     {
    ///         "name": attribute name, (case insensitive and ignore spaces)
    ///         "p_type": predicate type (Currently >= only)
    ///         "p_value": predicate value
    ///         "restrictions": Optional<wql query>,
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval this attribute
    ///                        // (overrides proof level interval)
    ///     }
    /// non_revoc_interval: Defines non-revocation interval
    ///     {
    ///         "from": Optional<int>, // timestamp of interval beginning
    ///         "to": Optional<int>, // timestamp of interval ending
    ///     }
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_proof_async<F: 'static>(wallet_handle: IndyHandle, proof_req_json: &str, requested_credentials_json: &str, master_secret_id: &str, schemas_json: &str, credential_defs_json: &str, rev_states_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        Prover::_create_proof(command_handle, wallet_handle, proof_req_json, requested_credentials_json, master_secret_id, schemas_json, credential_defs_json, rev_states_json, cb)
    }

    fn _create_proof(command_handle: IndyHandle, wallet_handle: IndyHandle, proof_req_json: &str, requested_credentials_json: &str, master_secret_id: &str, schemas_json: &str, credential_defs_json: &str, rev_states_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let proof_req_json = c_str!(proof_req_json);
        let requested_credentials_json = c_str!(requested_credentials_json);
        let master_secret_id = c_str!(master_secret_id);
        let schemas_json = c_str!(schemas_json);
        let credential_defs_json = c_str!(credential_defs_json);
        let rev_states_json = c_str!(rev_states_json);

        ErrorCode::from(unsafe {
          anoncreds::indy_prover_create_proof(command_handle, wallet_handle, proof_req_json.as_ptr(), requested_credentials_json.as_ptr(), master_secret_id.as_ptr(), schemas_json.as_ptr(), credential_defs_json.as_ptr(), rev_states_json.as_ptr(), cb)
        })
    }
}

pub struct Verifier {}

impl Verifier {
    /// Verifies a proof (of multiple credential).
    /// All required schemas, public keys and revocation registries must be provided.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `proof_json`: created for request proof json
    ///     {
    ///         "requested": {
    ///             "revealed_attrs": {
    ///                 "requested_attr1_id": {sub_proof_index: number, raw: string, encoded: string},
    ///                 "requested_attr4_id": {sub_proof_index: number: string, encoded: string},
    ///             },
    ///             "unrevealed_attrs": {
    ///                 "requested_attr3_id": {sub_proof_index: number}
    ///             },
    ///             "self_attested_attrs": {
    ///                 "requested_attr2_id": self_attested_value,
    ///             },
    ///             "requested_predicates": {
    ///                 "requested_predicate_1_referent": {sub_proof_index: int},
    ///                 "requested_predicate_2_referent": {sub_proof_index: int},
    ///             }
    ///         }
    ///         "proof": {
    ///             "proofs": [ <credential_proof>, <credential_proof>, <credential_proof> ],
    ///             "aggregated_proof": <aggregated_proof>
    ///         }
    ///         "identifiers": [{schema_id, cred_def_id, Optional<rev_reg_id>, Optional<timestamp>}]
    ///     }
    /// * `schemas_json`: all schema jsons participating in the proof
    ///     {
    ///         <schema1_id>: <schema1_json>,
    ///         <schema2_id>: <schema2_json>,
    ///         <schema3_id>: <schema3_json>,
    ///     }
    /// * `credential_defs_json`: all credential definitions json participating in the proof
    ///     {
    ///         "cred_def1_id": <credential_def1_json>,
    ///         "cred_def2_id": <credential_def2_json>,
    ///         "cred_def3_id": <credential_def3_json>,
    ///     }
    /// * `rev_reg_defs_json`: all revocation registry definitions json participating in the proof
    ///     {
    ///         "rev_reg_def1_id": <rev_reg_def1_json>,
    ///         "rev_reg_def2_id": <rev_reg_def2_json>,
    ///         "rev_reg_def3_id": <rev_reg_def3_json>,
    ///     }
    /// * `rev_regs_json`: all revocation registries json participating in the proof
    ///     {
    ///         "rev_reg_def1_id": {
    ///             "timestamp1": <rev_reg1>,
    ///             "timestamp2": <rev_reg2>,
    ///         },
    ///         "rev_reg_def2_id": {
    ///             "timestamp3": <rev_reg3>
    ///         },
    ///         "rev_reg_def3_id": {
    ///             "timestamp4": <rev_reg4>
    ///         },
    ///     }
    ///
    /// # Returns
    /// * `valid`: true - if signature is valid, false - otherwise
    pub fn verify_proof(proof_request_json: &str, proof_json: &str, schemas_json: &str, credential_defs_json: &str, rev_reg_defs_json: &str, rev_regs_json: &str) -> Result<bool, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_bool();

        let err = Verifier::_verify_proof(command_handle, proof_request_json, proof_json, schemas_json, credential_defs_json, rev_reg_defs_json, rev_regs_json, cb);

        ResultHandler::one(err, receiver)
    }

    /// Verifies a proof (of multiple credential).
    /// All required schemas, public keys and revocation registries must be provided.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `proof_json`: created for request proof json
    ///     {
    ///         "requested": {
    ///             "revealed_attrs": {
    ///                 "requested_attr1_id": {sub_proof_index: number, raw: string, encoded: string},
    ///                 "requested_attr4_id": {sub_proof_index: number: string, encoded: string},
    ///             },
    ///             "unrevealed_attrs": {
    ///                 "requested_attr3_id": {sub_proof_index: number}
    ///             },
    ///             "self_attested_attrs": {
    ///                 "requested_attr2_id": self_attested_value,
    ///             },
    ///             "requested_predicates": {
    ///                 "requested_predicate_1_referent": {sub_proof_index: int},
    ///                 "requested_predicate_2_referent": {sub_proof_index: int},
    ///             }
    ///         }
    ///         "proof": {
    ///             "proofs": [ <credential_proof>, <credential_proof>, <credential_proof> ],
    ///             "aggregated_proof": <aggregated_proof>
    ///         }
    ///         "identifiers": [{schema_id, cred_def_id, Optional<rev_reg_id>, Optional<timestamp>}]
    ///     }
    /// * `schemas_json`: all schema jsons participating in the proof
    ///     {
    ///         <schema1_id>: <schema1_json>,
    ///         <schema2_id>: <schema2_json>,
    ///         <schema3_id>: <schema3_json>,
    ///     }
    /// * `credential_defs_json`: all credential definitions json participating in the proof
    ///     {
    ///         "cred_def1_id": <credential_def1_json>,
    ///         "cred_def2_id": <credential_def2_json>,
    ///         "cred_def3_id": <credential_def3_json>,
    ///     }
    /// * `rev_reg_defs_json`: all revocation registry definitions json participating in the proof
    ///     {
    ///         "rev_reg_def1_id": <rev_reg_def1_json>,
    ///         "rev_reg_def2_id": <rev_reg_def2_json>,
    ///         "rev_reg_def3_id": <rev_reg_def3_json>,
    ///     }
    /// * `rev_regs_json`: all revocation registries json participating in the proof
    ///     {
    ///         "rev_reg_def1_id": {
    ///             "timestamp1": <rev_reg1>,
    ///             "timestamp2": <rev_reg2>,
    ///         },
    ///         "rev_reg_def2_id": {
    ///             "timestamp3": <rev_reg3>
    ///         },
    ///         "rev_reg_def3_id": {
    ///             "timestamp4": <rev_reg4>
    ///         },
    ///     }
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `valid`: true - if signature is valid, false - otherwise
    pub fn verify_proof_timeout(proof_request_json: &str, proof_json: &str, schemas_json: &str, credential_defs_json: &str, rev_reg_defs_json: &str, rev_regs_json: &str, timeout: Duration) -> Result<bool, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_bool();

        let err = Verifier::_verify_proof(command_handle, proof_request_json, proof_json, schemas_json, credential_defs_json, rev_reg_defs_json, rev_regs_json, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Verifies a proof (of multiple credential).
    /// All required schemas, public keys and revocation registries must be provided.
    ///
    /// # Arguments
    /// * `wallet_handle`: wallet handler (created by Wallet::open_wallet).
    /// * `proof_request_json`: proof request json
    ///     {
    ///         "name": string,
    ///         "version": string,
    ///         "nonce": string,
    ///         "requested_attributes": { // set of requested attributes
    ///              "<attr_referent>": <attr_info>, // see below
    ///              ...,
    ///         },
    ///         "requested_predicates": { // set of requested predicates
    ///              "<predicate_referent>": <predicate_info>, // see below
    ///              ...,
    ///          },
    ///         "non_revoked": Optional<<non_revoc_interval>>, // see below,
    ///                        // If specified prover must proof non-revocation
    ///                        // for date in this interval for each attribute
    ///                        // (can be overridden on attribute level)
    ///     }
    /// * `proof_json`: created for request proof json
    ///     {
    ///         "requested": {
    ///             "revealed_attrs": {
    ///                 "requested_attr1_id": {sub_proof_index: number, raw: string, encoded: string},
    ///                 "requested_attr4_id": {sub_proof_index: number: string, encoded: string},
    ///             },
    ///             "unrevealed_attrs": {
    ///                 "requested_attr3_id": {sub_proof_index: number}
    ///             },
    ///             "self_attested_attrs": {
    ///                 "requested_attr2_id": self_attested_value,
    ///             },
    ///             "requested_predicates": {
    ///                 "requested_predicate_1_referent": {sub_proof_index: int},
    ///                 "requested_predicate_2_referent": {sub_proof_index: int},
    ///             }
    ///         }
    ///         "proof": {
    ///             "proofs": [ <credential_proof>, <credential_proof>, <credential_proof> ],
    ///             "aggregated_proof": <aggregated_proof>
    ///         }
    ///         "identifiers": [{schema_id, cred_def_id, Optional<rev_reg_id>, Optional<timestamp>}]
    ///     }
    /// * `schemas_json`: all schema jsons participating in the proof
    ///     {
    ///         <schema1_id>: <schema1_json>,
    ///         <schema2_id>: <schema2_json>,
    ///         <schema3_id>: <schema3_json>,
    ///     }
    /// * `credential_defs_json`: all credential definitions json participating in the proof
    ///     {
    ///         "cred_def1_id": <credential_def1_json>,
    ///         "cred_def2_id": <credential_def2_json>,
    ///         "cred_def3_id": <credential_def3_json>,
    ///     }
    /// * `rev_reg_defs_json`: all revocation registry definitions json participating in the proof
    ///     {
    ///         "rev_reg_def1_id": <rev_reg_def1_json>,
    ///         "rev_reg_def2_id": <rev_reg_def2_json>,
    ///         "rev_reg_def3_id": <rev_reg_def3_json>,
    ///     }
    /// * `rev_regs_json`: all revocation registries json participating in the proof
    ///     {
    ///         "rev_reg_def1_id": {
    ///             "timestamp1": <rev_reg1>,
    ///             "timestamp2": <rev_reg2>,
    ///         },
    ///         "rev_reg_def2_id": {
    ///             "timestamp3": <rev_reg3>
    ///         },
    ///         "rev_reg_def3_id": {
    ///             "timestamp4": <rev_reg4>
    ///         },
    ///     }
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn verify_proof_async<F: 'static>(proof_request_json: &str, proof_json: &str, schemas_json: &str, credential_defs_json: &str, rev_reg_defs_json: &str, rev_regs_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, bool) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_bool(Box::new(closure));

        Verifier::_verify_proof(command_handle, proof_request_json, proof_json, schemas_json, credential_defs_json, rev_reg_defs_json, rev_regs_json, cb)
    }

    fn _verify_proof(command_handle: IndyHandle, proof_request_json: &str, proof_json: &str, schemas_json: &str, credential_defs_json: &str, rev_reg_defs_json: &str, rev_regs_json: &str, cb: Option<ResponseBoolCB>) -> ErrorCode {
        let proof_request_json = c_str!(proof_request_json);
        let proof_json = c_str!(proof_json);
        let schemas_json = c_str!(schemas_json);
        let credential_defs_json = c_str!(credential_defs_json);
        let rev_reg_defs_json = c_str!(rev_reg_defs_json);
        let rev_regs_json = c_str!(rev_regs_json);

        ErrorCode::from(unsafe {
            anoncreds::indy_verifier_verify_proof(command_handle, proof_request_json.as_ptr(), proof_json.as_ptr(), schemas_json.as_ptr(), credential_defs_json.as_ptr(), rev_reg_defs_json.as_ptr(), rev_regs_json.as_ptr(), cb)
        })
    }
}

pub struct AnonCreds {}

impl AnonCreds {
    /// Create revocation state for a credential in the particular time moment.
    ///
    /// # Arguments
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_reg_def_json`: revocation registry definition json
    /// * `rev_reg_delta_json`: revocation registry definition delta json
    /// * `timestamp`: time represented as a total number of seconds from Unix Epoch
    /// * `cred_rev_id`: user credential revocation id in revocation registry
    ///
    /// # Returns
    /// * `revocation_state_json`:
    /// {
    ///     "rev_reg": <revocation registry>,
    ///     "witness": <witness>,
    ///     "timestamp" : integer
    /// }
    pub fn create_revocation_state(blob_storage_reader_handle: IndyHandle, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = AnonCreds::_create_revocation_state(command_handle, blob_storage_reader_handle, rev_reg_def_json, rev_reg_delta_json, timestamp, cred_rev_id, cb);

        ResultHandler::one(err, receiver)
    }

    /// Create revocation state for a credential in the particular time moment.
    ///
    /// # Arguments
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_reg_def_json`: revocation registry definition json
    /// * `rev_reg_delta_json`: revocation registry definition delta json
    /// * `timestamp`: time represented as a total number of seconds from Unix Epoch
    /// * `cred_rev_id`: user credential revocation id in revocation registry
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `revocation_state_json`:
    /// {
    ///     "rev_reg": <revocation registry>,
    ///     "witness": <witness>,
    ///     "timestamp" : integer
    /// }
    pub fn create_revocation_state_timeout(blob_storage_reader_handle: IndyHandle, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = AnonCreds::_create_revocation_state(command_handle, blob_storage_reader_handle, rev_reg_def_json, rev_reg_delta_json, timestamp, cred_rev_id, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Create revocation state for a credential in the particular time moment.
    ///
    /// # Arguments
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_reg_def_json`: revocation registry definition json
    /// * `rev_reg_delta_json`: revocation registry definition delta json
    /// * `timestamp`: time represented as a total number of seconds from Unix Epoch
    /// * `cred_rev_id`: user credential revocation id in revocation registry
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn create_revocation_state_async<F: 'static>(blob_storage_reader_handle: IndyHandle, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        AnonCreds::_create_revocation_state(command_handle, blob_storage_reader_handle, rev_reg_def_json, rev_reg_delta_json, timestamp, cred_rev_id, cb)
    }

    fn _create_revocation_state(command_handle: IndyHandle, blob_storage_reader_handle: IndyHandle, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let rev_reg_def_json = c_str!(rev_reg_def_json);
        let rev_reg_delta_json = c_str!(rev_reg_delta_json);
        let cred_rev_id = c_str!(cred_rev_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_create_revocation_state(command_handle, blob_storage_reader_handle, rev_reg_def_json.as_ptr(), rev_reg_delta_json.as_ptr(), timestamp, cred_rev_id.as_ptr(), cb)
        })
    }

    /// Create new revocation state for a credential based on existed state
    /// at the particular time moment (to reduce calculation time).
    ///
    /// # Arguments
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_state_json`: revocation registry state json
    /// * `rev_reg_def_json`: revocation registry definition json
    /// * `rev_reg_delta_json`: revocation registry definition delta json
    /// * `timestamp`: time represented as a total number of seconds from Unix Epoch
    /// * `cred_rev_id`: user credential revocation id in revocation registry
    ///
    /// # Returns
    /// * `revocation_state_json`:
    /// {
    ///     "rev_reg": <revocation registry>,
    ///     "witness": <witness>,
    ///     "timestamp" : integer
    /// }
    pub fn update_revocation_state(blob_storage_reader_handle: IndyHandle, rev_state_json: &str, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = AnonCreds::_update_revocation_state(command_handle, blob_storage_reader_handle, rev_state_json, rev_reg_def_json, rev_reg_delta_json, timestamp, cred_rev_id, cb);

        ResultHandler::one(err, receiver)
    }

    /// Create new revocation state for a credential based on existed state
    /// at the particular time moment (to reduce calculation time).
    ///
    /// # Arguments
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_state_json`: revocation registry state json
    /// * `rev_reg_def_json`: revocation registry definition json
    /// * `rev_reg_delta_json`: revocation registry definition delta json
    /// * `timestamp`: time represented as a total number of seconds from Unix Epoch
    /// * `cred_rev_id`: user credential revocation id in revocation registry
    /// * `timeout` - the maximum time this function waits for a response
    ///
    /// # Returns
    /// * `revocation_state_json`:
    /// {
    ///     "rev_reg": <revocation registry>,
    ///     "witness": <witness>,
    ///     "timestamp" : integer
    /// }
    pub fn update_revocation_state_timeout(blob_storage_reader_handle: IndyHandle, rev_state_json: &str, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str, timeout: Duration) -> Result<String, ErrorCode> {
        let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();

        let err = AnonCreds::_update_revocation_state(command_handle, blob_storage_reader_handle, rev_state_json, rev_reg_def_json, rev_reg_delta_json, timestamp, cred_rev_id, cb);

        ResultHandler::one_timeout(err, receiver, timeout)
    }

    /// Create new revocation state for a credential based on existed state
    /// at the particular time moment (to reduce calculation time).
    ///
    /// # Arguments
    /// * `blob_storage_reader_handle`: configuration of blob storage reader handle that will allow to read revocation tails
    /// * `rev_state_json`: revocation registry state json
    /// * `rev_reg_def_json`: revocation registry definition json
    /// * `rev_reg_delta_json`: revocation registry definition delta json
    /// * `timestamp`: time represented as a total number of seconds from Unix Epoch
    /// * `cred_rev_id`: user credential revocation id in revocation registry
    /// * `closure` - the closure that is called when finished
    ///
    /// # Returns
    /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
    pub fn update_revocation_state_async<F: 'static>(blob_storage_reader_handle: IndyHandle, rev_state_json: &str, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
        let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));

        AnonCreds::_update_revocation_state(command_handle, blob_storage_reader_handle, rev_state_json, rev_reg_def_json, rev_reg_delta_json, timestamp, cred_rev_id, cb)
    }

    fn _update_revocation_state(command_handle: IndyHandle, blob_storage_reader_handle: IndyHandle, rev_state_json: &str, rev_reg_def_json: &str, rev_reg_delta_json: &str, timestamp: u64, cred_rev_id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
        let rev_state_json = c_str!(rev_state_json);
        let rev_reg_def_json = c_str!(rev_reg_def_json);
        let rev_reg_delta_json = c_str!(rev_reg_delta_json);
        let cred_rev_id = c_str!(cred_rev_id);

        ErrorCode::from(unsafe {
          anoncreds::indy_update_revocation_state(command_handle, blob_storage_reader_handle, rev_state_json.as_ptr(), rev_reg_def_json.as_ptr(), rev_reg_delta_json.as_ptr(), timestamp, cred_rev_id.as_ptr(), cb)
        })
    }
}