summaryrefslogtreecommitdiff
path: root/core/api-exchange.rst
blob: 4c5be000e38f8696fde4355c312844460f22678c (plain)
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
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
..
  This file is part of GNU TALER.
  Copyright (C) 2014-2024 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 2.1, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>

  @author Christian Grothoff

========================
The Exchange RESTful API
========================

The API specified here follows the :ref:`general conventions <http-common>`
for all details not specified in the individual requests.
The `glossary <https://docs.taler.net/glossary.html#glossary>`_
defines all specific terms used in this section.

.. contents:: Table of Contents
  :local:

.. include:: tos.rst

.. _keys:

---------------------------
Exchange status information
---------------------------

This API is used by wallets and merchants to obtain global information about
the exchange, such as online signing keys, available denominations and the fee
structure.  This is typically the first call any exchange client makes, as it
returns information required to process all of the other interactions with the
exchange.  The returned information is secured by (1) signature(s) from the exchange,
especially the long-term offline signing key of the exchange, which clients should
cache; (2) signature(s) from auditors, and the auditor keys should be
hard-coded into the wallet as they are the trust anchors for Taler; (3)
possibly by using HTTPS.


.. http:get:: /seed

  Return an entropy seed. The exchange will return a high-entropy
  value that will differ for every call.  The response is NOT in
  JSON, but simply high-entropy binary data in the HTTP body.
  This API should be used by wallets to guard themselves against
  running on low-entropy (bad PRNG) hardware. Naturally, the entropy
  returned MUST be mixed with locally generated entropy.


.. http:get:: /config

  Return the protocol version and currency supported by this exchange backend,
  as well as the list of possible KYC requirements.  This endpoint is largely
  for the SPA for AML officers. Merchants should use ``/keys`` which also
  contains the protocol version and currency.
  This specification corresponds to ``current`` protocol being **v19**.

  **Response:**

  :http:statuscode:`200 OK`:
    The body is a `VersionResponse`.

  .. ts:def:: ExchangeVersionResponse

    interface ExchangeVersionResponse {
      // libtool-style representation of the Exchange protocol version, see
      // https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning
      // The format is "current:revision:age".
      version: string;

      // Name of the protocol.
      name: "taler-exchange";

      // URN of the implementation (needed to interpret 'revision' in version).
      // @since **v18**, may become mandatory in the future.
      implementation?: string;

      // Currency supported by this exchange, given
      // as a currency code ("USD" or "EUR").
      currency: string;

      // How wallets should render this currency.
      currency_specification: CurrencySpecification;

      // Names of supported KYC requirements.
      supported_kyc_requirements: string[];

    }

  .. ts:def:: CurrencySpecification

    interface CurrencySpecification {
      // Name of the currency. Like "US Dollar".
      name: string;

      // Code of the currency.
      // Deprecated in protocol **v18** for the exchange
      // and in protocol v6 for the merchant.
      currency: string;

      // how many digits the user may enter after the decimal_separator
      num_fractional_input_digits: Integer;

      // Number of fractional digits to render in normal font and size.
      num_fractional_normal_digits: Integer;

      // Number of fractional digits to render always, if needed by
      // padding with zeros.
      num_fractional_trailing_zero_digits: Integer;

      // map of powers of 10 to alternative currency names / symbols, must
      // always have an entry under "0" that defines the base name,
      // e.g.  "0 => €" or "3 => k€". For BTC, would be "0 => BTC, -3 => mBTC".
      // Communicates the currency symbol to be used.
      alt_unit_names: { log10 : string };
    }


.. http:get:: /keys

  Get a list of all denomination keys offered by the exchange,
  as well as the exchange's current online signing key.

  **Request:**

  :query last_issue_date: Optional argument specifying the maximum value of any of the ``stamp_start`` members of the denomination keys of a ``/keys`` response that is already known to the client. Allows the exchange to only return keys that have changed since that timestamp.  The given value must be an unsigned 64-bit integer representing seconds after 1970.  If the timestamp does not exactly match the ``stamp_start`` of one of the denomination keys, all keys are returned.

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `ExchangeKeysResponse` object. This request should
    virtually always be successful. It only fails if the exchange is misconfigured or
    has not yet been provisioned with key signatures via ``taler-exchange-offline``.

  **Details:**

  .. ts:def:: ExchangeKeysResponse

    interface ExchangeKeysResponse {
      // libtool-style representation of the Exchange protocol version, see
      // https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning
      // The format is "current:revision:age".
      version: string;

      // The exchange's base URL.
      base_url: string;

      // The exchange's currency or asset unit.
      currency: string;

      // How wallets should render this currency.
      currency_specification: CurrencySpecification;

      // Absolute cost offset for the STEFAN curve used
      // to (over) approximate fees payable by amount.
      stefan_abs: Amount;

      // Factor to multiply the logarithm of the amount
      // with to (over) approximate fees payable by amount.
      // Note that the total to be paid is first to be
      // divided by the smallest denomination to obtain
      // the value that the logarithm is to be taken of.
      stefan_log: Amount;

      // Linear cost factor for the STEFAN curve used
      // to (over) approximate fees payable by amount.
      //
      // Note that this is a scalar, as it is multiplied
      // with the actual amount.
      stefan_lin: Float;

      // Type of the asset. "fiat", "crypto", "regional"
      // or "stock".  Wallets should adjust their UI/UX
      // based on this value.
      asset_type: string;

      // Array of wire accounts operated by the exchange for
      // incoming wire transfers.
      accounts: WireAccount[];

      // Object mapping names of wire methods (i.e. "iban" or "x-taler-bank")
      // to wire fees.
      wire_fees: { method : AggregateTransferFee[] };

      // List of exchanges that this exchange is partnering
      // with to enable wallet-to-wallet transfers.
      wads: ExchangePartner[];

      // Set to true if this exchange allows the use
      // of reserves for rewards.
      // @deprecated in protocol **v18**.
      rewards_allowed: false;

      // EdDSA master public key of the exchange, used to sign entries
      // in ``denoms`` and ``signkeys``.
      master_public_key: EddsaPublicKey;

      // Relative duration until inactive reserves are closed;
      // not signed (!), can change without notice.
      reserve_closing_delay: RelativeTime;

      // Threshold amounts beyond which wallet should
      // trigger the KYC process of the issuing
      // exchange.  Optional option, if not given there is no limit.
      // Currency must match ``currency``.
      wallet_balance_limit_without_kyc?: Amount[];

      // Denominations offered by this exchange
      denominations: DenomGroup[];

      // Compact EdDSA `signature` (binary-only) over the
      // contatentation of all of the master_sigs (in reverse
      // chronological order by group) in the arrays under
      // "denominations".  Signature of `TALER_ExchangeKeySetPS`
      exchange_sig: EddsaSignature;

      // Public EdDSA key of the exchange that was used to generate the signature.
      // Should match one of the exchange's signing keys from ``signkeys``.  It is given
      // explicitly as the client might otherwise be confused by clock skew as to
      // which signing key was used for the ``exchange_sig``.
      exchange_pub: EddsaPublicKey;

      // Denominations for which the exchange currently offers/requests recoup.
      recoup: Recoup[];

      // Array of globally applicable fees by time range.
      global_fees: GlobalFees[];

      // The date when the denomination keys were last updated.
      list_issue_date: Timestamp;

      // Auditors of the exchange.
      auditors: AuditorKeys[];

      // The exchange's signing keys.
      signkeys: SignKey[];

      // Optional field with a dictionary of (name, object) pairs defining the
      // supported and enabled extensions, such as ``age_restriction``.
      extensions?: { name: ExtensionManifest };

      // Signature by the exchange master key of the SHA-256 hash of the
      // normalized JSON-object of field extensions, if it was set.
      // The signature has purpose TALER_SIGNATURE_MASTER_EXTENSIONS.
      extensions_sig?: EddsaSignature;

    }

  The specification for the account object is:

  .. ts:def:: WireAccount

    interface WireAccount {
      // ``payto://`` URI identifying the account and wire method
      payto_uri: string;

      // URI to convert amounts from or to the currency used by
      // this wire account of the exchange. Missing if no
      // conversion is applicable.
      conversion_url?: string;

      // Restrictions that apply to bank accounts that would send
      // funds to the exchange (crediting this exchange bank account).
      // Optional, empty array for unrestricted.
      credit_restrictions: AccountRestriction[];

      // Restrictions that apply to bank accounts that would receive
      // funds from the exchange (debiting this exchange bank account).
      // Optional, empty array for unrestricted.
      debit_restrictions: AccountRestriction[];

      // Signature using the exchange's offline key over
      // a `TALER_MasterWireDetailsPS`
      // with purpose ``TALER_SIGNATURE_MASTER_WIRE_DETAILS``.
      master_sig: EddsaSignature;

      // Display label wallets should use to show this
      // bank account.
      // Since protocol **v19**.
      bank_label?: string;

      // *Signed* integer with the display priority for
      // this bank account. Optional, 0 if missing.
      // Since protocol **v19**.
      priority?: Integer;

    }

  .. ts:def:: AccountRestriction

    type AccountRestriction =
      | RegexAccountRestriction
      | DenyAllAccountRestriction

  .. ts:def:: DenyAllAccountRestriction

    // Account restriction that disables this type of
    // account for the indicated operation categorically.
    interface DenyAllAccountRestriction {

      type: "deny";
    }

  .. ts:def:: RegexAccountRestriction

    // Accounts interacting with this type of account
    // restriction must have a payto://-URI matching
    // the given regex.
    interface RegexAccountRestriction {

      type: "regex";

      // Regular expression that the payto://-URI of the
      // partner account must follow.  The regular expression
      // should follow posix-egrep, but without support for character
      // classes, GNU extensions, back-references or intervals. See
      // https://www.gnu.org/software/findutils/manual/html_node/find_html/posix_002degrep-regular-expression-syntax.html
      // for a description of the posix-egrep syntax. Applications
      // may support regexes with additional features, but exchanges
      // must not use such regexes.
      payto_regex: string;

      // Hint for a human to understand the restriction
      // (that is hopefully easier to comprehend than the regex itself).
      human_hint: string;

      // Map from IETF BCP 47 language tags to localized
      // human hints.
      human_hint_i18n?: { [lang_tag: string]: string };

    }

  .. ts:def:: GlobalFees

    interface GlobalFees {

      // What date (inclusive) does these fees go into effect?
      start_date: Timestamp;

      // What date (exclusive) does this fees stop going into effect?
      end_date: Timestamp;

      // Account history fee, charged when a user wants to
      // obtain a reserve/account history.
      history_fee: Amount;

      // Annual fee charged for having an open account at the
      // exchange.  Charged to the account.  If the account
      // balance is insufficient to cover this fee, the account
      // is automatically deleted/closed. (Note that the exchange
      // will keep the account history around for longer for
      // regulatory reasons.)
      account_fee: Amount;

      // Purse fee, charged only if a purse is abandoned
      // and was not covered by the account limit.
      purse_fee: Amount;

      // How long will the exchange preserve the account history?
      // After an account was deleted/closed, the exchange will
      // retain the account history for legal reasons until this time.
      history_expiration: RelativeTime;

      // Non-negative number of concurrent purses that any
      // account holder is allowed to create without having
      // to pay the purse_fee.
      purse_account_limit: Integer;

      // How long does an exchange keep a purse around after a purse
      // has expired (or been successfully merged)?  A 'GET' request
      // for a purse will succeed until the purse expiration time
      // plus this value.
      purse_timeout: RelativeTime;

      // Signature of `TALER_GlobalFeesPS`.
      master_sig: EddsaSignature;

    }

  .. ts:def:: AgeMask

    // Binary representation of the age groups.
    // The bits set in the mask mark the edges at the beginning of a next age
    // group.  F.e. for the age groups
    //     0-7, 8-9, 10-11, 12-13, 14-15, 16-17, 18-21, 21-*
    // the following bits are set:
    //
    //   31     24        16        8         0
    //   |      |         |         |         |
    //   oooooooo  oo1oo1o1  o1o1o1o1  ooooooo1
    //
    // A value of 0 means that the exchange does not support the extension for
    // age-restriction.
    type AgeMask = Integer;

  .. ts:def:: DenomGroup

    type DenomGroup =
      | DenomGroupRsa
      | DenomGroupCs
      | DenomGroupRsaAgeRestricted
      | DenomGroupCsAgeRestricted;

  .. ts:def:: DenomGroupRsa

    interface DenomGroupRsa extends DenomGroupCommon {
      cipher: "RSA";

      denoms: ({
        rsa_pub: RsaPublicKey;
      } & DenomCommon)[];
    }

  .. ts:def:: DenomGroupCs

    interface DenomGroupCs extends DenomGroupCommon {
      cipher: "CS";

      denoms: ({
        cs_pub: Cs25519Point;
      } & DenomCommon)[];
    }

  .. ts:def:: DenomGroupRsaAgeRestricted

    interface DenomGroupRsaAgeRestricted extends DenomGroupCommon {
      cipher: "RSA+age_restricted";
      age_mask: AgeMask;

      denoms: ({
        rsa_pub: RsaPublicKey;
      } & DenomCommon)[];
    }

  .. ts:def:: DenomGroupCsAgeRestricted

    interface DenomGroupCSAgeRestricted extends DenomGroupCommon {
      cipher: "CS+age_restricted";
      age_mask: AgeMask;

      denoms: ({
        cs_pub: Cs25519Point;
      } & DenomCommon)[];
    }

  .. ts:def:: DenomGroupCommon

    // Common attributes for all denomination groups
    interface DenomGroupCommon {
      // How much are coins of this denomination worth?
      value: Amount;

      // Fee charged by the exchange for withdrawing a coin of this denomination.
      fee_withdraw: Amount;

      // Fee charged by the exchange for depositing a coin of this denomination.
      fee_deposit: Amount;

      // Fee charged by the exchange for refreshing a coin of this denomination.
      fee_refresh: Amount;

      // Fee charged by the exchange for refunding a coin of this denomination.
      fee_refund: Amount;

    }

  .. ts:def:: DenomCommon

    interface DenomCommon {
      // Signature of `TALER_DenominationKeyValidityPS`.
      master_sig: EddsaSignature;

      // When does the denomination key become valid?
      stamp_start: Timestamp;

      // When is it no longer possible to withdraw coins
      // of this denomination?
      stamp_expire_withdraw: Timestamp;

      // When is it no longer possible to deposit coins
      // of this denomination?
      stamp_expire_deposit: Timestamp;

      // Timestamp indicating by when legal disputes relating to these coins must
      // be settled, as the exchange will afterwards destroy its evidence relating to
      // transactions involving this coin.
      stamp_expire_legal: Timestamp;

      // Set to 'true' if the exchange somehow "lost"
      // the private key. The denomination was not
      // necessarily revoked, but still cannot be used
      // to withdraw coins at this time (theoretically,
      // the private key could be recovered in the
      // future; coins signed with the private key
      // remain valid).
      lost?: boolean;
    }

  .. ts:def:: DenominationKey

    type DenominationKey =
      | RsaDenominationKey
      | CSDenominationKey;

  .. ts:def:: RsaDenominationKey

    interface RsaDenominationKey {
      cipher: "RSA";

      // 32-bit age mask.
      age_mask: Integer;

      // RSA public key
      rsa_public_key: RsaPublicKey;
    }

  .. ts:def:: CSDenominationKey

    interface CSDenominationKey {
      cipher: "CS";

      // 32-bit age mask.
      age_mask: Integer;

      // Public key of the denomination.
      cs_public_key: Cs25519Point;

    }

  Fees for any of the operations can be zero, but the fields must still be
  present. The currency of the ``fee_deposit``, ``fee_refresh`` and ``fee_refund`` must match the
  currency of the ``value``.  Theoretically, the ``fee_withdraw`` could be in a
  different currency, but this is not currently supported by the
  implementation.

  .. ts:def:: Recoup

    interface Recoup {
      // Hash of the public key of the denomination that is being revoked under
      // emergency protocol (see ``/recoup``).
      h_denom_pub: HashCode;

      // We do not include any signature here, as the primary use-case for
      // this emergency involves the exchange having lost its signing keys,
      // so such a signature here would be pretty worthless.  However, the
      // exchange will not honor ``/recoup`` requests unless they are for
      // denomination keys listed here.
    }

  A signing key in the ``signkeys`` list is a JSON object with the following fields:

  .. ts:def:: SignKey

    interface SignKey {
      // The actual exchange's EdDSA signing public key.
      key: EddsaPublicKey;

      // Initial validity date for the signing key.
      stamp_start: Timestamp;

      // Date when the exchange will stop using the signing key, allowed to overlap
      // slightly with the next signing key's validity to allow for clock skew.
      stamp_expire: Timestamp;

      // Date when all signatures made by the signing key expire and should
      // henceforth no longer be considered valid in legal disputes.
      stamp_end: Timestamp;

      // Signature over ``key`` and ``stamp_expire`` by the exchange master key.
      // Signature of `TALER_ExchangeSigningKeyValidityPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY``.
      master_sig: EddsaSignature;
    }

  An entry in the ``auditors`` list is a JSON object with the following fields:

  .. ts:def:: AuditorKeys

    interface AuditorKeys {
      // The auditor's EdDSA signing public key.
      auditor_pub: EddsaPublicKey;

      // The auditor's URL.
      auditor_url: string;

      // The auditor's name (for humans).
      auditor_name: string;

      // An array of denomination keys the auditor affirms with its signature.
      // Note that the message only includes the hash of the public key, while the
      // signature is actually over the expanded information including expiration
      // times and fees.  The exact format is described below.
      denomination_keys: AuditorDenominationKey[];
    }

  .. ts:def:: AuditorDenominationKey

    interface AuditorDenominationKey {
      // Hash of the public RSA key used to sign coins of the respective
      // denomination.  Note that the auditor's signature covers more than just
      // the hash, but this other information is already provided in ``denoms`` and
      // thus not repeated here.
      denom_pub_h: HashCode;

      // Signature of `TALER_ExchangeKeyValidityPS`.
      auditor_sig: EddsaSignature;
    }

  The same auditor may appear multiple times in the array for different subsets
  of denomination keys, and the same denomination key hash may be listed
  multiple times for the same or different auditors.  The wallet or merchant
  just should check that the denomination keys they use are in the set for at
  least one of the auditors that they accept.

  .. note::

    Both the individual denominations *and* the denomination list is signed,
    allowing customers to prove that they received an inconsistent list.

  Aggregate wire transfer fees representing the fees the exchange
  charges per wire transfer to a merchant must be specified as an
  array in all wire transfer response objects under ``fees``.  The
  respective array contains objects with the following members:

  .. ts:def:: AggregateTransferFee

    interface AggregateTransferFee {
      // Per transfer wire transfer fee.
      wire_fee: Amount;

      // Per transfer closing fee.
      closing_fee: Amount;

      // What date (inclusive) does this fee go into effect?
      // The different fees must cover the full time period in which
      // any of the denomination keys are valid without overlap.
      start_date: Timestamp;

      // What date (exclusive) does this fee stop going into effect?
      // The different fees must cover the full time period in which
      // any of the denomination keys are valid without overlap.
      end_date: Timestamp;

      // Signature of `TALER_MasterWireFeePS` with
      // purpose ``TALER_SIGNATURE_MASTER_WIRE_FEES``.
      sig: EddsaSignature;
    }

  .. ts:def:: ExchangePartner

    interface ExchangePartner {
      // Base URL of the partner exchange.
      partner_base_url: string;

      // Public master key of the partner exchange.
      partner_master_pub: EddsaPublicKey;

      // Per exchange-to-exchange transfer (wad) fee.
      wad_fee: Amount;

      // Exchange-to-exchange wad (wire) transfer frequency.
      wad_frequency: RelativeTime;

      // When did this partnership begin (under these conditions)?
      start_date: Timestamp;

      // How long is this partnership expected to last?
      end_date: Timestamp;

      // Signature using the exchange's offline key over
      // `TALER_WadPartnerSignaturePS`
      // with purpose ``TALER_SIGNATURE_MASTER_PARTNER_DETAILS``.
      master_sig: EddsaSignature;
    }




----------------------------------------------
Management operations authorized by master key
----------------------------------------------

.. http:get:: /management/keys

  Get a list of future public keys to be used by the exchange.  Only to be
  used by the exchange's offline key management team. Not useful for anyone
  else (but also not secret, so access is public).

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `FutureKeysResponse` object. This request should
    virtually always be successful.

  **Details:**

  .. ts:def:: FutureKeysResponse

    interface FutureKeysResponse {

      // Future denominations to be offered by this exchange
      // (only those lacking a master signature).
      future_denoms: FutureDenom[];

      // The exchange's future signing keys (only those lacking a master signature).
      future_signkeys: FutureSignKey[];

      // Master public key expected by this exchange (provided so that the
      // offline signing tool can check that it has the right key).
      master_pub: EddsaPublicKey;

      // Public key of the denomination security module.
      denom_secmod_public_key: EddsaPublicKey;

      // Public key of the signkey security module.
      signkey_secmod_public_key: EddsaPublicKey;

    }

  .. ts:def:: FutureDenom

    interface FutureDenom {
      // Name in the configuration file that defines this denomination.
      section_name: string;

      // How much are coins of this denomination worth?
      value: Amount;

      // When does the denomination key become valid?
      stamp_start: Timestamp;

      // When is it no longer possible to withdraw coins
      // of this denomination?
      stamp_expire_withdraw: Timestamp;

      // When is it no longer possible to deposit coins
      // of this denomination?
      stamp_expire_deposit: Timestamp;

      // Timestamp indicating by when legal disputes relating to these coins must
      // be settled, as the exchange will afterwards destroy its evidence relating to
      // transactions involving this coin.
      stamp_expire_legal: Timestamp;

      // Public key for the denomination.
      denom_pub: DenominationKey;

      // Fee charged by the exchange for withdrawing a coin of this denomination.
      fee_withdraw: Amount;

      // Fee charged by the exchange for depositing a coin of this denomination.
      fee_deposit: Amount;

      // Fee charged by the exchange for refreshing a coin of this denomination.
      fee_refresh: Amount;

      // Fee charged by the exchange for refunding a coin of this denomination.
      fee_refund: Amount;

      // Signature by the denomination security module
      // over `TALER_DenominationKeyAnnouncementPS`
      // for this denomination with purpose
      // ``TALER_SIGNATURE_SM_DENOMINATION_KEY``.
      denom_secmod_sig: EddsaSignature;

    }

  .. ts:def:: FutureSignKey

    interface SignKey {
      // The actual exchange's EdDSA signing public key.
      key: EddsaPublicKey;

      // Initial validity date for the signing key.
      stamp_start: Timestamp;

      // Date when the exchange will stop using the signing key, allowed to overlap
      // slightly with the next signing key's validity to allow for clock skew.
      stamp_expire: Timestamp;

      // Date when all signatures made by the signing key expire and should
      // henceforth no longer be considered valid in legal disputes.
      stamp_end: Timestamp;

      // Signature over `TALER_SigningKeyAnnouncementPS`
      // for this signing key by the signkey security
      // module using purpose ``TALER_SIGNATURE_SM_SIGNING_KEY``.
      signkey_secmod_sig: EddsaSignature;
    }


.. http:post:: /management/keys

  Provide master signatures for future public keys to be used by the exchange.
  Only to be used by the exchange's offline key management team. Not useful
  for anyone else.

  **Request:** The request body must be a `MasterSignatures` object.

  **Response:**

  :http:statuscode:`204 No content`:
    The request was successfully processed.
  :http:statuscode:`403 Forbidden`:
    A provided signature is invalid.
  :http:statuscode:`404 Not found`:
    One of the keys for which a signature was provided is unknown to the exchange.

  **Details:**

  .. ts:def:: MasterSignatures

    interface MasterSignatures {

      // Provided master signatures for future denomination keys.
      denom_sigs: DenomSignature[];

      // Provided master signatures for future online signing keys.
      signkey_sigs: SignKeySignature[];

    }

  .. ts:def:: DenomSignature

    interface DenomSignature {

      // Hash of the public key of the denomination.
      h_denom_pub: HashCode;

      // Signature over `TALER_DenominationKeyValidityPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY``
      master_sig: EddsaSignature;

    }

  .. ts:def:: SignKeySignature

    interface SignKeySignature {
      // The actual exchange's EdDSA signing public key.
      key: EddsaPublicKey;

      // Signature by the exchange master key over
      // `TALER_ExchangeSigningKeyValidityPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY``.
      master_sig: EddsaSignature;

    }


.. http:post:: /management/denominations/$H_DENOM_PUB/revoke

  Revoke denomination key, preventing further use by the exchange.
  Only to be used by the exchange's offline key management team. Not useful
  for anyone else.

  **Request:** The request body must be a `DenomRevocationSignature` object.

  **Response:**

  :http:statuscode:`204 No content`:
    The request was successfully processed.
  :http:statuscode:`403 Forbidden`:
    The provided signature is invalid.

  **Details:**

  .. ts:def:: DenomRevocationSignature

    interface DenomRevocationSignature {

      // Signature by the exchange master key over a
      // `TALER_MasterDenominationKeyRevocationPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED``.
      master_sig: EddsaSignature;

    }

.. http:post:: /management/signkeys/$EXCHANGE_PUB/revoke

  Revoke exchange online signing key, preventing further use by the exchange.
  Only to be used by the exchange's offline key management team. Not useful
  for anyone else.

  **Request:** The request body must be a `SignkeyRevocationSignature` object.

  **Response:**

  :http:statuscode:`204 No content`:
    The request was successfully processed.
  :http:statuscode:`403 Forbidden`:
    The provided signature is invalid.

  **Details:**

  .. ts:def:: SignkeyRevocationSignature

    interface SignkeyRevocationSignature {

      // Signature by the exchange master key over a
      // `TALER_MasterSigningKeyRevocationPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_SIGN_KEY_REVOKED``.
      master_sig: EddsaSignature;

    }


.. http:post:: /management/auditors

  This request will be used to enable an auditor.

  **Request:**

  The request must be a `AuditorSetupMessage`.

  **Response:**

  :http:statuscode:`204 No content`:
    The auditor was successfully enabled.
  :http:statuscode:`403 Forbidden`:
    The master signature is invalid.
  :http:statuscode:`409 Conflict`:
    The exchange has a more recent request related to this auditor key (replay detected).

  **Details:**

  .. ts:def:: AuditorSetupMessage

    interface AuditorSetupMessage {

      // Base URL of the auditor.
      auditor_url: string;

      // Human-readable name of the auditor.
      auditor_name: string;

      // The auditor's EdDSA signing public key.
      auditor_pub: EddsaPublicKey;

      // Signature by the exchange master ke yover a
      // `TALER_MasterAddAuditorPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_ADD_AUDITOR``.
      master_sig: EddsaSignature;

      // When does the auditor become active?
      // Should be the time when the signature was created,
      // using the (monotonic!) local time of the system
      // with the offline master public key. Note that
      // even if the time is in the future, the auditor will
      // become active immediately! Used ONLY to detect replay attacks.
      validity_start: Timestamp;

    }

.. http:post:: /management/auditors/$AUDITOR_PUB/disable

  This request will be used to disable the use of the given auditor.
  We use POST instead of DELETE because the exchange will retain state
  about the auditor (specifically the end date) to prevent replay
  attacks abusing the `AuditorSetupMessage`.  Also, DELETE would not
  support a body, which is needed to provide the signature authorizing
  the operation.

  **Request:**

  The request must be a `AuditorTeardownMessage`.

  **Response**

  :http:statuscode:`204 No content`:
    The auditor has successfully disabled the auditor. The body is empty.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`404 Not found`:
    The auditor is unknown to the exchange.
  :http:statuscode:`409 Conflict`:
    The exchange has a more recent request related to this auditor key (replay detected).

  **Details:**

  .. ts:def:: AuditorTeardownMessage

    interface AuditorTeardownMessage {

      // Signature by the exchange master key over a
      // `TALER_MasterDelAuditorPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_AUDITOR_DEL``.
      master_sig: EddsaSignature;

      // When does the auditor become inactive?
      // Should be the time when the signature was created,
      // using the (monotonic!) local time of the system
      // with the offline master public key.  Note that
      // even if the time is in the future, the auditor will
      // become inactive immediately! Used ONLY to detect replay attacks.
      validity_end: Timestamp;

    }


.. http:post:: /management/wire-fee

  This request is used to configure wire fees.

  **Request:**

  The request must be a `WireFeeSetupMessage`.

  **Response:**

  :http:statuscode:`204 No content`:
    The wire fee was successfully configured.
  :http:statuscode:`403 Forbidden`:
    The master signature is invalid.
  :http:statuscode:`409 Conflict`:
    The exchange has a conflicting wire fee already set up.

  **Details:**

  .. ts:def:: WireFeeSetupMessage

    interface WireFeeSetupMessage {

      // Wire method the fee applies to.
      wire_method: string;

      // Signature using the exchange's offline key
      // with purpose ``TALER_SIGNATURE_MASTER_WIRE_FEES``.
      master_sig_wire: EddsaSignature;

      // When does the wire fee validity period start?
      fee_start: Timestamp;

      // When does the wire fee validity period end (exclusive).
      fee_end: Timestamp;

      // Closing fee to charge during that time period for this wire method.
      closing_fee: Amount;

      // Wire fee to charge during that time period for this wire method.
      wire_fee: Amount;

    }

.. http:post:: /management/global-fees

  Provides global fee configuration for a timeframe.

  **Request:**

  The request must be a `GlobalFees` message.

  **Response**

  :http:statuscode:`204 No content`:
    The configuration update has been processed successfully. The body is empty.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`409 Conflict`:
    The exchange has previously received a conflicting configuration message.



.. http:post:: /management/wire

  This request will be used to enable a wire method (exchange bank account).

  **Request:**

  The request must be a `WireSetupMessage`.

  **Response:**

  :http:statuscode:`204 No content`:
    The wire method was successfully enabled.
  :http:statuscode:`403 Forbidden`:
    The master signature is invalid.
  :http:statuscode:`409 Conflict`:
    The exchange has a more recent request related to this wire method (replay detected).

  **Details:**

  .. ts:def:: WireSetupMessage

    interface WireSetupMessage {

      // ``payto://`` URL identifying the account and wire method
      payto_uri: string;

      // Signature using the exchange's offline key
      // over a `TALER_MasterWireDetailsPS`
      // with purpose ``TALER_SIGNATURE_MASTER_WIRE_DETAILS``.
      master_sig_wire: EddsaSignature;

      // Signature using the exchange's offline key over a
      // `TALER_MasterAddWirePS`
      // with purpose ``TALER_SIGNATURE_MASTER_WIRE_ADD``.
      master_sig_add: EddsaSignature;

      // When does the wire method become active?
      // Should be the time when the signature was created,
      // using the (monotonic!) local time of the system
      // with the offline master public key. Note that
      // even if the time is in the future, the wire method will
      // become active immediately! Used ONLY to detect replay attacks.
      validity_start: Timestamp;

      // Display label wallets should use to show this
      // bank account.
      // Since protocol **v19**.
      bank_label?: string;

      // *Signed* integer with the display priority for
      // this bank account.
      // Since protocol **v19**.
      priority?: Integer;

    }

.. http:post:: /management/wire/disable

  This request will be used to disable the use of the given wire method.
  We use POST instead of DELETE because the exchange will retain state
  about the wire method (specifically the end date) to prevent replay
  attacks abusing the `WireSetupMessage`.  Also, DELETE would not
  support a body, which is needed to provide the signature authorizing
  the operation.

  **Request:**

  The request must be a `WireTeardownMessage`.

  **Response**

  :http:statuscode:`204 No content`:
    The auditor has successfully disabled the wire method. The body is empty.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`404 Not found`:
    The wire method is unknown to the exchange.
  :http:statuscode:`409 Conflict`:
    The exchange has a more recent request related to this wire method (replay detected).

  **Details:**

  .. ts:def:: WireTeardownMessage

    interface WireTeardownMessage {

      // ``payto://`` URL identifying the account and wire method
      payto_uri: string;

      // Signature using the exchange's offline key over a
      // `TALER_MasterDelWirePS`.
      // with purpose ``TALER_SIGNATURE_MASTER_WIRE_DEL``.
      master_sig_del: EddsaSignature;

      // Should be the time when the signature was created,
      // using the (monotonic!) local time of the system
      // with the offline master public key.  Note that
      // even if the time is in the future, the wire method will
      // become inactive immediately! Used ONLY to detect replay attacks.
      validity_end: Timestamp;

    }


.. http:post:: /management/drain

  This request is used to drain profits from the
  exchange's escrow account to another regular
  bank account of the exchange.  The actual drain
  requires running the ``taler-exchange-drain`` tool.

  **Request:**

  The request must be a `DrainProfitsMessage`.

  **Response:**

  :http:statuscode:`204 No content`:
    The profit drain was scheduled.
  :http:statuscode:`403 Forbidden`:
    The master signature is invalid.

  **Details:**

  .. ts:def:: DrainProfitsMessage

    interface DrainProfitsMessage {

      // Configuration section of the account to debit.
      debit_account_section: string;

      // Credit payto URI
      credit_payto_uri: string;

      // Wire transfer identifier to use.
      wtid: Base32;

      // Signature by the exchange master key over a
      // `TALER_MasterDrainProfitPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_DRAIN_PROFITS``.
      master_sig: EddsaSignature;

      // When was the message created.
      date: Timestamp;

      // Amount to be drained.
      amount: Amount;

    }


.. http:post:: /management/aml-officers

  Update settings for an AML Officer status.

  **Request:**

  The request must be an `AmlOfficerSetup` message.

  **Response**

  :http:statuscode:`204 No content`:
    The officer settings have been updated successfully.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`409 Conflict`:
    The exchange has previously received a conflicting configuration message.

  **Details:**

  .. ts:def:: AmlOfficerSetup

    interface AmlOfficerSetup {

      // Public key of the AML officer
      officer_pub: EddsaPublicKey;

      // Legal full name of the AML officer
      officer_name: string;

      // Is the account active?
      is_active: boolean;

      // Is the account read-only?
      read_only: boolean;

      // Signature by the exchange master key over a
      // `TALER_MasterAmlOfficerStatusPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_AML_KEY``.
      master_sig: EddsaSignature;

      // When will the change take effect?
      change_date: Timestamp;

    }


  .. http:post:: /management/partners

    Enables a partner exchange for wad transfers.

  **Request:**

  The request must be an `ExchangePartner` message.

  **Response**

  :http:statuscode:`204 No content`:
    The partner has been added successfully.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`409 Conflict`:
    The exchange has previously received a conflicting configuration message.

  **Details:**

  .. ts:def:: ExchangePartner

    interface ExchangePartner {

      // Base URL of the partner exchange
      partner_base_url: string;

      // Master (offline) public key of the partner exchange.
      partner_pub: EddsaPublicKey;

      // How frequently will wad transfers be made
      wad_frequency: RelativeTime;

      // Signature by the exchange master key over a
      // `TALER_PartnerConfigurationPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_PARTNER_DETAILS``.
      master_sig: EddsaSignature;

      // When will the partner relationship start (inclusive).
      start_date: Timestamp;

      // When will the partner relationship end (exclusive).
      end_date: Timestamp;

      // Wad fee to be charged (to customers).
      wad_fee: Amount;

    }

--------------
AML operations
--------------

This API is only for designated AML officers. It is used
to allow exchange staff to monitor suspicious transactions
and freeze or unfreeze accounts suspected of money laundering.


.. http:get:: /aml/$OFFICER_PUB/decisions/$STATE

  Obtain list of AML decisions (filtered by $STATE).  ``$STATE`` must be either ``normal``, ``pending`` or ``frozen``.

  *Taler-AML-Officer-Signature*: The client must provide Base-32 encoded EdDSA signature with ``$OFFICER_PRIV``, affirming the desire to obtain AML data.  Note that this is merely a simple authentication mechanism, the details of the request are not protected by the signature.

  :query delta: *Optional*. takes value of the form ``N (-N)``, so that at most ``N`` values strictly older (younger) than ``start`` are returned.  Defaults to ``-20`` to return the last 20 entries (before ``start``).
  :query start: *Optional*. Row number threshold, see ``delta`` for its interpretation.  Defaults to ``INT64_MAX``, namely the biggest row id possible in the database.

  **Response**

  :http:statuscode:`200 OK`:
    The responds will be an `AmlRecords` message.
  :http:statuscode:`204 No content`:
    There are no matching AML records.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`404 Not found`:
    The designated AML account is not known.
  :http:statuscode:`409 Conflict`:
    The designated AML account is not enabled.

  **Details:**

  .. ts:def:: AmlRecords

    interface AmlRecords {

      // Array of AML records matching the query.
      records: AmlRecord[];
    }

  .. ts:def:: AmlRecord

    interface AmlRecord {

      // Which payto-address is this record about.
      // Identifies a GNU Taler wallet or an affected bank account.
      h_payto: PaytoHash;

      // What is the current AML state.
      current_state: Integer;

      // Monthly transaction threshold before a review will be triggered
      threshold: Amount;

      // RowID of the record.
      rowid: Integer;

    }


.. http:get:: /aml/$OFFICER_PUB/decision/$H_PAYTO

  Obtain deails about an AML decision.

  *Taler-AML-Officer-Signature*: The client must provide Base-32 encoded EdDSA signature with ``$OFFICER_PRIV``, affirming the desire to obtain AML data.  Note that this is merely a simple authentication mechanism, the details of the request are not protected by the signature.

  :query history: *Optional*. If set to yes, we return all historic decisions and not only the last one.

  **Response**

  :http:statuscode:`200 OK`:
    The responds will be an `AmlDecisionDetails` message.
  :http:statuscode:`204 No content`:
    There are no matching AML records for the given payto://-URI.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`404 Not found`:
    The designated AML account is not known.
  :http:statuscode:`409 Conflict`:
    The designated AML account is not enabled.

  **Details:**

  .. ts:def:: AmlDecisionDetails

    interface AmlDecisionDetails {

      // Array of AML decisions made for this account. Possibly
      // contains only the most recent decision if "history" was
      // not set to 'true'.
      aml_history: AmlDecisionDetail[];

      // Array of KYC attributes obtained for this account.
      kyc_attributes: KycDetail[];
    }

  .. ts:def:: AmlDecisionDetail

    interface AmlDecisionDetail {

      // What was the justification given?
      justification: string;

      // FIXME: review!
      // What is the new AML state.
      new_state: Integer;

      // When was this decision made?
      decision_time: Timestamp;

      // What is the new AML decision threshold (in monthly transaction volume)?
      new_threshold: Amount;

      // Who made the decision?
      decider_pub: AmlOfficerPublicKeyP;

    }

  .. ts:def:: KycDetail

    interface KycDetail {

      // Name of the configuration section that specifies the provider
      // which was used to collect the KYC details
      // FIXME: review!
      provider_section: string;

      // The collected KYC data.  NULL if the attribute data could not
      // be decrypted (internal error of the exchange, likely the
      // attribute key was changed).
      attributes?: Object;

      // Time when the KYC data was collected
      collection_time: Timestamp;

      // Time when the validity of the KYC data will expire
      expiration_time: Timestamp;

    }


  .. http:post:: /aml/$OFFICER_PUB/decision

  Make an AML decision. Triggers the respective action and
  records the justification.

  **Request:**

  The request must be an `AmlDecision` message.

  **Response**

  :http:statuscode:`204 No content`:
    The AML decision has been executed and recorded successfully.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
  :http:statuscode:`404 Not found`:
    The address the decision was made upon is unknown to the exchange or
    the designated AML account is not known.
  :http:statuscode:`409 Conflict`:
    The designated AML account is not enabled or a more recent
    decision was already submitted.

  **Details:**

  .. ts:def:: AmlDecision

    interface AmlDecision {

      // Human-readable justification for the decision.
      justification: string;

      // At what monthly transaction volume should the
      // decision be automatically reviewed?
      new_threshold: Amount;

      // Which payto-address is the decision about?
      // Identifies a GNU Taler wallet or an affected bank account.
      h_payto: PaytoHash;

      // What is the new AML state (e.g. frozen, unfrozen, etc.)
      // Numerical values are defined in `AmlDecisionState`.
      new_state: Integer;

      // Signature by the AML officer over a `TALER_AmlDecisionPS`.
      // Must have purpose ``TALER_SIGNATURE_MASTER_AML_KEY``.
      officer_sig: EddsaSignature;

      // When was the decision made?
      decision_time: Timestamp;

      // Optional argument to impose new KYC requirements
      // that the customer has to satisfy to unblock transactions.
      kyc_requirements?: string[];
    }


---------------
Auditor actions
---------------

.. _auditor_action:

This part of the API is for the use by auditors interacting with the exchange.


.. http:post:: /auditors/$AUDITOR_PUB/$H_DENOM_PUB

  This is used to add an auditor signature to the ``/keys`` response. It
  affirms to wallets and merchants that this auditor is indeed auditing
  the coins issued by the respective denomination.  There is no "delete"
  operation for this, as auditors can only stop auditing a denomination
  when it expires.

  **Request:**

  The request must be a `AuditorSignatureAddMessage`.

  **Response:**

  :http:statuscode:`204 No content`:
    The backend has successfully stored the auditor signature.
  :http:statuscode:`403 Forbidden`:
    The auditor signature is invalid.
  :http:statuscode:`404 Not found`:
    The denomination key for which the auditor is providing a signature is unknown.
    The response will be a `DenominationUnknownMessage`.
  :http:statuscode:`410 Gone`:
    This auditor is no longer supported by the exchange.
  :http:statuscode:`412 Precondition failed`:
    This auditor is not yet known to the exchange.

  **Details:**

  .. ts:def:: DenominationUnknownMessage

    interface DenominationUnknownMessage {

      // Taler error code.
      code: number;

      // Signature by the exchange over a
      // `TALER_DenominationUnknownAffirmationPS`.
      // Must have purpose ``TALER_SIGNATURE_EXCHANGE_AFFIRM_DENOM_UNKNOWN``.
      exchange_sig: EddsaSignature;

      // Public key of the exchange used to create
      // the 'exchange_sig.
      exchange_pub: EddsaPublicKey;

      // Hash of the denomination public key that is unknown.
      h_denom_pub: HashCode;

      // When was the signature created.
      timestamp: Timestamp;

    }

  .. ts:def:: AuditorSignatureAddMessage

    interface AuditorSignatureAddMessage {

      // Signature by the auditor over a
      // `TALER_ExchangeKeyValidityPS`.
      // Must have purpose ``TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS``.
      auditor_sig: EddsaSignature;

    }

.. _exchange-withdrawal:

----------
Withdrawal
----------

This API is used by the wallet to obtain digital coins.

When transferring money to the exchange such as via SEPA transfers, the exchange creates
a *reserve*, which keeps the money from the customer.  The customer must
specify an EdDSA reserve public key as part of the transfer, and can then
withdraw digital coins using the corresponding private key.  All incoming and
outgoing transactions are recorded under the corresponding public key by the
exchange.

.. note::

   Eventually the exchange will need to advertise a policy for how long it will
   keep transaction histories for inactive or even fully drained reserves.  We
   will therefore need some additional handler similar to ``/keys`` to
   advertise those terms of service.


.. http:get:: /reserves/$RESERVE_PUB

  Request summary information about a reserve.

  **Request:**

  :query timeout_ms=MILLISECONDS: *Optional.*  If specified, the exchange will wait up to MILLISECONDS for incoming funds before returning a 404 if the reserve does not yet exist.

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `ReserveSummary` object; the reserve was known to the exchange.
  :http:statuscode:`404 Not found`:
    The reserve key does not belong to a reserve known to the exchange.

  **Details:**

  .. ts:def:: ReserveSummary

    interface ReserveSummary {
      // Balance left in the reserve.
      balance: Amount;

      // If set, age restriction is required to be set for each coin to this
      // value during the withdrawal from this reserve. The client then MUST
      // use a denomination with support for age restriction enabled for the
      // withdrawal.
      // The value represents a valid age group from the list of permissible
      // age groups as defined by the exchange's output to /keys.
      maximum_age_group?: number;
    }


Withdraw
~~~~~~~~

.. http:post:: /csr-withdraw

  Obtain exchange-side input values in preparation for a
  withdraw step for certain denomination cipher types,
  specifically at this point for Clause-Schnorr blind
  signatures.

  **Request:** The request body must be a `WithdrawPrepareRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The request was successful, and the response is a `WithdrawPrepareResponse`.  Note that repeating exactly the same request
    will again yield the same response (assuming none of the denomination is expired).
  :http:statuscode:`404 Not found`:
    The denomination key is not known to the exchange.
  :http:statuscode:`410 Gone`:
    The requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was revoked. The response is a
    `DenominationExpiredMessage`. Clients must evaluate
    the error code provided to understand which of the
    cases this is and handle it accordingly.

  **Details:**

  .. ts:def:: WithdrawPrepareRequest

    interface WithdrawPrepareRequest {

      // Nonce to be used by the exchange to derive
      // its private inputs from. Must not have ever
      // been used before.
      nonce: CSNonce;

      // Hash of the public key of the denomination the
      // request relates to.
      denom_pub_hash: HashCode;

    }

  .. ts:def:: WithdrawPrepareResponse

    type WithdrawPrepareResponse =
      | ExchangeWithdrawValue;

  .. ts:def:: ExchangeWithdrawValue

    type ExchangeWithdrawValue =
      | ExchangeRsaWithdrawValue
      | ExchangeCsWithdrawValue;

  .. ts:def:: ExchangeRsaWithdrawValue

    interface ExchangeRsaWithdrawValue {
      cipher: "RSA";
    }

  .. ts:def:: ExchangeCsWithdrawValue

    interface ExchangeCsWithdrawValue {
      cipher: "CS";

      // CSR R0 value
      r_pub_0: CsRPublic;

      // CSR R1 value
      r_pub_1: CsRPublic;
    }


Batch Withdraw
~~~~~~~~~~~~~~

.. http:post:: /reserves/$RESERVE_PUB/batch-withdraw

  Withdraw multiple coins from the same reserve.  Note that the client should
  commit all of the request details, including the private key of the coins and
  the blinding factors, to disk *before* issuing this request, so that it can
  recover the information if necessary in case of transient failures, like
  power outage, network outage, etc.

  **Request:** The request body must be a `BatchWithdrawRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The request was successful, and the response is a `BatchWithdrawResponse`.
    Note that repeating exactly the same request will again yield the same
    response, so if the network goes down during the transaction or before the
    client can commit the coin signature to disk, the coin is not lost.
  :http:statuscode:`403 Forbidden`:
    A signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    A denomination key or the reserve are not known to the exchange.  If the
    denomination key is unknown, this suggests a bug in the wallet as the
    wallet should have used current denomination keys from ``/keys``.
    In this case, the response will be a `DenominationUnknownMessage`.
    If the reserve is unknown, the wallet should not report a hard error yet, but
    instead simply wait for up to a day, as the wire transaction might simply
    not yet have completed and might be known to the exchange in the near future.
    In this case, the wallet should repeat the exact same request later again
    using exactly the same blinded coin.
  :http:statuscode:`409 Conflict`:
    One of the following reasons occured:

    1. The balance of the reserve is not sufficient to withdraw the coins of the
    indicated denominations.  The response is `WithdrawError` object.

    2. The reserve has a birthday set and requires a request to ``/age-withdraw`` instead.
    The response comes with a standard `ErrorDetail` response with error-code ``TALER_EC_EXCHANGE_RESERVES_AGE_RESTRICTION_REQUIRED`` and an additional field ``maximum_allowed_age`` for the maximum age (in years) that the client can commit to in the call to ``/age-withdraw``
  :http:statuscode:`410 Gone`:
    A requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was revoked.
    The response is a `DenominationExpiredMessage`. Clients must evaluate the
    error code provided to understand which of the cases this is and handle it
    accordingly.
  :http:statuscode:`451 Unavailable for Legal Reasons`:
    This reserve has received funds from a purse or the amount withdrawn
    exceeds another legal threshold and thus the reserve must
    be upgraded to an account (with KYC) before the withdraw can
    complete.  Note that this response does NOT affirm that the
    withdraw will ultimately complete with the requested amount.
    The user should be redirected to the provided location to perform
    the required KYC checks to open the account before withdrawing.
    Afterwards, the request should be repeated.
    The response will be an `KycNeededRedirect` object.

    Implementation note: internally, we need to
    distinguish between upgrading the reserve to an
    account (due to P2P payment) and identifying the
    owner of the origin bank account (due to exceeding
    the withdraw amount threshold), as we need to create
    a different payto://-URI for the KYC check depending
    on the case.


  **Details:**

  .. ts:def:: BatchWithdrawRequest

    interface BatchWithdrawRequest {
      // Array of requests for the individual coins to withdraw.
      planchets: WithdrawRequest[];

    }

  .. ts:def:: WithdrawRequest

    interface WithdrawRequest {
      // Hash of a denomination public key, specifying the type of coin the client
      // would like the exchange to create.
      denom_pub_hash: HashCode;

      // Coin's blinded public key, should be (blindly) signed by the exchange's
      // denomination private key.
      coin_ev: CoinEnvelope;

      // Signature of `TALER_WithdrawRequestPS` created with
      // the `reserves's private key <reserve-priv>`
      // using purpose ``TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW``.
      reserve_sig: EddsaSignature;

    }


  .. ts:def:: BatchWithdrawResponse

    interface BatchWithdrawResponse {
      // Array of blinded signatures, in the same order as was
      // given in the request.
      ev_sigs: WithdrawResponse[];

    }

  .. ts:def:: WithdrawResponse

    interface WithdrawResponse {
      // The blinded signature over the 'coin_ev', affirms the coin's
      // validity after unblinding.
      ev_sig: BlindedDenominationSignature;

    }

  .. ts:def:: BlindedDenominationSignature

    type BlindedDenominationSignature =
      | RsaBlindedDenominationSignature
      | CSBlindedDenominationSignature;

  .. ts:def:: RsaBlindedDenominationSignature

    interface RsaBlindedDenominationSignature {
      cipher: "RSA";

      // (blinded) RSA signature
      blinded_rsa_signature: BlindedRsaSignature;
    }

  .. ts:def:: CSBlindedDenominationSignature

    interface CSBlindedDenominationSignature {
      type: "CS";

      // Signer chosen bit value, 0 or 1, used
      // in Clause Blind Schnorr to make the
      // ROS problem harder.
      b: Integer;

      // Blinded scalar calculated from c_b.
      s: Cs25519Scalar;

    }

  .. ts:def:: KycNeededRedirect

    interface KycNeededRedirect {

      // Numeric `error code <error-codes>` unique to the condition.
      // Should always be ``TALER_EC_EXCHANGE_GENERIC_KYC_REQUIRED``.
      code: number;

      // Human-readable description of the error, i.e. "missing parameter", "commitment violation", ...
      // Should give a human-readable hint about the error's nature. Optional, may change without notice!
      hint?: string;

      // Hash of the payto:// account URI that identifies
      // the account which is being KYCed.
      h_payto:  PaytoHash;

      // Legitimization target that the merchant should
      // use to check for its KYC status using
      // the ``/kyc-check/$REQUIREMENT_ROW/...`` endpoint.
      requirement_row: Integer;

    }

  .. ts:def:: WithdrawError

    interface WithdrawError {
      // Text describing the error.
      hint: string;

      // Detailed error code.
      code: Integer;

      // Amount left in the reserve.
      balance: Amount;

      // History of the reserve's activity, in the same format
      // as returned by ``/reserve/$RID/history``.
      history: TransactionHistoryItem[]
    }

  .. ts:def:: DenominationExpiredMessage

    interface DenominationExpiredMessage {

      // Taler error code.  Note that beyond
      // expiration this message format is also
      // used if the key is not yet valid, or
      // has been revoked.
      code: number;

      // Signature by the exchange over a
      // `TALER_DenominationExpiredAffirmationPS`.
      // Must have purpose ``TALER_SIGNATURE_EXCHANGE_AFFIRM_DENOM_EXPIRED``.
      exchange_sig: EddsaSignature;

      // Public key of the exchange used to create
      // the 'exchange_sig.
      exchange_pub: EddsaPublicKey;

      // Hash of the denomination public key that is unknown.
      h_denom_pub: HashCode;

      // When was the signature created.
      timestamp: Timestamp;

      // What kind of operation was requested that now
      // failed?
      oper: string;
    }





Withdraw with Age Restriction
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If the reserve was marked with a maximum age group, the client has to perform a
cut&choose protocol with the exchange.  It first calls
``/reserves/$RESERVE_PUB/age-withdraw`` and commits to ``n*kappa`` coins.  On
success, the exchange answers this request with an noreveal-index.  The client
then has to call ``/age-withdraw/$ACH/reveal`` to reveal all ``n*(kappa - 1)``
coins along with their age commitments to proof that they were appropriate.
If so, the exchange will blindly sign ``n`` undisclosed coins from the request.


.. http:post:: /reserves/$RESERVE_PUB/age-withdraw

  Withdraw multiple coins *with age restriction* from the same reserve.
  Note that the client should commit all of the request details, including the
  private key of the coins and the blinding factors, to disk *before* issuing
  this request, so that it can recover the information if necessary in case of
  transient failures, like power outage, network outage, etc.

  **Request:** The request body must be a `AgeWithdrawRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The request was successful, and the response is a `AgeWithdrawResponse`.
    Note that repeating exactly the same request will again yield the same
    response, so if the network goes down during the transaction or before the
    client can commit the coin signature to disk, the coin is not lost.
  :http:statuscode:`403 Forbidden`:
    A signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`409 Conflict`:
    One of two reasons occured:

    1. The balance of the reserve is not sufficient to withdraw the coins of the
    given amount.  The response is a `WithdrawError` object.

    2. The provided value for ``max_age`` is higher than the allowed value according to the reserve's birthday.
    The response comes with a standard `ErrorDetail` response with error-code ``TALER_EC_EXCHANGE_AGE_WITHDRAW_MAXIMUM_AGE_TOO_LARGE`` and an additional field ``maximum_allowed_age`` for the maximum age (in years) that the client can commit to in a call to ``/age-withdraw``
  :http:statuscode:`410 Gone`:
    A requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was revoked.
    The response is a `DenominationExpiredMessage`. Clients must evaluate the
    error code provided to understand which of the cases this is and handle it
    accordingly.
  :http:statuscode:`451 Unavailable for Legal Reasons`:
    This reserve has received funds from a purse or the amount withdrawn
    exceeds another legal threshold and thus the reserve must
    be upgraded to an account (with KYC) before the withdraw can
    complete.  Note that this response does NOT affirm that the
    withdraw will ultimately complete with the requested amount.
    The user should be redirected to the provided location to perform
    the required KYC checks to open the account before withdrawing.
    Afterwards, the request should be repeated.
    The response will be an `KycNeededRedirect` object.

  .. ts:def:: AgeWithdrawRequest

    interface AgeWithdrawRequest {
      // Array of ``n`` hash codes of denomination public keys to order.
      // These denominations MUST support age restriction as defined in the
      // output to /keys.
      // The sum of all denomination's values and fees MUST be at most the
      // balance of the reserve.  The balance of the reserve will be
      // immediatley reduced by that amount.
      denoms_h: HashCode[];

      // ``n`` arrays of ``kappa`` entries with blinded coin envelopes.  Each
      // (toplevel)  entry represents ``kappa`` canditates for a particular
      // coin.  The exchange  will respond with an index ``gamma``, which is
      // the index that shall remain undisclosed during the reveal phase.
      // The SHA512 hash $ACH over the blinded coin envelopes is the commitment
      // that is later used as the key to the reveal-URL.
      blinded_coins_evs:  CoinEnvelope[][];

      // The maximum age to commit to.  MUST be the same as the maximum
      // age in the reserve.
      max_age: number;

      // Signature of `TALER_AgeWithdrawRequestPS` created with
      // the `reserves's private key <reserve-priv>`
      // using purpose ``TALER_SIGNATURE_WALLET_RESERVE_AGE_WITHDRAW``.
      reserve_sig: EddsaSignature;
    }

  .. ts:def:: AgeWithdrawResponse

    interface AgeWithdrawResponse {
      // index of the commitments that the client doesn't
      // have to disclose
      noreveal_index: Integer;

      // Signature of `TALER_AgeWithdrawConfirmationPS` whereby
      // the exchange confirms the ``noreveal_index``.
      exchange_sig: EddsaSignature;

      // `Public EdDSA key <sign-key-pub>` of the exchange that was used to
      // generate the signature.  Should match one of the exchange's signing
      // keys from ``/keys``.  Again given explicitly as the client might
      // otherwise be confused by clock skew as to which signing key was used.
      exchange_pub: EddsaPublicKey;
    }



.. http:post:: /age-withdraw/$ACH/reveal

  The client has previously committed to multiple coins with age restriction
  in a call to ``/reserve/$RESERVE_PUB/age-withdraw`` and got a
  `AgeWithdrawResponse` from the exchange.  By calling this
  endpoint, the client has to reveal each coin and their ``kappa - 1``
  age commitments, except for the age commitments with index
  ``noreveal_index``.  The hash of all commitments from the former withdraw
  request is given as the ``$ACH`` value in the URL to this endpoint.


  **Request:** The request body must be a `AgeWithdrawRevealRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The request was successful, and the response is a `AgeWithdrawRevealResponse`.
    Note that repeating exactly the same request will again yield the same
    response, so if the network goes down during the transaction or before the
    client can commit the coin signature to disk, the coin is not lost.
  :http:statuscode:`404 Not found`:
    The provided commitment $ACH is unknown.
  :http:statuscode:`409 Conflict`:
    The reveal operation failed and the response is an `WithdrawError` object.
    The error codes indicate one of two cases:

    1. An age commitment for at least one of the coins did not fulfill the
       required maximum age requirement of the corresponding reserve.
       Error code:
       ``TALER_EC_EXCHANGE_GENERIC_COIN_AGE_REQUIREMENT_FAILURE``.
    2. The computation of the hash of the commitment with provided input does
       result in the value $ACH.
       Error code:
       ``TALER_EC_EXCHANGE_AGE_WITHDRAW_REVEAL_INVALID_HASH``


  .. ts:def:: AgeWithdrawRevealRequest

    interface AgeWithdrawRevealRequest {
      // Array of ``n`` of ``(kappa - 1)`` disclosed coin master secrets, from
      // which the coins' private key, blinding, nonce (for Clause-Schnorr) and
      // age-restriction  is calculated.
      //
      // Given each coin's private key and age commitment, the exchange will
      // calculate each coin's blinded hash value und use all those (disclosed)
      // blinded hashes together with the non-disclosed envelopes ``coin_evs``
      // during the verification of the original age-withdraw-commitment.
      disclosed_coin_secrets: AgeRestrictedCoinSecret[][];
    }

  .. ts:def:: AgeRestrictedCoinSecret

    // The Master key material from which the coins' private key ``coin_priv``,
    // blinding ``beta`` and nonce ``nonce`` (for Clause-Schnorr) itself are
    // derived as usually in wallet-core.  Given a coin's master key material,
    // the age commitment for the coin MUST be derived from this private key as
    // follows:
    //
    // Let m ∈  {1,...,M} be the maximum age group as defined in the reserve
    // that the wallet can commit to.
    //
    // For age group $AG ∈  {1,...m}, set
    //     seed = HDKF(coin_secret, "age-commitment", $AG)
    //   p[$AG] = Edx25519_generate_private(seed)
    // and calculate the corresponding Edx25519PublicKey as
    //   q[$AG] = Edx25519_public_from_private(p[$AG])
    //
    // For age groups $AG ∈  {m,...,M}, set
    //   f[$AG] = HDKF(coin_secret, "age-factor", $AG)
    // and calculate the corresponding Edx25519PublicKey as
    //   q[$AG] = Edx25519_derive_public(`PublishedAgeRestrictionBaseKey`, f[$AG])
    //
    type AgeRestrictedCoinSecret = string;

  .. ts:def:: PublishedAgeRestrictionBaseKey

    // The value for ``PublishedAgeRestrictionBaseKey`` is a randomly chosen
    // `Edx25519PublicKey` for which the private key is not known to the clients.  It is
    // used during the age-withdraw protocol so that clients can proof that they
    // derived all public keys to age groups higher than their allowed maximum
    // from this particular value.
    const PublishedAgeRestrictionBaseKey =
        new Edx25519PublicKey("CH0VKFDZ2GWRWHQBBGEK9MWV5YDQVJ0RXEE0KYT3NMB69F0R96TG");

  .. ts:def:: AgeWithdrawRevealResponse

    interface AgeWithdrawRevealResponse {
      // List of the exchange's blinded RSA signatures on the new coins.
      ev_sigs : BlindedDenominationSignature[];
    }


.. _reserve-history:

---------------
Reserve History
---------------

.. http:get:: /reserves/$RESERVE_PUB/history

  Request information about the full history of
  a reserve or an account.

  **Request:**

  The GET request should come with the following HTTP headers:

  *If-None-Match*: The client MAY provide an ``If-None-Match`` header with an
  Etag.  In that case, the server MUST additionally respond with an ``304``
  status code in case the reserve history matches the provided Etag.

  *Taler-Reserve-History-Signature*: The client MUST provide Base-32 encoded
   EdDSA signature over a TALER_SIGNATURE_RESERVE_HISTORY_REQUEST made with
   the respective ``$RESERVE_PRIV``, affirming desire to download the current
   reserve transaction history.

  :query start=OFFSET: *Optional.* Only return reserve history entries with
                       offsets above the given OFFSET. Allows clients to not
                       retrieve history entries they already have.

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `ReserveHistory` object; the reserve was known to the exchange.
  :http:statuscode:`204 No content`:
    The reserve history is known, but at this point from the given starting point it is empty. Can only happen if OFFSET was positive.
  :http:statuscode:`304 Not modified`:
    The reserve history matches the one identified by the "If-none-match" HTTP header of the request.
  :http:statuscode:`403 Forbidden`:
    The *TALER_SIGNATURE_RESERVE_HISTORY_REQUEST* is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The reserve key does not belong to a reserve known to the exchange.

  **Details:**

  .. ts:def:: ReserveHistory

    interface ReserveHistory {
      // Balance left in the reserve.
      balance: Amount;

      // If set, gives the maximum age group that the client is required to set
      // during withdrawal.
      maximum_age_group: number;

      // Transaction history for this reserve.
      // May be partial (!).
      history: TransactionHistoryItem[];
    }

  Objects in the transaction history have the following format:

  .. ts:def:: TransactionHistoryItem

    // Union discriminated by the "type" field.
    type TransactionHistoryItem =
      | AccountSetupTransaction
      | ReserveWithdrawTransaction
      | ReserveAgeWithdrawTransaction
      | ReserveCreditTransaction
      | ReserveClosingTransaction
      | ReserveOpenRequestTransaction
      | ReserveCloseRequestTransaction
      | PurseMergeTransaction;

  .. ts:def:: AccountSetupTransaction

    interface AccountSetupTransaction {
      type: "SETUP";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // KYC fee agreed to by the reserve owner.
      kyc_fee: Amount;

      // Time when the KYC was triggered.
      kyc_timestamp: Timestamp;

      // Hash of the wire details of the account.
      // Note that this hash is unsalted and potentially
      // private (as it could be inverted), hence access
      // to this endpoint must be authorized using the
      // private key of the reserve.
      h_wire: HashCode;

      // Signature created with the reserve's private key.
      // Must be of purpose ``TALER_SIGNATURE_ACCOUNT_SETUP_REQUEST`` over
      // a ``TALER_AccountSetupRequestSignaturePS``.
      reserve_sig: EddsaSignature;

    }

  .. ts:def:: ReserveWithdrawTransaction

    interface ReserveWithdrawTransaction {
      type: "WITHDRAW";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // Amount withdrawn.
      amount: Amount;

      // Hash of the denomination public key of the coin.
      h_denom_pub: HashCode;

      // Hash of the blinded coin to be signed.
      h_coin_envelope: HashCode;

      // Signature over a `TALER_WithdrawRequestPS`
      // with purpose ``TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW``
      // created with the reserve's private key.
      reserve_sig: EddsaSignature;

      // Fee that is charged for withdraw.
      withdraw_fee: Amount;
     }

  .. ts:def:: ReserveAgeWithdrawTransaction

    interface ReserveAgeWithdrawTransaction {
      type: "AGEWITHDRAW";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // Total Amount withdrawn.
      amount: Amount;

      // Commitment of all ``n*kappa`` blinded coins.
      h_commitment: HashCode;

      // Signature over a `TALER_AgeWithdrawRequestPS`
      // with purpose ``TALER_SIGNATURE_WALLET_RESERVE_AGE_WITHDRAW``
      // created with the reserve's private key.
      reserve_sig: EddsaSignature;

      // Fee that is charged for withdraw.
      withdraw_fee: Amount;
     }


  .. ts:def:: ReserveCreditTransaction

    interface ReserveCreditTransaction {
      type: "CREDIT";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // Amount deposited.
      amount: Amount;

      // Sender account ``payto://`` URL.
      sender_account_url: string;

      // Opaque identifier internal to the exchange that
      // uniquely identifies the wire transfer that credited the reserve.
      wire_reference: Integer;

      // Timestamp of the incoming wire transfer.
      timestamp: Timestamp;
    }


  .. ts:def:: ReserveClosingTransaction

    interface ReserveClosingTransaction {
      type: "CLOSING";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // Closing balance.
      amount: Amount;

      // Closing fee charged by the exchange.
      closing_fee: Amount;

      // Wire transfer subject.
      wtid: Base32;

      // ``payto://`` URI of the wire account into which the funds were returned to.
      receiver_account_details: string;

      // This is a signature over a
      // struct `TALER_ReserveCloseConfirmationPS` with purpose
      // ``TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED``.
      exchange_sig: EddsaSignature;

      // Public key used to create 'exchange_sig'.
      exchange_pub: EddsaPublicKey;

      // Time when the reserve was closed.
      timestamp: Timestamp;
    }


  .. ts:def:: ReserveOpenRequestTransaction

    interface ReserveOpenRequestTransaction {
      type: "OPEN";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // Open fee paid from the reserve.
      open_fee: Amount;

      // This is a signature over
      // a struct `TALER_ReserveOpenPS` with purpose
      // ``TALER_SIGNATURE_WALLET_RESERVE_OPEN``.
      reserve_sig: EddsaSignature;

      // Timestamp of the open request.
      request_timestamp: Timestamp;

      // Requested expiration.
      requested_expiration: Timestamp;

      // Requested number of free open purses.
      requested_min_purses: Integer;

    }

  .. ts:def:: ReserveCloseRequestTransaction

    interface ReserveCloseRequestTransaction {
      type: "CLOSE";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // This is a signature over
      // a struct `TALER_ReserveClosePS` with purpose
      // ``TALER_SIGNATURE_WALLET_RESERVE_CLOSE``.
      reserve_sig: EddsaSignature;

      // Target account ``payto://``, optional.
      h_payto?: PaytoHash;

      // Timestamp of the close request.
      request_timestamp: Timestamp;
    }

  .. ts:def:: ReserveCreditTransaction

    interface ReserveCreditTransaction {
      type: "CREDIT";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // Amount deposited.
      amount: Amount;

      // Sender account ``payto://`` URL.
      sender_account_url: string;

      // Opaque identifier internal to the exchange that
      // uniquely identifies the wire transfer that credited the reserve.
      wire_reference: Integer;

      // Timestamp of the incoming wire transfer.
      timestamp: Timestamp;
    }

  .. ts:def:: PurseMergeTransaction

    interface PurseMergeTransaction {
      type: "MERGE";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // SHA-512 hash of the contact of the purse.
      h_contract_terms: HashCode;

      // EdDSA public key used to approve merges of this purse.
      merge_pub: EddsaPublicKey;

      // Minimum age required for all coins deposited into the purse.
      min_age: Integer;

      // Number that identifies who created the purse
      // and how it was paid for.
      flags: Integer;

      // Purse public key.
      purse_pub: EddsaPublicKey;

      // EdDSA signature of the account/reserve affirming the merge
      // over a `TALER_AccountMergeSignaturePS`.
      // Must be of purpose ``TALER_SIGNATURE_ACCOUNT_MERGE``
      reserve_sig: EddsaSignature;

      // Client-side timestamp of when the merge request was made.
      merge_timestamp: Timestamp;

      // Indicative time by which the purse should expire
      // if it has not been merged into an account. At this
      // point, all of the deposits made should be
      // auto-refunded.
      purse_expiration: Timestamp;

      // Purse fee the reserve owner paid for the purse creation.
      purse_fee: Amount;

      // Total amount merged into the reserve.
      // (excludes fees).
      amount: Amount;

      // True if the purse was actually merged.
      // If false, only the purse_fee has an impact
      // on the reserve balance!
      merged: boolean;
    }


.. _coin-history:

------------
Coin History
------------

.. http:get:: /coins/$COIN_PUB/history

  Obtain the transaction history of a coin.  Used only in special cases, like
  when the exchange claims a double-spending error and the wallet does not
  believe it. Usually, the wallet knows the transaction history of each coin
  and thus has no need to inquire.

  **Request:**

  The GET request should come with the following HTTP headers:

  *If-None-Match*: The client MAY provide an ``If-None-Match`` header with an
  Etag.  In that case, the server MUST additionally respond with an ``304``
  status code in case the coin history matches the provided Etag.

  *Taler-Coin-History-Signature*: The client MUST provide Base-32 encoded
   EdDSA signature over a TALER_SIGNATURE_COIN_HISTORY_REQUEST made with
   the respective ``$RESERVE_PRIV``, affirming desire to download the current
   coin transaction history.

   :query start=OFFSET: *Optional.* Only return coin history entries with
                       offsets above the given OFFSET. Allows clients to not
                       retrieve history entries they already have.


  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange confirms that no double-spending took
    place.  The response will include a `CoinHistoryResponse` object.
  :http:statuscode:`204 No content`:
    The reserve history is known, but at this point from the given starting point it is empty. Can only happen if OFFSET was positive.
  :http:statuscode:`304 Not modified`:
    The coin history has not changed since the previous query (detected via Etag
    in "If-none-match" header).
  :http:statuscode:`403 Forbidden`:
    The *TALER_SIGNATURE_COIN_HISTORY_REQUEST* is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The coin public key is not (yet) known to the exchange.

  .. ts:def:: CoinHistoryResponse

    interface CoinHistoryResponse {
      // Current balance of the coin.
      balance: Amount;

      // Hash of the coin's denomination.
      h_denom_pub: HashCode;

      // Transaction history for the coin.
      history: CoinSpendHistoryItem[];
    }

  .. ts:def:: CoinSpendHistoryItem

    // Union discriminated by the "type" field.
    type CoinSpendHistoryItem =
      | CoinDepositTransaction
      | CoinMeltTransaction
      | CoinRefundTransaction
      | CoinRecoupTransaction
      | CoinOldCoinRecoupTransaction
      | CoinRecoupRefreshTransaction
      | CoinPurseDepositTransaction
      | CoinPurseRefundTransaction
      | CoinReserveOpenDepositTransaction;

  .. ts:def:: CoinDepositTransaction

    interface CoinDepositTransaction {
      type: "DEPOSIT";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value absorbed (or restored in the
      // case of a refund) by this transaction.
      // The amount given includes
      // the deposit fee. The current coin value can thus be computed by
      // subtracting this amount.
      amount: Amount;

      // Deposit fee.
      deposit_fee: Amount;

      // Public key of the merchant.
      merchant_pub: EddsaPublicKey;

      // Date when the operation was made.
      timestamp: Timestamp;

      // Date until which the merchant can issue a refund to the customer via the
      // exchange, possibly zero if refunds are not allowed.
      refund_deadline?: Timestamp;

      // Signature over `TALER_DepositRequestPS`, made by the customer with the
      // `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;

      // Hash of the bank account from where we received the funds.
      h_wire: HashCode;

      // Hash of the public denomination key used to sign the coin.
      // Needed because 'coin_sig' signs over this, and
      // that is important to fix the coin's denomination.
      h_denom_pub: HashCode;

      // Hash over the proposal data of the contract that
      // is being paid.
      h_contract_terms: HashCode;

    }

  .. ts:def:: CoinMeltTransaction

    interface CoinMeltTransaction {
      type: "MELT";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value absorbed by this transaction.
      // Note that for melt this means the amount given includes
      // the melt fee. The current coin value can thus be computed by
      // subtracting the amounts.
      amount: Amount;

      // Signature by the coin over a
      // `TALER_RefreshMeltCoinAffirmationPS` of
      // purpose ``TALER_SIGNATURE_WALLET_COIN_MELT``.
      coin_sig: EddsaSignature;

      // Melt fee.
      melt_fee: Amount;

      // Commitment from the melt operation.
      rc: TALER_RefreshCommitmentP;

      // Hash of the public denomination key used to sign the coin.
      // Needed because 'coin_sig' signs over this, and
      // that is important to fix the coin's denomination.
      h_denom_pub: HashCode;

    }

 .. ts:def:: CoinRefundTransaction

    interface CoinRefundTransaction {
      type: "REFUND";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value restored
      // by this transaction.
      // The amount given excludes the transaction fee.
      // The current coin value can thus be computed by
      // adding the amounts to the coin's denomination value.
      amount: Amount;

      // Refund fee.
      refund_fee: Amount;

      // Hash over the proposal data of the contract that
      // is being refunded.
      h_contract_terms: HashCode;

      // Refund transaction ID.
      rtransaction_id: Integer;

      // `EdDSA Signature <eddsa-sig>` authorizing the REFUND over a
      // `TALER_MerchantRefundConfirmationPS` with
      // purpose ``TALER_SIGNATURE_MERCHANT_REFUND_OK``. Made with
      // the `public key of the merchant <merchant-pub>`.
      merchant_sig: EddsaSignature;

    }

 .. ts:def:: CoinRecoupTransaction

    interface CoinRecoupTransaction {
      type: "RECOUP";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value absorbed
      // by this transaction.
      // The current coin value can thus be computed by
      // subtracting the amount from
      // the coin's denomination value.
      amount: Amount;

      // Date when the operation was made.
      timestamp: Timestamp;

      // Signature by the coin over a
      // `TALER_RecoupRequestPS` with purpose
      // ``TALER_SIGNATURE_WALLET_COIN_RECOUP``.
      coin_sig: EddsaSignature;

      // Hash of the public denomination key used to sign the coin.
      // Needed because 'coin_sig' signs over this, and
      // that is important to fix the coin's denomination.
      h_denom_pub: HashCode;

      // Coin blinding key.
      coin_blind: DenominationBlindingKeyP;

      // Reserve receiving the recoup.
      reserve_pub: EddsaPublicKey;

      // Signature by the exchange over a
      // `TALER_RecoupConfirmationPS`, must be
      // of purpose ``TALER_SIGNATURE_EXCHANGE_CONFIRM_RECOUP``.
      exchange_sig: EddsaSignature;

      // Public key of the private key used to create 'exchange_sig'.
      exchange_pub: EddsaPublicKey;

    }

 .. ts:def:: CoinOldCoinRecoupTransaction

    interface CoinOldCoinRecoupTransaction {
      type: "OLD-COIN-RECOUP";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value restored
      // by this transaction.
      // The current coin value can thus be computed by
      // adding the amount to the coin's denomination value.
      amount: Amount;

      // Date when the operation was made.
      timestamp: Timestamp;

      // Signature by the exchange over a
      // `TALER_RecoupRefreshConfirmationPS`
      // of purpose ``TALER_SIGNATURE_EXCHANGE_CONFIRM_RECOUP_REFRESH``.
      exchange_sig: EddsaSignature;

      // Public key of the private key used to create 'exchange_sig'.
      exchange_pub: EddsaPublicKey;

    }

 .. ts:def:: CoinRecoupRefreshTransaction

    interface CoinRecoupRefreshTransaction {
      type: "RECOUP-REFRESH";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value absorbed
      // by this transaction.
      // The current coin value can thus be computed by
      // subtracting this amounts from
      // the coin's denomination value.
      amount: Amount;

      // Date when the operation was made.
      timestamp: Timestamp;

      // Signature by the coin over a `TALER_RecoupRequestPS`
      // with purpose ``TALER_SIGNATURE_WALLET_COIN_RECOUP``.
      coin_sig: EddsaSignature;

      // Hash of the public denomination key used to sign the coin.
      // Needed because 'coin_sig' signs over this, and
      // that is important to fix the coin's denomination.
      h_denom_pub: HashCode;

      // Coin blinding key.
      coin_blind: DenominationBlindingKeyP;

      // Signature by the exchange over a
      // `TALER_RecoupRefreshConfirmationPS`
      // of purpose ``TALER_SIGNATURE_EXCHANGE_CONFIRM_RECOUP_REFRESH``.
      exchange_sig: EddsaSignature;

      // Public key used to sign 'exchange_sig'.
      exchange_pub: EddsaPublicKey;

      // Blinding factor of the revoked new coin.
      new_coin_blinding_secret: DenominationBlindingKeySecret;

      // Blinded public key of the revoked new coin.
      new_coin_ev: DenominationBlindingKeySecret;
    }

 .. ts:def:: CoinPurseDepositTransaction

    interface CoinPurseDepositTransaction {
      type: "PURSE-DEPOSIT";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value absorbed
      // by this transaction.
      // Note that this means the amount given includes
      // the deposit fee. The current coin value can thus be computed by
      // subtracting the amount from
      // the coin's denomination value.
      amount: Amount;

      // Deposit fee.
      deposit_fee: Amount;

      // Public key of the purse.
      purse_pub: EddsaPublicKey;

      // Date when the purse was set to expire.
      purse_expiration: Timestamp;

      // Signature by the coin over a
      // `TALER_PurseDepositSignaturePS` of
      // purpose ``TALER_SIGNATURE_PURSE_DEPOSIT``.
      coin_sig: EddsaSignature;

      // Hash of the public denomination key used to sign the coin.
      // Needed because 'coin_sig' signs over this, and
      // that is important to fix the coin's denomination.
      h_denom_pub: HashCode;

    }

 .. ts:def:: CoinPurseRefundTransaction

    interface CoinPurseRefundTransaction {
      type: "PURSE-REFUND";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value restored
      // by this transaction.
      // The amount given excludes the refund fee.
      // The current coin value can thus be computed by
      // adding the amount to the coin's denomination value.
      amount: Amount;

      // Refund fee (of the coin's denomination). The deposit
      // fee will be waived.
      refund_fee: Amount;

      // Public key of the purse that expired.
      purse_pub: EddsaPublicKey;

      // Signature by the exchange over a
      // ``TALER_CoinPurseRefundConfirmationPS``
      // of purpose ``TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND``.
      exchange_sig: EddsaSignature;

     // Public key used to sign 'exchange_sig'.
      exchange_pub: EddsaPublicKey;

    }

 .. ts:def:: CoinReserveOpenDepositTransaction

    interface CoinReserveOpenDepositTransaction {
      type: "RESERVE-OPEN-DEPOSIT";

      // Offset of this entry in the reserve history.
      // Useful to request incremental histories via
      // the "start" query parameter.
      history_offset: Integer;

      // The total amount of the coin's value absorbed
      // by this transaction.
      // Note that this means the amount given includes
      // the deposit fee.
      coin_contribution: Amount;

      // Signature of the reserve open operation being paid for.
      reserve_sig: EddsaSignature;

      // Signature by the coin over a
      // `TALER_ReserveOpenDepositSignaturePS` of
      // purpose ``TALER_SIGNATURE_RESERVE_OPEN_DEPOSIT``.
      coin_sig: EddsaSignature;

    }


.. _deposit-par:

-------
Deposit
-------

Deposit operations are requested f.e. by a merchant during a transaction or a
bidder during an auction.

For the deposit operation during purchase, the merchant has to obtain the
deposit permission for a coin from their customer who owns the coin.  When
depositing a coin, the merchant is credited an amount specified in the deposit
permission, possibly a fraction of the total coin's value, minus the deposit
fee as specified by the coin's denomination.

For auctions, a bidder performs an deposit operation and provides all relevant
information for the auction policy (such as timeout and public key as bidder)
and can use the ``exchange_sig`` field from the `DepositSuccess` message as a
proof to the seller for the escrow of sufficient fund.


.. _deposit:

.. http:post:: /batch-deposit

  Deposit multiple coins and ask the exchange to transfer the given :ref:`amount`
  into the merchant's bank account.  This API is used by the merchant to redeem
  the digital coins.

  **Request:**

  The request body must be a `BatchDepositRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange confirms that no double-spending took
    place.  The response will include a `DepositSuccess` object.
  :http:statuscode:`403 Forbidden`:
    One of the signatures is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    Either one of the denomination keys is not recognized (expired or invalid),
    or the wire type is not recognized.
    If a denomination key is unknown, the response will be
    a `DenominationUnknownMessage`.
  :http:statuscode:`409 Conflict`:
    The deposit operation has either failed because a coin has insufficient
    residual value, or because the same public key of a coin has been
    previously used with a different denomination.
    Which case it is can be decided by looking at the error code:

    1. ``TALER_EC_EXCHANGE_DEPOSIT_CONFLICTING_CONTRACT`` (same coin used in different ways),
    2. ``TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS`` (balance insufficient),
    3. ``TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY`` (same coin public key, but different denomination).
    4. ``TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_AGE_HASH`` (same coin public key, but different age commitment).

    The request should not be repeated again with this coin.  Instead, the client
    can get from the exchange via the ``/coin/$COIN_PUB/history`` endpoint the record
    of the transactions known for this coin's public key.
  :http:statuscode:`410 Gone`:
    The requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was revoked. The response is a
    `DenominationExpiredMessage`. Clients must evaluate
    the error code provided to understand which of the
    cases this is and handle it accordingly.

  **Details:**

  .. ts:def:: BatchDepositRequest

    interface BatchDepositRequest {

      // The merchant's account details.
      merchant_payto_uri: string;

      // The salt is used to hide the ``payto_uri`` from customers
      // when computing the ``h_wire`` of the merchant.
      wire_salt: WireSalt;

      // SHA-512 hash of the contract of the merchant with the customer.  Further
      // details are never disclosed to the exchange.
      h_contract_terms: HashCode;

      // The list of coins that are going to be deposited with this Request.
      coins: BatchDepositRequestCoin[];

      // Timestamp when the contract was finalized.
      timestamp: Timestamp;

      // Indicative time by which the exchange undertakes to transfer the funds to
      // the merchant, in case of successful payment. A wire transfer deadline of 'never'
      // is not allowed.
      wire_transfer_deadline: Timestamp;

      // EdDSA `public key of the merchant <merchant-pub>`, so that the client can identify the
      // merchant for refund requests.
      merchant_pub: EddsaPublicKey;

      // Date until which the merchant can issue a refund to the customer via the
      // exchange, to be omitted if refunds are not allowed.
      //
      // THIS FIELD WILL BE DEPRICATED, once the refund mechanism becomes a
      // policy via extension.
      refund_deadline?: Timestamp;

      // CAVEAT: THIS IS WORK IN PROGRESS
      // (Optional) policy for the batch-deposit.
      // This might be a refund, auction or escrow policy.
      policy?: DepositPolicy;
    }

  .. ts:def:: BatchDepositRequestCoin

    interface BatchDepositRequestCoin {
      // EdDSA public key of the coin being deposited.
      coin_pub: EddsaPublicKey;

      // Hash of denomination RSA key with which the coin is signed.
      denom_pub_hash: HashCode;

      // Exchange's unblinded RSA signature of the coin.
      ub_sig: DenominationSignature;

      // Amount to be deposited, can be a fraction of the
      // coin's total value.
      contribution: Amount;

      // Signature over `TALER_DepositRequestPS`, made by the customer with the
      // `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;
    }

  .. ts:def:: DenominationSignature

    type DenominationSignature =
      | RsaDenominationSignature
      | CSDenominationSignature;

  .. ts:def:: RsaDenominationSignature

    interface RsaDenominationSignature {
      cipher: "RSA";

      // RSA signature
      rsa_signature: RsaSignature;
    }

  .. ts:def:: CSDenominationSignature

    interface CSDenominationSignature {
      type: "CS";

      // R value component of the signature.
      cs_signature_r: Cs25519Point;

      // s value component of the signature.
      cs_signature_s: Cs25519Scalar:

    }

  .. ts:def:: DepositPolicy

    type DepositPolicy =
    | PolicyMerchantRefund
    | PolicyBrandtVickreyAuction
    | PolicyEscrowedPayment;

  .. ts:def:: PolicyMerchantRefund

    // CAVEAT: THIS IS STILL WORK IN PROGRESS.
    // This policy is optional and might not be supported by the exchange.
    // If it does, the exchange MUST show support for this policy in the
    // ``extensions`` field in the response to ``/keys``.
    interface PolicyMerchantRefund {
      type: "merchant_refund";

      // EdDSA `public key of the merchant <merchant-pub>`, so that the client
      // can identify the merchant for refund requests.
      merchant_pub: EddsaPublicKey;

      // Date until which the merchant can issue a refund to the customer via
      // the ``/extensions/policy_refund``-endpoint of the exchange.
      deadline: Timestamp;
    }

  .. ts:def:: PolicyBrandtVickreyAuction

    // CAVEAT: THIS IS STILL WORK IN PROGRESS.
    // This policy is optional and might not be supported by the exchange.
    // If it does, the exchange MUST show support for this policy in the
    // ``extensions`` field in the response to ``/keys``.
    interface PolicyBrandtVickreyAuction {
      type: "brandt_vickrey_auction";

      // Public key of this bidder.
      //
      // The bidder uses this key to sign the auction information and
      // the messages it sends to the seller during the auction.
      bidder_pub: EddsaPublicKey;

      // Hash of the auction terms
      //
      // The hash should be taken over a normalized JSON object of type
      // `BrandtVickreyAuction`.
      h_auction: HashCode;

      // The amount that this bidder commits to for this auction
      //
      // This amount can be larger than the contribution of a single coin.
      // The bidder can increase funding of this auction policy by using
      // sufficiently many coins during the deposit operation (single or batch)
      // with the same policy.
      commitment: Amount;

      // Date until the auction must have been successfully executed and
      // a valid transcript provided to the
      // ``/extensions/policy_brandt_vickrey_auction``-endpoint of the
      // exchange.
      //
      // [If the auction has not been executed by then] OR [has been executed
      // before then, but this bidder did not win], the coin's value doesn't
      // change and the owner can refresh the coin.
      //
      // If this bidder won the auction, the winning price/amount from the
      // outcome will be substracted from the coin and transfered to the
      // merchant's ``payout_uri`` from the deposit request (minus a potential
      // auction fee).  For any remaining value, the bidder can refresh the
      // coin to retrieve change.
      deadline: Timestamp;
    }

  .. ts:def:: BrandtVickreyAuction

    // CAVEAT: THIS IS STILL WORK IN PROGRESS.
    // This structure defines an auction of Brandt-Vickory kind.
    // It is used for the `PolicyBrandtVickreyAuction`.
    interface BrandtVickreyAuction {
      // Start date of the auction
      time_start: Timestamp;

      // Maximum duration per round.  There are four rounds in an auction of
      // Brandt-Vickrey kind.
      time_round: RelativeTime;

      // This integer m refers to the (m+1)-type of the Brandt-Vickrey-auction.
      // - Type 0 refers to an auction with one highest-price winner,
      // - Type 1 refers to an auction with one winner, paying the second
      //   highest price,
      // - Type 2 refers to an auction with two winners, paying
      //   the third-highest price,
      // - etc.
      auction_type: number;

      // The vector of prices for the Brandt-Vickrey auction.  The values MUST
      // be in strictly increasing order.
      prices: Amount[];

      // The type of outcome of the auction.
      // In case the auction is declared public, each bidder can calculate the
      // winning price.  This field is not relevant for the replay of a
      // transcript, as the transcript must be provided by the seller who sees
      // the winner(s) and winning price of the auction.
      outcome_public: boolean;

      // The public key of the seller.
      pubkey: EddsaPublicKey;

      // The seller's account details.
      payto_uri: string;
    }


  .. ts:def:: PolicyEscrowedPayment

    // CAVEAT: THIS IS STILL WORK IN PROGRESS
    // This policy is optional and might not be supported by the exchange.
    // If it does, the exchange MUST show support for this policy in the
    // ``extensions`` field in the response to ``/keys``.
    interface PolicyEscrowedPayment {
      type: "escrowed_payment";

      // Public key of this trustor, the owner of the coins.
      //
      // To claim the deposit, the merchant must provide the valid signature
      // of the ``h_contract_terms`` field from the deposit, signed by _this_
      // key, to the ``/extensions/policy_escrow``-endpoint of the exchange,
      // after the date specified in ``not_before`` and before the date
      // specified in ``not_after``.
      trustor_pub: EddsaPublicKey;

      // Latest date by which the deposit must be claimed.  If the deposit
      // has not been claimed by that date, the deposited coins can be
      // refreshed by the (still) owner.
      deadline: Timestamp;
    }

  The deposit operation succeeds if the coin is valid for making a deposit and
  has enough residual value that has not already been deposited or melted.

  .. ts:def:: DepositSuccess

     interface DepositSuccess {
      // Optional base URL of the exchange for looking up wire transfers
      // associated with this transaction.  If not given,
      // the base URL is the same as the one used for this request.
      // Can be used if the base URL for ``/transactions/`` differs from that
      // for ``/coins/``, i.e. for load balancing.  Clients SHOULD
      // respect the ``transaction_base_url`` if provided.  Any HTTP server
      // belonging to an exchange MUST generate a 307 or 308 redirection
      // to the correct base URL should a client uses the wrong base
      // URL, or if the base URL has changed since the deposit.
      transaction_base_url?: string;

      // Timestamp when the deposit was received by the exchange.
      exchange_timestamp: Timestamp;

      // `Public EdDSA key of the exchange <sign-key-pub>` that was used to
      // generate the signature.
      // Should match one of the exchange's signing keys from ``/keys``.  It is given
      // explicitly as the client might otherwise be confused by clock skew as to
      // which signing key was used.
      exchange_pub: EddsaPublicKey;

      // Deposit confirmation signature from the exchange.
      // The EdDSA signature of `TALER_DepositConfirmationPS` using a current
      // `signing key of the exchange <sign-key-priv>` affirming the successful
      // deposit and that the exchange will transfer the funds after the refund
      // deadline, or as soon as possible if the refund deadline is zero.
      exchange_sig: EddsaSignature;
    }

  .. ts:def:: DepositDoubleSpendError

    interface DepositDoubleSpendError {

      // Must be TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS
      code: Integer;

      // A string explaining that the user tried to
      // double-spend.
      hint: string;

      // EdDSA public key of a coin being double-spent.
      coin_pub: EddsaPublicKey;

      // Transaction history for the coin that is
      // being double-spended.
      // DEPRECATED! Will be removed soon. Use
      // GET /coins/$COIN_PUB to get the history!
      history: CoinSpendHistoryItem[];
    }


----------
Refreshing
----------

Refreshing creates ``n`` new coins from ``m`` old coins, where the sum of
denominations of the new coins must be smaller than the sum of the old coins'
denominations plus melting (refresh) and withdrawal fees charged by the exchange.
The refreshing API can be used by wallets to melt partially spent coins, making
transactions with the freshly exchangeed coins unlinkabe to previous transactions
by anyone except the wallet itself.

However, the new coins are linkable from the private keys of all old coins
using the ``/refresh/link`` request.  While ``/refresh/link`` must be implemented by
the exchange to achieve taxability, wallets do not really ever need that part of
the API during normal operation.


.. http:post:: /csr-melt

  Obtain exchange-side input values in preparation for a
  melt step for certain denomination cipher types,
  specifically at this point for Clause-Schnorr blind
  signatures.

  **Request:** The request body must be a `MeltPrepareRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The request was successful, and the response is a `MeltPrepareResponse`.  Note that repeating exactly the same request
    will again yield the same response (assuming none of the denomination is expired).
  :http:statuscode:`404 Not found`:
    A denomination key is not known to the exchange.
  :http:statuscode:`410 Gone`:
    A requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was revoked. The response is a
    `DenominationExpiredMessage`. Clients must evaluate
    the error code provided to understand which of the
    cases this is and handle it accordingly.

  **Details:**

  .. ts:def:: MeltPrepareRequest

    interface WithdrawPrepareRequest {

      // Master seed for the Clause-schnorr R-value
      // creation.
      // Must not have been used in any prior request.
      rms: RefreshMasterSeed;

      // Array of denominations and coin offsets for
      // each of the fresh coins with a CS-cipher
      // denomination.
      nks: MeltPrepareDenomNonce[];

    }

  .. ts:def:: MeltPrepareDenomNonce

    interface MeltPrepareDenomNonce {

      // Offset of this coin in the list of
      // fresh coins. May not match the array offset
      // as the fresh coins may include non-CS
      // denominations as well.
      coin_offset: Integer;

      // Hash of the public key of the denomination the
      // request relates to. Must be a CS denomination type.
      denom_pub_hash: HashCode;
    }


  .. ts:def:: MeltPrepareResponse

    interface MeltPrepareResponse {
      // Responses for each request, in the same
      // order that was used in the request.
      ewvs: ExchangeWithdrawValue[];
    }


.. _refresh:
.. http:post:: /coins/$COIN_PUB/melt

  "Melts" a coin.  Invalidates the coins and prepares for exchanging of fresh
  coins.  Taler uses a global parameter ``kappa`` for the cut-and-choose
  component of the protocol, for which this request is the commitment.  Thus,
  various arguments are given ``kappa``-times in this step.  At present ``kappa``
  is always 3.

  The base URL for ``/coins/``-requests may differ from the main base URL of the
  exchange. The exchange MUST return a 307 or 308 redirection to the correct
  base URL if this is the case.

  :http:statuscode:`200 OK`:
    The request was successful.  The response body is `MeltResponse` in this case.
  :http:statuscode:`403 Forbidden`:
    One of the signatures is invalid.
  :http:statuscode:`404 Not found`:
    The exchange does not recognize the denomination key as belonging to the exchange,
    or it has expired.
    If the denomination key is unknown, the response will be
    a `DenominationUnknownMessage`.
  :http:statuscode:`409 Conflict`:
    The operation is not allowed as the coin has insufficient
    residual value, or because the same public key of the coin has been
    previously used with a different denomination.  Which case it is
    can be decided by looking at the error code
    (``TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS`` or
    ``TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY``).
    The response is `MeltForbiddenResponse` in both cases.
  :http:statuscode:`410 Gone`:
    The requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was revoked. The response is a
    `DenominationExpiredMessage`. Clients must evaluate
    the error code provided to understand which of the
    cases this is and handle it accordingly.

  **Details:**


  .. ts:def:: MeltRequest

    interface MeltRequest {

      // Hash of the denomination public key, to determine total coin value.
      denom_pub_hash: HashCode;

      // Signature over the `coin public key <eddsa-coin-pub>` by the denomination.
      denom_sig: DenominationSignature;

      // Signature by the `coin <coin-priv>` over the melt commitment.
      confirm_sig: EddsaSignature;

      // Amount of the value of the coin that should be melted as part of
      // this refresh operation, including melting fee.
      value_with_fee: Amount;

      // Melt commitment.  Hash over the various coins to be withdrawn.
      // See also ``TALER_refresh_get_commitment()``.
      rc: HashCode;

      // Master seed for the Clause-schnorr R-value
      // creation. Must match the /csr-melt request.
      // Must not have been used in any prior melt request.
      // Must be present if one of the fresh coin's
      // denominations is of type Clause-Schnorr.
      rms?: RefreshMasterSeed;

      // IFF the denomination has age restriction support, the client MUST
      // provide the SHA256 hash of the age commitment of the coin.
      // MUST be omitted otherwise.
      age_commitment_hash?: AgeCommitmentHash;
    }

  For details about the HKDF used to derive the new coin private keys and
  the blinding factors from ECDHE between the transfer public keys and
  the private key of the melted coin, please refer to the
  implementation in ``libtalerutil``.

  .. ts:def:: MeltResponse

    interface MeltResponse {
      // Which of the ``kappa`` indices does the client not have to reveal.
      noreveal_index: Integer;

      // Signature of `TALER_RefreshMeltConfirmationPS` whereby the exchange
      // affirms the successful melt and confirming the ``noreveal_index``.
      exchange_sig: EddsaSignature;

      // `Public EdDSA key <sign-key-pub>` of the exchange that was used to generate the signature.
      // Should match one of the exchange's signing keys from ``/keys``.  Again given
      // explicitly as the client might otherwise be confused by clock skew as to
      // which signing key was used.
      exchange_pub: EddsaPublicKey;

      // Base URL to use for operations on the refresh context
      // (so the reveal operation).  If not given,
      // the base URL is the same as the one used for this request.
      // Can be used if the base URL for ``/refreshes/`` differs from that
      // for ``/coins/``, i.e. for load balancing.  Clients SHOULD
      // respect the refresh_base_url if provided.  Any HTTP server
      // belonging to an exchange MUST generate a 307 or 308 redirection
      // to the correct base URL should a client uses the wrong base
      // URL, or if the base URL has changed since the melt.
      //
      // When melting the same coin twice (technically allowed
      // as the response might have been lost on the network),
      // the exchange may return different values for the ``refresh_base_url``.
      refresh_base_url?: string;

    }


  .. ts:def:: MeltForbiddenResponse

    interface MeltForbiddenResponse {
      // Text describing the error.
      hint: string;

      // Detailed error code.
      code: Integer;

      // The transaction list of the respective coin that failed to have sufficient funds left.
      // Note that only the transaction history for one bogus coin is given,
      // even if multiple coins would have failed the check.
      history: CoinSpendHistoryItem[];
    }


.. http:post:: /refreshes/$RCH/reveal

  Reveal previously committed values to the exchange, except for the values
  corresponding to the ``noreveal_index`` returned by the ``/coins/``-melt step.

  The $RCH is the hash over the refresh commitment from the ``/coins/``-melt step
  (note that the value is calculated independently by both sides and has never
  appeared *explicitly* in the protocol before).

  The base URL for ``/refreshes/``-requests may differ from the main base URL of
  the exchange. Clients SHOULD respect the ``refresh_base_url`` returned for the
  coin during melt operations. The exchange MUST return a
  307 or 308 redirection to the correct base URL if the client failed to
  respect the ``refresh_base_url`` or if the allocation has changed.

  Errors such as failing to do proper arithmetic when it comes to calculating
  the total of the coin values and fees are simply reported as bad requests.
  This includes issues such as melting the same coin twice in the same session,
  which is simply not allowed.  However, theoretically it is possible to melt a
  coin twice, as long as the ``value_with_fee`` of the two melting operations is
  not larger than the total remaining value of the coin before the melting
  operations. Nevertheless, this is not really useful.

  :http:statuscode:`200 OK`:
    The transfer private keys matched the commitment and the original request was well-formed.
    The response body is a `RevealResponse`.
  :http:statuscode:`409 Conflict`:
    There is a problem between the original commitment and the revealed private
    keys.  The returned information is proof of the mismatch, and therefore
    rather verbose, as it includes most of the original /refresh/melt request,
    but of course expected to be primarily used for diagnostics.
    The response body is a `RevealConflictResponse`.
  :http:statuscode:`410 Gone`:
    The requested denomination key (for the fresh coins) is not yet or no longer valid.
    It either before the validity start, past the expiration or was revoked. The response is a
    `DenominationExpiredMessage`. Clients must evaluate
    the error code provided to understand which of the
    cases this is and handle it accordingly.

  **Details:**

  Request body contains a JSON object with the following fields:

  .. ts:def:: RevealRequest

    interface RevealRequest {

      // Array of ``n`` new hash codes of denomination public keys to order.
      new_denoms_h: HashCode[];

      // Array of ``n`` entries with blinded coins,
      // matching the respective entries in ``new_denoms``.
      coin_evs: CoinEnvelope[];

      // ``kappa - 1`` transfer private keys (ephemeral ECDHE keys).
      transfer_privs: EddsaPrivateKey[];

      // Transfer public key at the ``noreveal_index``.
      transfer_pub: EddsaPublicKey;

      // Array of ``n`` signatures made by the wallet using the old coin's private key,
      // used later to verify the /refresh/link response from the exchange.
      // Signs over a `TALER_CoinLinkSignaturePS`.
      link_sigs: EddsaSignature[];

      // IFF the corresponding denomination has support for age restriction,
      // the client MUST provide the original age commitment, i. e. the
      // vector of public keys.
      // The size of the vector MUST be the number of age groups as defined by the
      // Exchange in the field ``.age_groups`` of the extension ``age_restriction``.
      old_age_commitment?: Edx25519PublicKey[];

    }


  .. ts:def:: RevealResponse

    type RevealResponse = BatchWithdrawResponse;


  .. ts:def:: RevealConflictResponse

    interface RevealConflictResponse {
      // Text describing the error.
      hint: string;

      // Detailed error code.
      code: Integer;

      // Commitment as calculated by the exchange from the revealed data.
      rc_expected: HashCode;

    }


.. http:get:: /coins/$COIN_PUB/link

  Link the old public key of a melted coin to the coin(s) that were exchanged during the refresh operation.

  **Request:**

  **Response:**

  :http:statuscode:`200 OK`:
    All commitments were revealed successfully.  The exchange returns an array (typically consisting of only one element), in which each each element of the array contains a `LinkResponse` entry with information about a melting session that the coin was used in.
  :http:statuscode:`404 Not found`:
    The exchange has no linkage data for the given public key, as the coin has not
    yet been involved in a refresh operation.

  **Details:**

  .. ts:def:: LinkResponse

    interface LinkResponse {
      // Transfer ECDHE public key corresponding to the ``coin_pub``, used to
      // compute the blinding factor and private key of the fresh coins.
      transfer_pub: EcdhePublicKey;

      // Array with (encrypted/blinded) information for each of the coins
      // exchangeed in the refresh operation.
      new_coins: NewCoinInfo[];
    }

  .. ts:def:: NewCoinInfo

    interface NewCoinInfo {
      // RSA public key of the exchangeed coin.
      denom_pub: RsaPublicKey;

      // Exchange's blinded signature over the fresh coin.
      ev_sig: BlindedDenominationSignature;

      // Blinded coin.
      coin_ev : CoinEnvelope;

      // Values contributed by the exchange during the
      // withdraw operation (see /csr-melt).
      ewv: ExchangeWithdrawValue;

      // Offset of this coin in the refresh operation.
      // Input needed to derive the private key.
      coin_idx: Integer;

      // Signature made by the old coin over the refresh request.
      // Signs over a `TALER_CoinLinkSignaturePS`.
      link_sig: EddsaSignature;

    }


------
Recoup
------

This API is only used if the exchange is either about to go out of
business or has had its private signing keys compromised (so in
either case, the protocol is only used in **abnormal**
situations).  In the above cases, the exchange signals to the
wallets that the emergency cash back protocol has been activated
by putting the affected denomination keys into the cash-back
part of the ``/keys`` response.  If and only if this has happened,
coins that were signed with those denomination keys can be cashed
in using this API.

.. http:post:: /coins/$COIN_PUB/recoup

  Demand that a coin be refunded via wire transfer to the original owner.

  The base URL for ``/coins/``-requests may differ from the main base URL of the
  exchange. The exchange MUST return a 307 or 308 redirection to the correct
  base URL if this is the case.

  The remaining amount on the coin will be credited to the reserve
  that ``$COIN_PUB`` was withdrawn from.

  Note that the original withdrawal fees will **not** be recouped.


  **Request:** The request body must be a `RecoupRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The request was successful, and the response is a `RecoupWithdrawalConfirmation`.
    Note that repeating exactly the same request
    will again yield the same response, so if the network goes down during the
    transaction or before the client can commit the coin signature to disk, the
    coin is not lost.
  :http:statuscode:`403 Forbidden`:
    The coin's signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The denomination key is unknown, or the blinded
    coin is not known to have been withdrawn.
    If the denomination key is unknown, the response will be
    a `DenominationUnknownMessage`.
  :http:statuscode:`409 Conflict`:
    The operation is not allowed as the coin has insufficient
    residual value, or because the same public key of the coin has been
    previously used with a different denomination.  Which case it is
    can be decided by looking at the error code
    (usually ``TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS``).
    The response is a `DepositDoubleSpendError`.
  :http:statuscode:`410 Gone`:
    The requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was not yet revoked. The response is a
    `DenominationExpiredMessage`. Clients must evaluate
    the error code provided to understand which of the
    cases this is and handle it accordingly.

  **Details:**

  .. ts:def:: RecoupRequest

    interface RecoupRequest {
      // Hash of denomination public key, specifying the type of coin the client
      // would like the exchange to pay back.
      denom_pub_hash: HashCode;

      // Signature over the `coin public key <eddsa-coin-pub>` by the denomination.
      denom_sig: DenominationSignature;

      // Exchange-contributed values during the refresh
      // operation (see /csr-withdraw).
      ewv: ExchangeWithdrawValue;

      // Signature of `TALER_RecoupRequestPS` created with
      // the `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;

      // Coin's blinding factor.
      coin_blind_key_secret: DenominationBlindingKeySecret;

      // Nonce that was used by the exchange to derive
      // its private inputs from during withdraw. Only
      // present if the cipher of the revoked denomination
      // is of type Clause-Schnorr (CS).
      cs_nonce?: CSNonce;
    }


  .. ts:def:: RecoupWithdrawalConfirmation

    interface RecoupWithdrawalConfirmation {
      // Public key of the reserve that will receive the recoup.
      reserve_pub: EddsaPublicKey;
    }


.. http:post:: /coins/$COIN_PUB/recoup-refresh

  Demand that a coin be refunded via wire transfer to the original owner.

  The base URL for ``/coins/``-requests may differ from the main base URL of the
  exchange. The exchange MUST return a 307 or 308 redirection to the correct
  base URL if this is the case.

  The remaining amount on the coin will be credited to
  the old coin that ``$COIN_PUB`` was refreshed from.

  Note that the original refresh fees will **not** be recouped.


  **Request:** The request body must be a `RecoupRefreshRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The request was successful, and the response is a `RecoupRefreshConfirmation`.
    Note that repeating exactly the same request
    will again yield the same response, so if the network goes down during the
    transaction or before the client can commit the coin signature to disk, the
    coin is not lost.
  :http:statuscode:`403 Forbidden`:
    The coin's signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The denomination key is unknown, or the blinded
    coin is not known to have been withdrawn.
    If the denomination key is unknown, the response will be
    a `DenominationUnknownMessage`.
  :http:statuscode:`409 Conflict`:
    The operation is not allowed as the coin has insufficient
    residual value, or because the same public key of the coin has been
    previously used with a different denomination.  Which case it is
    can be decided by looking at the error code
    (usually ``TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_BALANCE``).
    The response is a `DepositDoubleSpendError`.
  :http:statuscode:`410 Gone`:
    The requested denomination key is not yet or no longer valid.
    It either before the validity start, past the expiration or was not yet revoked. The response is a
    `DenominationExpiredMessage`. Clients must evaluate
    the error code provided to understand which of the
    cases this is and handle it accordingly.

  **Details:**

  .. ts:def:: RecoupRefreshRequest

    interface RecoupRefreshRequest {
      // Hash of denomination public key, specifying the type of coin the client
      // would like the exchange to pay back.
      denom_pub_hash: HashCode;

      // Signature over the `coin public key <eddsa-coin-pub>` by the denomination.
      denom_sig: DenominationSignature;

      // Exchange-contributed values during the refresh
      // operation (see /csr-melt).
      ewv: ExchangeWithdrawValue;

      // Signature of `TALER_RecoupRequestPS` created with
      // the `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;

      // Coin's blinding factor.
      coin_blind_key_secret: DenominationBlindingKeySecret;

      // Nonce that was used by the exchange to derive
      // its private inputs from during withdraw. Only
      // present if the cipher of the revoked denomination
      // is of type Clause-Schnorr (CS).
      cs_nonce?: CSNonce;
    }


  .. ts:def:: RecoupRefreshConfirmation

    interface RecoupRefreshConfirmation {
      // Public key of the old coin that will receive the recoup.
      old_coin_pub: EddsaPublicKey;
    }


-----------------------
Tracking wire transfers
-----------------------

This API is used by merchants that need to find out which wire
transfers (from the exchange to the merchant) correspond to which deposit
operations.  Typically, a merchant will receive a wire transfer with a
**wire transfer identifier** and want to know the set of deposit
operations that correspond to this wire transfer.  This is the
preferred query that merchants should make for each wire transfer they
receive.  If a merchant needs to investigate a specific deposit
operation (i.e. because it seems that it was not paid), then the
merchant can also request the wire transfer identifier for a deposit
operation.

Sufficient information is returned to verify that the coin signatures
are correct. This also allows governments to use this API when doing
a tax audit on merchants.

Naturally, the returned information may be sensitive for the merchant.
We do not require the merchant to sign the request, as the same requests
may also be performed by the government auditing a merchant.
However, wire transfer identifiers should have sufficient entropy to
ensure that obtaining a successful reply by brute-force is not practical.
Nevertheless, the merchant should protect the wire transfer identifiers
from his bank statements against unauthorized access, lest his income
situation is revealed to an adversary. (This is not a major issue, as
an adversary that has access to the line-items of bank statements can
typically also view the balance.)


.. http:get:: /transfers/$WTID

  Provides deposits associated with a given wire transfer.  The
  wire transfer identifier (WTID) and the base URL for tracking
  the wire transfer are both given in the wire transfer subject.

  **Request:**

  **Response:**

  :http:statuscode:`200 OK`:
    The wire transfer is known to the exchange, details about it follow in the body.
    The body of the response is a `TrackTransferResponse`.
  :http:statuscode:`404 Not found`:
    The wire transfer identifier is unknown to the exchange.

  .. ts:def:: TrackTransferResponse

    interface TrackTransferResponse {
      // Actual amount of the wire transfer, excluding the wire fee.
      total: Amount;

      // Applicable wire fee that was charged.
      wire_fee: Amount;

      // Public key of the merchant (identical for all deposits).
      merchant_pub: EddsaPublicKey;

      // Hash of the payto:// account URI (identical for all deposits).
      h_payto: PaytoHash;

      // Time of the execution of the wire transfer by the exchange.
      execution_time: Timestamp;

      // Details about the deposits.
      deposits: TrackTransferDetail[];

      // Signature from the exchange made with purpose
      // ``TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT``
      // over a `TALER_WireDepositDataPS`.
      exchange_sig: EddsaSignature;

      // Public EdDSA key of the exchange that was used to generate the signature.
      // Should match one of the exchange's signing keys from ``/keys``.  Again given
      // explicitly as the client might otherwise be confused by clock skew as to
      // which signing key was used.
      exchange_pub: EddsaSignature;
    }

  .. ts:def:: TrackTransferDetail

    interface TrackTransferDetail {
      // SHA-512 hash of the contact of the merchant with the customer.
      h_contract_terms: HashCode;

      // Coin's public key, both ECDHE and EdDSA.
      coin_pub: CoinPublicKey;

      // The total amount the original deposit was worth,
      // including fees and after applicable refunds.
      deposit_value: Amount;

      // Applicable fees for the deposit, possibly
      // reduced or waived due to refunds.
      deposit_fee: Amount;

      // Refunds that were applied to the value of
      // this coin. Optional.
      // Since protocol **v19**.  Before, refunds were
      // incorrectly still included in the
      // ``deposit_value`` (!).
      refund_total?: Amount;

    }

.. http:get:: /deposits/$H_WIRE/$MERCHANT_PUB/$H_CONTRACT_TERMS/$COIN_PUB

  Provide the wire transfer identifier associated with an (existing) deposit operation.
  The arguments are the hash of the merchant's payment details (H_WIRE), the
  merchant's public key (EdDSA), the hash of the contract terms that were paid
  (H_CONTRACT_TERMS) and the public key of the coin used for the payment (COIN_PUB).

  **Request:**

  :query merchant_sig: EdDSA signature of the merchant made with purpose
    ``TALER_SIGNATURE_MERCHANT_TRACK_TRANSACTION`` over a
    ``TALER_DepositTrackPS``, affirming that it is really the merchant who
    requires obtaining the wire transfer identifier.
  :query timeout_ms=NUMBER: *Optional.* If specified, the exchange will wait
    up to ``NUMBER`` milliseconds for completion of a deposit operation before
    sending the HTTP response.

  **Response:**

  :http:statuscode:`200 OK`:
    The deposit has been executed by the exchange and we have a wire transfer identifier.
    The response body is a `TrackTransactionResponse` object.
  :http:statuscode:`202 Accepted`:
    The deposit request has been accepted for processing, but was not yet
    executed.  Hence the exchange does not yet have a wire transfer identifier.  The
    merchant should come back later and ask again.
    The response body is a `TrackTransactionAcceptedResponse`.
  :http:statuscode:`403 Forbidden`:
    A signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The deposit operation is unknown to the exchange.

  **Details:**

  .. ts:def:: TrackTransactionResponse

    interface TrackTransactionResponse {

      // Raw wire transfer identifier of the deposit.
      wtid: Base32;

      // When was the wire transfer given to the bank.
      execution_time: Timestamp;

      // The contribution of this coin to the total (without fees)
      coin_contribution: Amount;

      // Binary-only Signature_ with purpose ``TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE``
      // over a `TALER_ConfirmWirePS`
      // whereby the exchange affirms the successful wire transfer.
      exchange_sig: EddsaSignature;

      // Public EdDSA key of the exchange that was used to generate the signature.
      // Should match one of the exchange's signing keys from /keys.  Again given
      // explicitly as the client might otherwise be confused by clock skew as to
      // which signing key was used.
      exchange_pub: EddsaPublicKey;
    }

  .. ts:def:: TrackTransactionAcceptedResponse

    interface TrackTransactionAcceptedResponse {

      // Legitimization target that the merchant should
      // use to check for its KYC status using
      // the ``/kyc-check/$REQUIREMENT_ROW/...`` endpoint.
      // Optional, not present if the deposit has not
      // yet been aggregated to the point that a KYC
      // need has been evaluated.
      requirement_row?: Integer;

      // Current AML state for the target account. Non-zero
      // values indicate that the transfer is blocked due to
      // AML enforcement.
      aml_decision: Integer;

      // True if the KYC check for the merchant has been
      // satisfied.  False does not mean that KYC
      // is strictly needed, unless also a
      // legitimization_uuid is provided.
      kyc_ok: boolean;

      // Time by which the exchange currently thinks the deposit will be executed.
      // Actual execution may be later if the KYC check is not satisfied by then.
      execution_time: Timestamp;
    }


.. _exchange_refund:

-------
Refunds
-------

.. http:post:: /coins/$COIN_PUB/refund

  Undo deposit of the given coin, restoring its value.

  **Request:** The request body must be a `RefundRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange confirms that the coin can now be refreshed.  The response will include a `RefundSuccess` object.
  :http:statuscode:`403 Forbidden`:
    Merchant signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The refund operation failed as we could not find a matching deposit operation (coin, contract, transaction ID and merchant public key must all match).
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`409 Conflict`:
    The exchange has previously received a refund request for the same coin, merchant and contract, but specifying a different amount for the same refund transaction ID.  The response will be a `RefundFailure` object.
  :http:statuscode:`410 Gone`:
    It is too late for a refund by the exchange, the money was already sent to the merchant.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`412 Precondition failed`:
    The request transaction ID is identical to a previous refund request by the same
    merchant for the same coin and contract, but the refund amount differs. (The
    failed precondition is that the ``rtransaction_id`` is not unique.)
    The response will be a `RefundFailure` object with the conflicting refund request.

  **Details:**

  .. ts:def:: RefundRequest

     interface RefundRequest {

      // Amount to be refunded, can be a fraction of the
      // coin's total deposit value (including deposit fee);
      // must be larger than the refund fee.
      refund_amount: Amount;

      // SHA-512 hash of the contact of the merchant with the customer.
      h_contract_terms: HashCode;

      // 64-bit transaction id of the refund transaction between merchant and customer.
      rtransaction_id: Integer;

      // EdDSA public key of the merchant.
      merchant_pub: EddsaPublicKey;

      // EdDSA signature of the merchant over a
      // `TALER_RefundRequestPS` with purpose
      // ``TALER_SIGNATURE_MERCHANT_REFUND``
      // affirming the refund.
      merchant_sig: EddsaPublicKey;

    }

  .. ts:def:: RefundSuccess

    interface RefundSuccess {

      // The EdDSA :ref:`signature` (binary-only) with purpose
      // ``TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND`` over
      // a `TALER_RecoupRefreshConfirmationPS`
      // using a current signing key of the
      // exchange affirming the successful refund.
      exchange_sig: EddsaSignature;

      // Public EdDSA key of the exchange that was used to generate the signature.
      // Should match one of the exchange's signing keys from ``/keys``.  It is given
      // explicitly as the client might otherwise be confused by clock skew as to
      // which signing key was used.
      exchange_pub: EddsaPublicKey;
   }

  .. ts:def:: RefundFailure

    interface RefundFailure {

      // Numeric error code unique to the condition, which can be either
      // related to the deposit value being insufficient for the requested
      // refund(s), or the requested refund conflicting due to refund
      // transaction number re-use (with different amounts).
      code: Integer;

      // Human-readable description of the error message.
      hint: string;

      // Information about the conflicting refund request(s).
      // This will not be the full history of the coin, but only
      // the relevant subset of the transactions.
      history: CoinSpendHistoryItem[];
    }


.. _exchange_w2w:

--------------------------
Wallet-to-wallet transfers
--------------------------

.. http:get:: /purses/$PURSE_PUB/merge
.. http:get:: /purses/$PURSE_PUB/deposit

  Obtain information about a purse.  Depending on the suffix,
  the long-polling (if any) will wait for either a merge or
  a deposit event.

  **Request:**

  :query timeout_ms=NUMBER: *Optional.*  If specified,
    the exchange
    will wait up to ``NUMBER`` milliseconds for completion
    of a merge operation before sending the HTTP response.
  :query deposit_timeout_ms=NUMBER: *Optional.*  If specified,
    the exchange
    will wait up to ``NUMBER`` milliseconds for completion
    of a deposit operation before sending the HTTP response.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange provides details
    about the purse.
    The response will include a `PurseStatus` object.
  :http:statuscode:`404 Not found`:
    The purse is unknown to the exchange.
  :http:statuscode:`410 Gone`:
    The purse expired before the deposit or merge was completed.

  **Details:**

  .. ts:def:: PurseStatus

     interface PurseStatus {

      // Total amount deposited into the purse so far.
      // If 'total_deposit_amount' minus 'deposit_fees'
      // exceeds 'merge_value_after_fees', and a
      // 'merge_request' exists for the purse, then the
      // purse will (have been) merged with the account.
      balance: Amount;

      // When does the purge expire.
      purse_expiration: Timestamp;

      // Time of the merge, missing if "never".
      merge_timestamp?: Timestamp;

      // Time of the deposits being complete, missing if "never".
      // Note that this time may not be "stable": once sufficient
      // deposits have been made, is "now" before the purse
      // expiration, and otherwise set to the purse expiration.
      // However, this should also not be relied upon. The key
      // property is that it is either "never" or in the past.
      deposit_timestamp?: Timestamp;

      // Time when the purse expires and
      // funds that were not merged are refunded
      // on the deposited coins.
      // FIXME: Document the exchange protocol version
      //        in which this field became available.
      purse_expiration: Timestamp;

      // EdDSA signature of the exchange over a
      // `TALER_PurseStatusResponseSignaturePS`
      // with purpose ``TALER_SIGNATURE_PURSE_STATUS_RESPONSE``
      // affirming the purse status.
      exchange_sig: EddsaSignature;

      // EdDSA public key exchange used for 'exchange_sig'.
      exchange_pub: EddsaPublicKey;

    }



.. http:post:: /purses/$PURSE_PUB/create

  Create a purse by depositing money into it. First step of a PUSH payment.

  **Request:**

  The request body must be a `PurseCreate` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange confirms that all
    coins were deposited into the purse.
    The response will include a `PurseDepositSuccess` object.
  :http:statuscode:`403 Forbidden`:
    A coin, denomination or contract signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not Found`:
    The denomination of one of the coins is unknown to the exchange.
  :http:statuscode:`409 Conflict`:
    The deposit operation has either failed because a coin has insufficient
    residual value, or because the same public key of the coin has been
    previously used with a different denomination, or because a purse with
    the same public key but different meta data was created previously.
    Which case it is
    can be decided by looking at the error code
    (``TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS`` or
    ``TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY`` or
    ``TALER_EC_EXCHANGE_PURSE_CREATE_CONFLICTING_META_DATA`` or
    ``TALER_EC_EXCHANGE_PURSE_DEPOSIT_CONFLICTING_META_DATA`` or
    ``TALER_EC_EXCHANGE_PURSE_ECONTRACT_CONFLICTING_META_DATA``).
    The specific fields of the response depend on the error code
    and include the signatures (and what was signed over) proving the
    conflict.
  :http:statuscode:`425 Too Early`:
    This response type is used if the given purse expiration time
    is too far in the future (at least from the perspective
    of the exchange). Thus, retrying at a later time may
    succeed. The client should look at the ``Date:`` header
    of the response to see if a minor time difference is to
    blame and possibly adjust the request accordingly.
    (Note: this status code is not yet used.)


  **Details:**

  .. ts:def:: PurseCreate

    interface PurseCreate {

      // Total value of the purse, excluding fees.
      amount: Amount;

      // Minimum age required for all coins deposited into the purse.
      min_age: Integer;

      // Optional encrypted contract, in case the buyer is
      // proposing the contract and thus establishing the
      // purse with the payment.
      econtract?: EncryptedContract;

      // EdDSA public key used to approve merges of this purse.
      merge_pub: EddsaPublicKey;

      // EdDSA signature of the purse over a
      // `TALER_PurseRequestSignaturePS`
      // of purpose ``TALER_SIGNATURE_WALLET_PURSE_CREATE``
      // confirming the key
      // invariants associated with the purse.
      // (amount, h_contract_terms, expiration).
      purse_sig: EddsaSignature;

      // SHA-512 hash of the contact of the purse.
      h_contract_terms: HashCode;

      // Array of coins being deposited into the purse.
      // Maximum length is 128.
      deposits: PurseDeposit[];

      // Indicative time by which the purse should expire
      // if it has not been merged into an account. At this
      // point, all of the deposits made will be auto-refunded.
      purse_expiration: Timestamp;

    }

  .. ts:def:: EncryptedContract

    interface EncryptedContract {

      // Encrypted contract.
      econtract: string;

      // Signature over the (encrypted) contract.
      econtract_sig: EddsaSignature;

      // Ephemeral public key for the DH operation to decrypt the encrypted contract.
      contract_pub: EddsaPublicKey;

    }

  .. ts:def:: PurseDeposit

    interface PurseDeposit {

      // Amount to be deposited, can be a fraction of the
      // coin's total value.
      amount: Amount;

      // Hash of denomination RSA key with which the coin is signed.
      denom_pub_hash: HashCode;

      // Exchange's unblinded RSA signature of the coin.
      ub_sig: DenominationSignature;

      // Age commitment for the coin, if the denomination is age-restricted.
      age_commitment?: AgeCommitment;

      // Attestation for the minimum age, if the denomination is age-restricted.
      attest?: Attestation;

      // Signature over `TALER_PurseDepositSignaturePS`
      // of purpose ``TALER_SIGNATURE_WALLET_PURSE_DEPOSIT``
      // made by the customer with the
      // `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;

      // Public key of the coin being deposited into the purse.
      coin_pub: EddsaPublicKey;

    }

  .. ts:def:: PurseDepositSuccess

     interface PurseDepositSuccess {

      // Total amount deposited into the purse so far (without fees).
      total_deposited: Amount;

      // Time at the exchange.
      exchange_timestamp: Timestamp;

      // EdDSA signature of the exchange affirming the payment,
      // of purpose ``TALER_SIGNATURE_PURSE_DEPOSIT_CONFIRMED``
      // over a `TALER_PurseDepositConfirmedSignaturePS`.
      // Signs over the above and the purse public key and
      // the hash of the contract terms.
      exchange_sig: EddsaSignature;

      // public key used to create the signature.
      exchange_pub: EddsaPublicKey;

    }

  .. ts:def:: PurseConflict

    // Union discriminated by the "code" field.
    type PurseConflict =
    | DepositDoubleSpendError
    | PurseCreateConflict
    | PurseDepositConflict
    | PurseContractConflict;

  .. ts:def:: PurseCreateConflict

    interface PurseCreateConflict {
      // Must be equal to TALER_EC_EXCHANGE_PURSE_CREATE_CONFLICTING_META_DATA
      code: Integer;

      // Total amount to be merged into the reserve.
      // (excludes fees).
      amount: Amount;

      // Minimum age required for all coins deposited into the purse.
      min_age: Integer;

      // Indicative time by which the purse should expire
      // if it has not been merged into an account. At this
      // point, all of the deposits made should be
      // auto-refunded.
      purse_expiration: Timestamp;

      // EdDSA signature of the purse over
      // `TALER_PurseMergeSignaturePS` of
      // purpose ``TALER_SIGNATURE_WALLET_PURSE_MERGE``
      // confirming that the
      // above details hold for this purse.
      purse_sig: EddsaSignature;

      // SHA-512 hash of the contact of the purse.
      h_contract_terms: HashCode;

      // EdDSA public key used to approve merges of this purse.
      merge_pub: EddsaPublicKey;
    }

  .. ts:def:: PurseDepositConflict

    interface PurseDepositConflict {
      // Must be equal to TALER_EC_EXCHANGE_PURSE_DEPOSIT_CONFLICTING_META_DATA
      code: Integer;

      // Public key of the coin being deposited into the purse.
      coin_pub: EddsaPublicKey;

      // Signature over `TALER_PurseDepositSignaturePS`
      // of purpose ``TALER_SIGNATURE_WALLET_PURSE_DEPOSIT``
      // made by the customer with the
      // `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;

      // Target exchange URL for the purse. Not present for the
      // same exchange.
      partner_url?: string;

      // Amount to be contributed to the purse by this coin.
      amount: Amount;

    }

  .. ts:def:: PurseContractConflict

    interface PurseContractConflict {
      // Must be equal to TALER_EC_EXCHANGE_PURSE_ECONTRACT_CONFLICTING_META_DATA
      code: Integer;

      // Hash of the encrypted contract.
      h_econtract: HashCode;

      // Signature over the contract.
      econtract_sig: EddsaSignature;

      // Ephemeral public key for the DH operation to decrypt the contract.
      contract_pub: EddsaPublicKey;

    }



.. http:delete:: /purses/$PURSE_PUB

  Delete a purse that is unmerged and not yet expired. Refunds any money that
  is already in the purse.

  **Request:**

  The request body must be empty, as recommended for HTTP delete in general.
  To authorize the request, the header must contain a
  ``Taler-Purse-Signature: $PURSE_SIG`` where ``$PURSE_SIG`` is the Crockford base32-encoded
  EdDSA signature of purpose TALER_SIGNATURE_WALLET_PURSE_DELETE.

  **Response:**

  :http:statuscode:`204 No Content`:
    The operation succeeded, the exchange confirms that the purse
    was deleted.
  :http:statuscode:`403 Forbidden`:
    The signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not Found`:
    The purse is not known. Might have already been deleted previously.
  :http:statuscode:`409 Conflict`:
    It is too late to delete the purse, its fate (merge or expiration)
    was already decided.


.. http:post:: /purses/$PURSE_PUB/merge

  Merge purse with account, adding the value of the purse into
  the account.  Endpoint to be used by the receiver of a PUSH payment.

  **Request:**

  The request body must be a `MergeRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange confirms that the
    funds were merged into the account.
    The response will include a `MergeSuccess` object.
  :http:statuscode:`402 Payment Required`:
    The purse is not yet full and more money needs to be deposited
    before the merge can be made.
  :http:statuscode:`403 Forbidden`:
    The signature of the merge request or the reserve was invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The merge operation failed as we could not find the purse
    or the partner exchange.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`409 Conflict`:
    The purse was already merged into a different reserve.
    The response will include a `MergeConflict` object.
  :http:statuscode:`410 Gone`:
    The purse has already expired and thus can no longer be merged.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`451 Unavailable For Legal Reasons`:
    This account has not yet passed the KYC checks.
    The client must pass KYC checks before proceeding with the merge.
    The response will be an `KycNeededRedirect` object.

  **Details:**

  .. ts:def:: MergeRequest

    interface MergeRequest {

      // payto://-URI of the account the purse is to be merged into.
      // Must be of the form: 'payto://taler/$EXCHANGE_URL/$RESERVE_PUB'.
      payto_uri: string;

      // EdDSA signature of the account/reserve affirming the merge
      // over a `TALER_AccountMergeSignaturePS`.
      // Must be of purpose ``TALER_SIGNATURE_ACCOUNT_MERGE``
      reserve_sig: EddsaSignature;

      // EdDSA signature of the merge private key affirming the merge
      // over a `TALER_PurseMergeSignaturePS`.
      // Must be of purpose ``TALER_SIGNATURE_PURSE_MERGE``.
      merge_sig: EddsaSignature;

      // Client-side timestamp of when the merge request was made.
      merge_timestamp: Timestamp;

    }

  .. ts:def:: MergeSuccess

     interface MergeSuccess {

      // Amount merged (excluding deposit fees).
      merge_amount: Amount;

      // Time at which the merge came into effect.
      // Maximum of the "payment_timestamp" and the
      // "merge_timestamp".
      exchange_timestamp: Timestamp;

      // EdDSA signature of the exchange affirming the merge of
      // purpose ``TALER_SIGNATURE_PURSE_MERGE_SUCCESS``
      // over `TALER_PurseMergeSuccessSignaturePS`.
      // Signs over the above and the account public key.
      exchange_sig: EddsaSignature;

      // public key used to create the signature.
      exchange_pub: EddsaPublicKey;

    }

  .. ts:def:: MergeConflict

    interface MergeConflict {

      // Client-side timestamp of when the merge request was made.
      merge_timestamp: Timestamp;

      // EdDSA signature of the purse private key affirming the merge
      // over a `TALER_PurseMergeSignaturePS`.
      // Must be of purpose ``TALER_SIGNATURE_PURSE_MERGE``.
      merge_sig: EddsaSignature;

      // Base URL of the exchange receiving the payment, only present
      // if the exchange hosting the reserve is not this exchange.
      partner_url?: string;

      // Public key of the reserve that the purse was merged into.
      reserve_pub: EddsaPublicKey;
    }



.. http:post:: /reserves/$RESERVE_PUB/purse

  Create purse for an account.  First step of a PULL payment.

  **Request:**

  The request body must be a `ReservePurseRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange confirms that the
    purse was allocated.
    The response will include a `PurseDepositSuccess` object.
  :http:statuscode:`402 Payment Required`:
    The account needs to contain more funding to create more purses.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`403 Forbidden`:
    Account or contract signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The purse creation operation failed as we could not find the reserve.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`409 Conflict`:
    The purse creation failed because a purse with
    the same public key but different meta data was
    created previously.  Which specific conflict it is
    can be decided by looking at the error code
    (``TALER_EC_EXCHANGE_PURSE_CREATE_CONFLICTING_META_DATA`` or
    ``TALER_EC_EXCHANGE_PURSE_DEPOSIT_CONFLICTING_META_DATA`` or
    ``TALER_EC_EXCHANGE_PURSE_ECONTRACT_CONFLICTING_META_DATA``).
    The specific fields of the response depend on the error code
    and include the signatures (and what was signed over) proving the
    conflict.
    The response will be a `PurseConflict` response
    (but not a `DepositDoubleSpendError`).
  :http:statuscode:`451 Unavailable For Legal Reasons`:
    This account has not yet passed the KYC checks.
    The client must pass KYC checks before proceeding with the merge.
    The response will be an `KycNeededRedirect` object.

  **Details:**

  .. ts:def:: ReservePurseRequest

    interface ReservePurseRequest {

      // Minimum amount that must be credited to the reserve, that is
      // the total value of the purse minus the deposit fees.
      // If the deposit fees are lower, the contribution to the
      // reserve can be higher!
      purse_value: Amount;

      // Minimum age required for all coins deposited into the purse.
      min_age: Integer;

      // Purse fee the reserve owner is willing to pay
      // for the purse creation. Optional, if not present
      // the purse is to be created from the purse quota
      // of the reserve.
      purse_fee: Amount;

      // Optional encrypted contract, in case the buyer is
      // proposing the contract and thus establishing the
      // purse with the payment.
      econtract?: EncryptedContract;

      // EdDSA public key used to approve merges of this purse.
      merge_pub: EddsaPublicKey;

      // EdDSA signature of the purse private key affirming the merge
      // over a `TALER_PurseMergeSignaturePS`.
      // Must be of purpose ``TALER_SIGNATURE_PURSE_MERGE``.
      merge_sig: EddsaSignature;

      // EdDSA signature of the account/reserve affirming the merge.
      // Must be of purpose ``TALER_SIGNATURE_WALLET_ACCOUNT_MERGE``
      reserve_sig: EddsaSignature;

      // Purse public key.
      purse_pub: EddsaPublicKey;

      // EdDSA signature of the purse over
      // `TALER_PurseRequestSignaturePS` of
      // purpose ``TALER_SIGNATURE_PURSE_REQUEST``
      // confirming that the
      // above details hold for this purse.
      purse_sig: EddsaSignature;

      // SHA-512 hash of the contact of the purse.
      h_contract_terms: HashCode;

      // Client-side timestamp of when the merge request was made.
      merge_timestamp: Timestamp;

      // Indicative time by which the purse should expire
      // if it has not been paid.
      purse_expiration: Timestamp;

    }


.. http:post:: /purses/$PURSE_PUB/deposit

  Deposit money into a purse. Used by the buyer for a PULL payment.

  **Request:**

  The request body must be a `PurseDeposits` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange confirms that all
    coins were deposited into the purse.
    The response will include a `PurseDepositSuccess` object.
  :http:statuscode:`403 Forbidden`:
    A coin or denomination signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The purse is unknown.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`409 Conflict`:
    The deposit operation has either failed because a coin has insufficient
    residual value, or because the same public key of the coin has been
    previously used with a different denomination.  Which case it is
    can be decided by looking at the error code
    (``TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS`` or
    ``TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY`` or
    ``TALER_EC_EXCHANGE_PURSE_DEPOSIT_CONFLICTING_META_DATA``).
    This response comes with a standard `PurseConflict` response
    (alas some cases are impossible).
  :http:statuscode:`410 Gone`:
    The purse has expired.


  **Details:**

   .. ts:def:: PurseDeposits

    interface PurseDeposits {

      // Array of coins to deposit into the purse.
      deposits: PurseDeposit[];
    }

  .. ts:def:: PurseDeposit

    interface PurseDeposit {

      // Amount to be deposited, can be a fraction of the
      // coin's total value.
      amount: Amount;

      // Hash of denomination RSA key with which the coin is signed.
      denom_pub_hash: HashCode;

      // Exchange's unblinded RSA signature of the coin.
      ub_sig: DenominationSignature;

      // Age commitment for the coin, if the denomination is age-restricted.
      age_commitment?: AgeCommitment;

      // Attestation for the minimum age, if the denomination is age-restricted.
      attest?: Attestation;

      // Signature over `TALER_PurseDepositSignaturePS`
      // of purpose ``TALER_SIGNATURE_WALLET_PURSE_DEPOSIT``
      // made by the customer with the
      // `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;

      // Public key of the coin being deposited into the purse.
      coin_pub: EddsaPublicKey;

    }

  .. ts:def:: PurseDepositSuccess

     interface PurseDepositSuccess {

      // Total amount paid into the purse.
      total_deposited: Amount;

      // Total amount expected in the purse.
      purse_value_after_fees: Amount;

      // Time at which the deposit came into effect.
      exchange_timestamp: Timestamp;

      // Indicative time by which the purse should expire
      // if it has not been merged into an account. At this
      // point, all of the deposits made will be auto-refunded.
      purse_expiration: Timestamp;

      // SHA-512 hash of the contact of the purse.
      h_contract_terms: HashCode;

      // EdDSA signature of the exchange affirming the payment,
      // of purpose ``TALER_SIGNATURE_PURSE_DEPOSIT_CONFIRMED``
      // over a `TALER_PurseDepositConfirmedSignaturePS`.
      // Signs over the above and the purse public key and
      // the hash of the contract terms.
      exchange_sig: EddsaSignature;

      // public key used to create the signature.
      exchange_pub: EddsaPublicKey;

    }

  .. ts:def:: AgeCommitment

     // AgeCommitment is an array of public keys, one for each age group of the
     // age-restricted denomination.
     type AgeCommitment = Edx25519PublicKey[];

  .. ts:def:: Attestation

     // An attestation for a minimum age is an Edx25519 signature of the age
     // with purpose ``TALER_SIGNATURE_WALLET_AGE_ATTESTATION``.
     type Attestation = string;

.. _exchange_wads:


----
Wads
----

  .. note::

     This is a draft API that is not yet implemented.


These endpoints are used to manage exchange-to-exchange payments in support of
wallet-to-wallet payments.  Only another exchange should access this endpoint.


.. http:get:: /wads/$WAD_ID

  Obtain information about a wad.

  **Request:**

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange provides details
    about the wad.
    The response will include a `WadDetails` object.
  :http:statuscode:`404 Not found`:
    The wad is unknown to the exchange.

  **Details:**

  .. ts:def:: WadDetails

     interface WadDetails {

      // Total transfer amount claimed by the exchange.
      total: Amount;

      // Indicative time by which the wad was given to the
      // bank to execute the wire transfer.
      wad_execution_time: Timestamp;

      // Transfers aggregated in the wad.
      items: WadItem[];

      // EdDSA signature of the exchange affirming the wad
      // data is correct, must be over `TALER_WadDataSignaturePS`
      // and of purpose ``TALER_SIGNATURE_WAD_DATA``.
      exchange_sig: EddsaSignature;

      // public key used to create the signature.
      exchange_pub: EddsaPublicKey;
     }

  Objects in the wad item list have the following format:

  .. ts:def:: WadItem

    interface WadItem {

      // Amount in the purse.
      amount: Amount;

      // payto://-URI of the account the purse is to be merged into.
      // Must be of the form: 'payto://taler/EXCHANGE_URL/RESERVE_PUB'.
      payto_uri: string;

      // Purse public key.
      purse_pub: EddsaPublicKey;

      // Hash of the contract.
      h_contract: HashCode;

      // Indicative time by which the purse should expire
      // if it has not been paid.
      purse_expiration: Timestamp;

      // Client-side timestamp of when the merge request was made.
      merge_timestamp: Timestamp;

      // Signature created with the reserve's private key.
      // Must be of purpose ``TALER_SIGNATURE_ACCOUNT_MERGE``
      // and over `TALER_AccountMergeSignaturePS`.
      reserve_sig: EddsaSignature;

      // Signature created with the purse's private key.
      // Must be of purpose ``TALER_SIGNATURE_PURSE_MERGE``
      // and over `TALER_PurseMergeSignaturePS`.
      purse_sig: EddsaSignature;

      // Deposit fees that were charged to the purse.
      deposit_fees: Amount;

      // Wad fees that was charged to the purse.
      wad_fees: Amount;
    }


------------------
KYC status updates
------------------

This section describes endpoints used to set up, complete and
inquire about KYC operations performed by an exchange for
regulatory compliance.

.. http:post:: /kyc-wallet

  Setup KYC identification for a wallet.  Returns the KYC UUID.
  This endpoint is used by compliant Taler wallets when they
  are about to hit the balance threshold and thus need to have
  the customer provide their personal details to the exchange.
  The wallet is identified by its long-lived reserve public key
  (which is used for P2P payments, not for withdrawals).

  **Request:**

  The request body must be a `WalletKycRequest` object.

  **Response:**

  :http:statuscode:`204 No Content`:
    KYC is disabled at this exchange, or the balance
    is below the threshold that requires KYC, or this
    wallet already satisfied the KYC check for the
    given balance.
  :http:statuscode:`403 Forbidden`:
    The provided signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`451 Unavailable for Legal Reasons`:
    The wallet must undergo a KYC check. A KYC ID was created.
    The response will be a `WalletKycUuid` object.

  **Details:**

  .. ts:def:: WalletKycRequest

     interface WalletKycRequest {

      // Balance threshold (not necessarily exact balance)
      // to be crossed by the wallet that (may) trigger
      // additional KYC requirements.
      balance: Amount;

      // EdDSA signature of the wallet affirming the
      // request, must be of purpose
      // ``TALER_SIGNATURE_WALLET_ACCOUNT_SETUP``
      reserve_sig: EddsaSignature;

      // long-term wallet reserve-account
      // public key used to create the signature.
      reserve_pub: EddsaPublicKey;
    }

  .. ts:def:: WalletKycUuid

     interface WalletKycUuid {

       // UUID that the wallet should use when initiating
       // the KYC check.
       requirement_row: number;

       // Hash of the payto:// account URI for the wallet.
       h_payto: PaytoHash;

     }


.. http:get:: /kyc-check/$REQUIREMENT_ROW/$H_PAYTO/$USERTYPE

  Checks the KYC status of a particular payment target and possibly begins the
  KYC process. This endpoint is used by wallets or merchants that have been
  told about a KYC requirement and now want to check if the KYC requirement
  has been fulfilled.  Long-polling may be used to instantly observe a change
  in the KYC requirement status.

  Returns the current KYC status of the requirement process and, if negative,
  returns the URL where the KYC process can be initiated.  The
  ``$REQUIREMENT_ROW`` must have been returned previously from an exchange API
  endpoint that determined that KYC was needed.  The ``$H_PATYO`` must be the
  hash of the "payto://" URI of the payment target.  The ``$USERTYPE`` states
  whether the entity to perform the KYC is an "individual" or a "business".

  **Request:**

  :query timeout_ms=NUMBER: *Optional.*  If specified, the exchange will
    wait up to ``timeout_ms`` milliseconds if the payment target
    is currently not legitimized.  Ignored if the payment target
    is already legitimized. Note that the legitimization would be
    triggered by another request to the same endpoint with a valid
    ``token``.

  **Response:**

  :http:statuscode:`200 Ok`:
    The KYC operation succeeded, the exchange confirms that the
    payment target already authorized to transact.
    The response will be an `AccountKycStatus` object.
  :http:statuscode:`202 Accepted`:
    The user should be redirected to the provided location to perform
    the required KYC checks to satisfy the legal requirements. Afterwards, the
    ``/kyc-check/`` request should be repeated to check whether the
    user has completed the process.
    The response will be an `AccountKycRedirect` object.
  :http:statuscode:`204 No content`:
    The exchange is not configured to perform KYC and thus
    the legal requirements are already satisfied.
  :http:statuscode:`402 Payment Required`:
    The client must pay the KYC fee for the KYC process.
    **This is currently not implemented, see #7365.**
  :http:statuscode:`403 Forbidden`:
    The provided hash does not match the payment target.
  :http:statuscode:`404 Not found`:
    The payment target is unknown.
  :http:statuscode:`451 Unavailable for Legal Reasons`:
    The transaction cannot be completed due to AML rules.
    Thus, the operation is currently not stuck on KYC, but
    on exchange staff performing their AML review. The user
    should be told to wait and/or contact the exchange operator
    if the situation persists.
    The response will be a `AccountAmlBlocked` object.

  **Details:**

  .. ts:def:: AccountKycStatus

    interface AccountKycStatus {

      // Details about the KYC check that the user
      // passed.
      kyc_details: KycDetails;

      // Current time of the exchange, used as part of
      // what the exchange signs over.
      now: Timestamp;

      // EdDSA signature of the exchange affirming the account
      // is KYC'ed, must be of purpose
      // ``TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS``
      // and over ``TALER_AccountSetupStatusSignaturePS``.
      exchange_sig: EddsaSignature;

      // public key used to create the signature.
      exchange_pub: EddsaPublicKey;

      // Current AML state for the target account. Non-zero
      // values indicate that the transfer is blocked due to
      // AML enforcement.
      aml_status: Integer;

    }

  .. ts:def:: AccountKycRedirect

    interface AccountKycRedirect {

      // URL that the user should open in a browser to
      // proceed with the KYC process.
      kyc_url: string;

      // Current AML state for the target account. Non-zero
      // values indicate that the transfer is blocked due to
      // AML enforcement.
      aml_status: Integer;

    }

  .. ts:def:: AccountAmlBlocked

    interface AccountAmlBlocked {

      // Current AML state for the target account. Non-zero
      // values indicate that the transfer is blocked due to
      // AML enforcement.
      aml_status: Integer;

    }

  .. ts:def:: KycDetails

    // Object that specifies which KYC checks are satisfied.
    interface KycDetails {

      // Keys are the names of the check(s).
      // The values are for now always empty objects.

    }

.. http:get:: /kyc-proof/$PROVIDER_SECTION?state=$H_PAYTO

  Endpoint accessed from the user's browser at the *end* of a
  KYC process, possibly providing the exchange with additional
  credentials to obtain the results of the KYC process.
  Specifically, the URL arguments should provide
  information to the exchange that allows it to verify that the
  user has completed the KYC process. The details depend on
  the logic, which is selected by the "$PROVIDER_SECTION".

  While this is a GET (and thus safe, and idempotent), the operation
  may actually trigger significant changes in the exchange's state.
  In particular, it may update the KYC status of a particular
  payment target.

  **Request:**

  Details on the request depend on the specific KYC logic
  that was used.

  If the KYC plugin logic is OAuth 2.0, the query parameters are:

  :query code=CODE:  OAuth 2.0 code argument.
  :query state=STATE:  OAuth 2.0 state argument with the H_PAYTO.

  .. note::

    Depending on the OAuth variant used, additional
    query parameters may need to be passed here.

  **Response:**

  Given that the response is returned to a user using a browser and **not** to
  a Taler wallet, the response format is in human-readable HTML and not in
  machine-readable JSON.

  :http:statuscode:`302 Found`:
    The KYC operation succeeded and the
    payment target is now authorized to transact.
    The browser is redirected to a human-readable
    page configured by the exchange operator.
  :http:statuscode:`401 Unauthorized`:
    The provided authorization token is invalid.
  :http:statuscode:`404 Not found`:
    The payment target is unknown.
  :http:statuscode:`502 Bad Gateway`:
    The exchange received an invalid reply from the
    legitimization service.
  :http:statuscode:`504 Gateway Timeout`:
    The exchange did not receive a reply from the legitimization
    service within a reasonable time period.


.. http:get:: /kyc-webhook/$PROVIDER_SECTION/*
.. http:post:: /kyc-webhook/$PROVIDER_SECTION/*
.. http:get:: /kyc-webhook/$LOGIC/*
.. http:post:: /kyc-webhook/$LOGIC/*

  All of the above endpoints can be used to update KYC status of a particular
  payment target. They provide information to the KYC logic of the exchange
  that allows it to verify that the user has completed the KYC process.  May
  be a GET or a POST request, depending on the specific "$LOGIC" and/or the
  "$PROVIDER_SECTION".

  **Request:**

  Details on the request depend on the specific KYC logic
  that was used.

  **Response:**

  :http:statuscode:`204 No content`:
    The operation succeeded.
  :http:statuscode:`404 Not found`:
    The specified logic is unknown.


---------------
Reserve control
---------------

This section describes the reserve control API which can be used to (1)
prevent a reserve from expiring, to (2) pay an annual fee to allow a number of
purses to be created for the respective reserve without paying a purse fee
each time, to (3) obtain KYC information associated with a reserve to prove
the identity of the person sending an invoice to the payer, and to (4) close a
reserve before it would naturally expire and possibly (5) wire the funds to a
designated account.

  .. note::

     This section is about a proposed API. It is not implemented. See also DD 31.

.. http:post:: /reserves/$RESERVE_PUB/open

  Request keeping a reserve open for invoicing.

  **Request:**

  The request body must be a `ReserveOpenRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `ReserveOpenResponse` object.
  :http:statuscode:`402 Payment Required`:
    The exchange responds with a `ReserveOpenFailure` object when
    the payment offered is insufficient for the requested operation.
  :http:statuscode:`403 Forbidden`:
    The *TALER_SIGNATURE_WALLET_RESERVE_OPEN* signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The reserve key does not belong to a reserve known to the exchange.
  :http:statuscode:`409 Conflict`:
    The balance of the reserve or of a coin was insufficient.
    Which case it is can be decided by looking at the error code
    (``TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS`` or
    ``TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY`` or
    ``TALER_EC_EXCHANGE_OPEN_INSUFFICIENT_FUNDS``).
    The specific fields of the response depend on the error code
    and include the signatures (and what was signed over) proving the
    conflict.
    The response is `WithdrawError` object or a `DepositDoubleSpendError`
    depending on the error type.
  :http:statuscode:`451 Unavailable For Legal Reasons`:
    This account has not yet passed the KYC checks.
    The client must pass KYC checks before the reserve can be opened.
    The response will be an `KycNeededRedirect` object.

  **Details:**

  .. ts:def:: ReserveOpenRequest

    interface ReserveOpenRequest {
      // Signature of purpose
      // ``TALER_SIGNATURE_WALLET_RESERVE_OPEN`` over
      // a `TALER_ReserveOpenPS`.
      reserve_sig: EddsaSignature;

      // Array of payments made towards the cost of the
      // operation.
      payments: OpenPaymentDetail[];

      // Amount to be paid from the reserve for this
      // operation.
      reserve_payment: Amount;

      // Time when the client made the request.
      // Timestamp must be reasonably close to the time of
      // the exchange, otherwise the exchange may reject
      // the request (with a status code of 400).
      request_timestamp: Timestamp;

      // Desired new expiration time for the reserve.
      // If the reserve would expire before this time,
      // the exchange will charge account fees (and
      // possibly KYC fees) until the expiration time
      // exceeds this timestamp. Note that the exchange
      // will refuse requests (with a status code of 400)
      // if the time is so far in the future that the
      // fees are not yet known (see /keys).
      reserve_expiration: Timestamp;

      // Desired open purse limit. Can be used to pay the
      // annual account fee more than once to get a larger
      // purse limit.
      purse_limit: Integer;

    }

  .. ts:def:: ReserveOpenResponse

    interface ReserveOpenResponse {
      // Transaction cost for extending the expiration time.
      // Excludes KYC fees.
      open_cost: Amount;

      // Current expiration time for the reserve.
      reserve_expiration: Timestamp;
    }

  .. ts:def:: ReserveOpenFailure

    interface ReserveOpenFailure {
      // Transaction cost that should have been paid
      // to extending the reserve as requested.
      // Excludes KYC fees.
      open_cost: Amount;

      // Remaining expiration time for the reserve.
      reserve_expiration: Timestamp;
    }

  .. ts:def:: OpenPaymentDetail

    interface OpenPaymentDetail {

      // Contribution of this coin to the overall amount.
      // Can be a fraciton of the coin's total value.
      amount: Amount;

      // Hash of denomination RSA key with which the coin is signed.
      denom_pub_hash: HashCode;

      // Exchange's unblinded RSA signature of the coin.
      ub_sig: DenominationSignature;

      // Age commitment for the coin, if the denomination is age-restricted.
      age_commitment?: AgeCommitment;

      // Signature over `TALER_ReserveOpenDepositSignaturePS`
      // of purpose ``TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT``
      // made by the customer with the
      // `coin's private key <coin-priv>`.
      coin_sig: EddsaSignature;

      // Public key of the coin being used to pay for
      // opening the reserve.
      coin_pub: EddsaPublicKey;

    }


.. http:get:: /reserves-attest/$RESERVE_PUB

  Request list of available KYC attributes about the owner of a reserve.
  Used as a preliminary step to find out which subsets of attributes the
  exchange could provide signatures over.

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `ReserveKycAttributes` object.
  :http:statuscode:`404 Not found`:
    The reserve key does not belong to a reserve known to the exchange.
  :http:statuscode:`409 Conflict`:
    The exchange does not have the requested KYC information.

  **Details:**

  .. ts:def:: ReserveKycAttributes

    interface ReserveKycAttributes {
      // Array of KYC attributes available.  The attribute names
      // listed are expected to be from the respective GANA
      // registry.
      details: string[];
    }


.. http:post:: /reserves-attest/$RESERVE_PUB

  Request signed KYC information about the owner of a reserve.
  This can be used by a reserve owner to include a proof
  of their identity in invoices.

  **Request:**

  The request body must be a `ReserveAttestRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `ReserveAttestResponse` object.
  :http:statuscode:`403 Forbidden`:
    The *TALER_SIGNATURE_WALLET_KYC_DETAILS* signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The reserve key does not belong to a reserve known to the exchange.
  :http:statuscode:`409 Conflict`:
    The exchange does not have the requested KYC information.

  **Details:**

  .. ts:def:: ReserveAttestRequest

    interface ReserveAttestRequest {
      // Signature of purpose
      // ``TALER_SIGNATURE_WALLET_ATTEST_DETAILS`` over
      // a `TALER_WalletReserveAttestRequestSignaturePS`.
      reserve_sig: EddsaSignature;

      // Client's time for the request.
      request_timestamp: Timestamp;

      // Array of KYC attributes requested.
      details: string[];
    }

  .. ts:def:: ReserveAttestResponse

    interface ReserveAttestResponse {
      // Signature of purpose
      // ``TALER_SIGNATURE_EXCHANGE_RESERVE_ATTEST_DETAILS`` over
      // a `TALER_ExchangeAttestPS`.
      exchange_sig: EddsaSignature;

      // Exchange public key used to create the
      // signature.
      exchange_pub: EddsaPublicKey;

      // Time when the exchange created the signature.
      exchange_timestamp: Timestamp;

      // Expiration time for the provided information.
      expiration_time: Timestamp;

      // KYC details (key-value pairs) as requested.
      // The keys will match the elements of the
      // ``details`` array from the request.
      attributes: Object;
    }


.. http:post:: /reserves/$RESERVE_PUB/close

  Force immediate closure of a reserve. Does not actually
  delete the reserve or the KYC data, but merely forces
  the reserve's current balance to be wired back to the
  account where it originated from, or another account of
  the user's choosing if they performed the required KYC
  check and designated another target account.

  **Request:**

  The request body must be a `ReserveCloseRequest` object.

  **Response:**

  :http:statuscode:`200 OK`:
    The exchange responds with a `ReserveCloseResponse` object.
  :http:statuscode:`403 Forbidden`:
    The *TALER_SIGNATURE_WALLET_RESERVE_CLOSE* signature is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The reserve key does not belong to a reserve known to the exchange.
  :http:statuscode:`409 Conflict`:
    No target account was given, and the exchange does not know an
    origin account for this reserve.
  :http:statuscode:`451 Unavailable For Legal Reasons`:
    This account has not yet passed the KYC checks, hence wiring
    funds to a non-origin account is not allowed.
    The client must pass KYC checks before the reserve can be opened.
    The response will be an `KycNeededRedirect` object.

  **Details:**

  .. ts:def:: ReserveCloseRequest

    interface ReserveCloseRequest {
      // Signature of purpose
      // ``TALER_SIGNATURE_WALLET_RESERVE_CLOSE`` over
      // a `TALER_ReserveCloseRequestSignaturePS`.
      reserve_sig: EddsaSignature;

      // Time when the client made the request.
      // Timestamp must be reasonably close to the time of
      // the exchange, otherwise the exchange may reject
      // the request (with a status code of 400).
      request_timestamp: Timestamp;

      // payto://-URI of the account the reserve balance is to be
      // wired to.  Must be of the form: 'payto://$METHOD' for a
      // wire method supported by this exchange (if the
      // method is not supported, this is a bad request (400)).
      // If not given, the reserve's origin account
      // will be used. If no origin account is known for the
      // reserve and not given, this is a conflict (409).
      payto_uri?: string;

    }

  .. ts:def:: ReserveCloseResponse

    interface ReserveCloseResponse {

      // Actual amount that will be wired (excludes closing fee).
      wire_amount: Amount;

    }


.. _delete-reserve:

.. http:DELETE:: /reserves/$RESERVE_PUB

  Forcefully closes a reserve.
  The request header must contain an *Account-Request-Signature*.
  Note: this endpoint is not currently implemented!

  **Request:**

  *Account-Request-Signature*: The client must provide Base-32 encoded EdDSA signature made with ``$ACCOUNT_PRIV``, affirming its authorization to delete the account.  The purpose used MUST be ``TALER_SIGNATURE_RESERVE_CLOSE``.

  :query force=BOOLEAN: *Optional.*  If set to 'true' specified, the exchange
    will delete the account even if there is a balance remaining.

  **Response:**

  :http:statuscode:`200 OK`:
    The operation succeeded, the exchange provides details
    about the account deletion.
    The response will include a `ReserveDeletedResponse` object.
  :http:statuscode:`403 Forbidden`:
    The *Account-Request-Signature* is invalid.
    This response comes with a standard `ErrorDetail` response.
  :http:statuscode:`404 Not found`:
    The account is unknown to the exchange.
  :http:statuscode:`409 Conflict`:
    The account is still has digital cash in it, the associated
    wire method is ``void`` and the *force* option was not provided.
    This response comes with a standard `ErrorDetail` response.

  **Details:**

  .. ts:def:: ReserveDeletedResponse

     interface ReserveDeletedResponse {

      // Final balance of the account.
      closing_amount: Amount;

      // Current time of the exchange, used as part of
      // what the exchange signs over.
      close_time: Timestamp;

      // Hash of the wire account into which the remaining
      // balance will be transferred. Note: may be the
      // hash over ``payto://void/`, in which case the
      // balance is forfeit to the profit of the exchange.
      h_wire: HashCode;

      // This is a signature over a
      // struct ``TALER_AccountDeleteConfirmationPS`` with purpose
      // ``TALER_SIGNATURE_EXCHANGE_RESERVE_DELETED``.
      exchange_sig: EddsaSignature;

    }