summaryrefslogtreecommitdiff
path: root/api-mint.rst
blob: e693622cb93fc809cc3d350dcb97b2f27ec35bc1 (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
=========================
The Mint RESTful JSON API
=========================

The API specified here follows the :ref:`general conventions <http-common>`
for all details not specified in the individual requests.

-------------------
Obtaining Mint Keys
-------------------

This API is used by wallets and merchants to obtain global information about
the mint, such as online signing keys, available denominations and the fee
structure.  This is typically the first call any mint client makes, as it
returns information required to process all of the other interactions with the
mint.  The returned information is secured by (1) signature(s) from the mint,
especially the long-term offline signing key of the mint, 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:: /keys

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

  **Response:**

  :status 200 OK:
    The mint responds with a `MintKeysResponse`_ object. This request should
    virtually always be successful.

  **Details:**
  
  .. _MintKeysResponse:
  .. code-block:: tsref

    interface MintKeysResponse {
      // EdDSA master public key of the mint, used to sign entries in `denoms` and `signkeys`
      master_public_key: EddsaPublicKey;

      // Denomination offered by this mint.
      denoms: Denom[];

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

      // Auditors of the mint.
      auditors: Auditor[];

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

      // compact EdDSA signature_ (binary-only) over the SHA-512 hash of the
      // concatenation of all SHA-512 hashes of the RSA denomination public keys
      // in `denoms` in the same order as they were in `denoms`.  Note that for
      // hashing, the binary format of the RSA public keys is used, and not their
      // base32_ encoding.  Wallets cannot do much with this signature by itself;
      // it is only useful when multiple clients need to establish that the mint
      // is sabotaging end-user anonymity by giving disjoint denomination keys to
      // different users.  If a mint were to do this, this signature allows the
      // clients to demonstrate to the public that the mint is dishonest.
      eddsa_sig: string;

      // Public EdDSA key of the mint that was used to generate the signature.
      // Should match one of the mint'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.
      eddsa_pub: string;
    }

  .. _tsref-type-Denom:
  .. code-block:: tsref

    interface Denom {
      // 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 fresh coins
      // of this denomination?
      stamp_expire_withdraw: Timestamp;

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

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

      // Public (RSA) key for the denomination in base32 encoding.
      denom_pub: string;

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

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

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

      // Signature with purpose
      // `TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY` over the expiration
      // dates, value and the key, created with the mint's master key.
      master_sig: EddsaSignature;
    }

  Fees for any of the operations can be zero, but the fields must still be
  present. The currency of the `fee_deposit` and `fee_refresh` 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.

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

  .. _tsref-type-SignKey:
  .. code-block:: tsref

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

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

      // Date when the mint 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 mint master key.
      // 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:

  .. _tsref-type-Auditor:
  .. code-block:: tsref

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

      // 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: DenominationKey[];
    }

  .. _tsref-type-DenominationKey:
  .. code-block:: tsref

    interface DenominationKey {
      // 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;

      // A signature_ (binary-only) with purpose
      // `TALER_SIGNATURE_AUDITOR_MINT_KEYS` over the mint's public key and the
      // denomination key information. To verify the signature, the `denom_pub_h`
      // must be resolved with the information from `denoms`
      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.

-----------------------------------
Obtaining wire-transfer information
-----------------------------------

.. http:get:: /wire

  Returns a list of payment methods supported by the mint.  The idea is that wallets may use this information to instruct users on how to perform wire transfers to top up their wallets.

  **Response:**

  :status 200: The mint responds with a `WireResponse`_ object. This request should virtually always be successful.

  **Details:**

  .. _WireResponse:
  .. _tsref-type-WireResponse:
  .. code-block:: tsref

    interface WireResponse {
      // Names of supported methods (i.e. "sepa" or "test").
      // Payment method METHOD is available under /wire/METHOD.
      methods: string[];

      // the EdDSA signature_ (binary-only) with purpose
      // `TALER_SIGNATURE_MINT_PAYMENT_METHODS` signing over the hash over the
      // 0-terminated strings representing the payment methods in the same order
      // as given in methods.
      sig: EddsaSignature;

      // public EdDSA key of the mint that was used to generate the signature.
      // Should match one of the mint'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.
      pub: EddsaPublicKey;
    }


.. http:get:: /wire/test

  The "test" payment method is for testing the system without using
  real-world currencies or actual wire transfers.  If the mint operates
  in "test" mode, this request provides a redirect to an address where
  the user can initiate a fake wire transfer for testing.

  :status 302: Redirect to the webpage where fake wire transfers can be made.
  :status 501: This wire transfer method is not supported by this mint.

.. http:get:: /wire/sepa

  Provides instructions for how to transfer funds to the mint using the SEPA
  transfers.  Always signed using the mint's long-term offline master public
  key.

  :status 200: The mint responds with a `WireSepaResponse`_ object. This request should virtually always be successful.
  :status 501: This wire transfer method is not supported by this mint.
    

  **Details:**

  .. _WireSepaResponse:
  .. _tsref-type-WireSepaResponse:
  .. code-block:: tsref

    interface WireSepaResponse {
      // Legal name of the mint operator who is receiving the funds
      receiver_name: string;

      // IBAN account number for the mint
      iban: string;

      // BIC of the bank of the mint
      bic: string;

      // the EdDSA signature_ (binary-only) with purpose
      // `TALER_SIGNATURE_MINT_PAYMENT_METHOD_SEPA` signing over the hash over the
      // 0-terminated strings representing the receiver's name, IBAN and the BIC.
      sig: EddsaSignature;
    }


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

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

When transfering money to the mint such as via SEPA transfers, the mint 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
mint.

  .. note::

     Eventually the mint 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:: /reserve/status

  Request information about a reserve.

  .. note::
    The client currently does not have to demonstrate knowledge of the private
    key of the reserve to make this request, which makes the reserve's public
    key privliged information known only to the client, their bank, and the
    mint.  In future, we might wish to revisit this decision to improve
    security, such as by having the client EdDSA-sign an ECDHE key to be used
    to derive a symmetric key to encrypt the response.  This would be useful if
    for example HTTPS were not used for communication with the mint.

  **Request:**

  :query reserve_pub: EdDSA reserve public key identifying the reserve.

  **Response:**

  :status 200 OK:
    The mint responds with a `ReserveStatus`_ object;  the reserve was known to the mint,
  :status 404 Not Found: The withdrawal key does not belong to a reserve known to the mint.

  **Details:**

  .. _ReserveStatus:
  .. code-block:: tsref

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

      // Transaction history for this reserve
      history: TransactionHistoryItem[];
    }

  Objects in the transaction history have the following format:

  .. _tsref-type-TransactionHistoryItem:
  .. code-block:: tsref

    interface TransactionHistoryItem {
      // Either "WITHDRAW" or "DEPOSIT"
      type: string;

      // The amount that was withdrawn or deposited.
      amount: Amount;

      // Wiring details, only present if type is "DEPOSIT".
      wire?: any;

      // binary encoding of the transaction data as a `TALER_WithdrawRequestPS`
      // struct described in :ref:`Signatures`, only present if the `type` was
      // "WITHDRAW".  Its `purpose` should match our `type`, `amount_with_fee`,
      // should match our `amount`, and its `size` should be consistent.
      string?: details;

      // Signature over the transaction details.
      // Purpose: TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW
      signature?: EddsaSignature;
    }


.. http:post:: /reserve/withdraw

  Withdraw a coin of the specified denomination.  Note that the client should
  commit all of the request details, including the private key of the coin and
  the blinding factor, 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 `WithdrawRequest`_ object.

  **Response:**

  :status 200 OK:
    The request was succesful, and the response is a `WithdrawResponse`.  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.
  :status 401 Unauthorized: The signature is invalid.
  :status 404 Not Found:
    The denomination key or the reserve are not known to the mint.  If the
    denomination key is unknown, this suggests a bug in the wallet as the
    wallet should have used current denomination keys from /keys.  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 mint in the near future.
    In this case, the wallet should repeat the exact same request later again
    using exactly the same blinded coin.
  :status 402 Payment Required:
    The balance of the reserve is not sufficient to withdraw a coin of the indicated denomination.
    The response is `WithdrawError`_ object.


  **Details:**

  .. _WithdrawRequest:
  .. code-block:: tsref

    interface WithdrawRequest {
      // Denomination public key (RSA), specifying the type of coin the client
      // would like the mint to create.
      denom_pub: RsaPublicKey;

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

      // public (EdDSA) key of the reserve from which the coin should be
      // withdrawn.  The total amount deducted will be the coin's value plus the
      // withdrawal fee as specified with the denomination information.
      reserve_pub: EddsaPublicKey;

      // Signature (binary-only) of purpose
      // `TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW` created with the reserves's
      // private key
      reserve_sig: EddsaSignature;
    } 


  .. _WithdrawResponse:
  .. code-block:: tsref

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

  .. _WithdrawError:
  .. code-block:: tsref

    interface WithdrawError {
      // Constant "Insufficient funds"
      error: string;

      // Amount left in the reserve
      balance: Amount;

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


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

Deposit operations are requested by a merchant during a transaction. For the
deposit operation, 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.


.. _deposit:
.. http:POST:: /deposit

  Deposit the given coin and ask the mint to transfer the given :ref:`amount`
  to the merchants bank account.  This API is used by the merchant to redeem
  the digital coins.  The request should contain a JSON object with the
  following fields:

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

  **Response:**

  :status 200:
    The operation succeeded, the mint confirms that no double-spending took place.
  :status 401 Unauthorized:
    One of the signatures is invalid.
  :status 403:
    The deposit operation has failed because the coin has insufficient
    residual value; the request should not be repeated again with this coin.
    In this case, the response is a `DepositDoubleSpendError`_.
  :status 404:
    Either the denomination key is not recognized (expired or invalid) or
    the wire type is not recognized.

  **Details:**

  .. _DepositRequest:
  .. code-block:: tsref

    interface DepositRequest {
      // Amount to be deposited, can be a fraction of the
      // coin's total value.
      f: Amount;

      // The merchant's account details. This must be a JSON object whose format
      // must correspond to one of the supported wire transfer formats of the mint.
      // See `wireformats`_.
      wire: WireFormat;

      // SHA-512 hash of the merchant's payment details from `wire`.  Although
      // strictly speaking redundant, this helps detect inconsistencies.
      H_wire: HashCode;

      // SHA-512 hash of the contact of the merchant with the customer.  Further
      // details are never disclosed to the mint.
      H_contract: HashCode;

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

      // denomination RSA key with which the coin is signed
      denom_pub: RsaPublicKey;

      // mint's unblinded RSA `signature`_ of the coin
      ub_sig: RsaSignature;

      // timestamp when the contract was finalized, must match approximately the
      // current time of the mint
      timestamp: Timestamp;

      // indicative time by which the mint undertakes to transfer the funds to
      // the merchant, in case of successful payment.
      edate: Timestamp;

      // 64-bit transaction id for the transaction between merchant and customer
      transaction_id: number;

      // EdDSA public key of the merchant, 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
      // mint, possibly zero if refunds are not allowed.
      refund_deadline: Timestamp;

      // The EdDSA signature (binary-only) made with purpose
      // `TALER_SIGNATURE_WALLET_COIN_DEPOSIT` made by the customer with the coin's
      // private key.
      coin_sig: EddsaSignature;
    }

  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.


  .. code-block:: tsref

    interface DepositSuccess {
      // The string constant "DEPOSIT_OK"
      status: string;

      // the EdDSA :ref:`signature` (binary-only) with purpose
      // `TALER_SIGNATURE_MINT_CONFIRM_DEPOSIT` using a current signing key of the
      // mint affirming the successful deposit and that the mint will transfer the
      // funds after the refund deadline, or as soon as possible if the refund
      // deadline is zero.
      sig: EddsaSignature;

      // public EdDSA key of the mint that was used to generate the signature.
      // Should match one of the mint'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.
      pub: EddsaPublicKey;
    }

  .. _DepositDoubleSpendError:
  .. code-block:: tsref
    
    interface DepositDoubleSpendError {
      // The string constant "insufficient funds"
      string error;

      // Transaction history for the coin that is
      // being double-spended
      history: CoinSpendHistoryItem[];
    }

  .. code-block:: tsref

    interface CoinSpendHistoryItem {
      // Either "deposit" or "melt"
      type: string;

      // The total amount of the coin's value absorbed by this transaction
      amount: Amount;

      // base32 binary encoding of the transaction data as a
      // `TALER_DepositRequestPS` or `TALER_RefreshMeltCoinAffirmationPS`
      // struct described in :ref:`Signatures`.  Its `purpose` should match our
      // `type`, `amount_with_fee`, should match our `amount`, and its `size`
      // should be consistent.
      details: string;

      // the EdDSA :ref:`signature` (binary-only) made with purpose
      // `TALER_SIGNATURE_WALLET_COIN_DEPOSIT` or
      // `TALER_SIGNATURE_WALLET_COIN_MELT` over the transaction's details.
      signature: EddsaSignature;
    }

------------------
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 mint.
The refreshing API can be used by wallets to melt partially spent coins, making
transactions with the freshly minted 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 mint to achieve taxability, wallets do not really ever need that part of
the API during normal operation.

.. _refresh:
.. http:post:: /refresh/melt

  "Melts" coins.  Invalidates the coins and prepares for minting 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.


  :status 401 Unauthorized:
    One of the signatures is invalid.
  :status 200 OK:
    The request was succesful.  The response body is `MeltResponse`_ in this case.
  :status 403 Forbidden:
    The operation is not allowed as at least one of the coins has insufficient funds.  The response
    is `MeltForbiddenResponse`_ in this case.
  :status 404:
    the mint does not recognize the denomination key as belonging to the mint,
    or it has expired

  **Details:**


  .. code-block:: tsref

    interface MeltRequest {
      // Array of `n` new denominations to order.
      new_denoms: RsaPublicKey[];

      // List of `m` coins to melt.
      melt_coins: MeltCoin[];

      // For each of the `n` new coins, `kappa` transfer keys.
      // coin_evs[j][k] is the k-th blank (of kappa) for the k-th new coin (of n).
      coin_evs: CoinBlank[][]

      // For each of the `m` old coins, `kappa` transfer public keys (2D-array
      // of ephemeral ECDHE keys)
      transfer_pubs: EddsaPublicKey[][];

      // For each of the `m` old coins, `kappa` link encryptions with an
      // ECDHE-encrypted SHA-512 hash code.  The ECDHE encryption is done using
      // the private key of the respective old coin and the corresponding transfer
      // public key.  Note that the SHA-512 hash code must be the same across all
      // coins, but different across all of the `kappa` dimensions.  Given the
      // private key of a single old coin, it is thus possible to decrypt the
      // respective `secret_encs` and obtain the SHA-512 hash that was used to
      // symetrically encrypt the `link_encs` of all of the new coins.
      secret_encs: string[][];

      // For each of the `n` new coins, `kappa` symmetrically encrypted tuples
      // consisting of the EdDSA/ECDHE-private key of the new coin and the
      // corresponding blinding factor, encrypted using the corresponding SHA-512
      // hash that is encrypted in `secret_encs`.
      link_encs: string[][];
    }

  For details about the HKDF used to derive the symmetric encryption keys from
  ECDHE and the symmetric encryption (AES+Twofish) used, please refer to the
  implementation in `libtalerutil`. The `melt_coins` field is a list of JSON
  objects with the following fields:


  .. _tsref-type-MeltCoin:
  .. code-block:: tsref

    interface MeltCoin {
      // Coin public key, uniquely identifies the coin
      coin_pub: string;

      // The denomination public key allows the mint to determine total coin value.
      denom_pub: RsaPublicKey;

      // Signature over the coin public key by the denomination.
      denom_sig: RsaSignature;

      // Signature by the coin over the session public key
      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;

  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.


  .. _tsref-type-MeltResponse:
  .. _MeltResponse:
  .. code-block:: tsref

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

      // binary-only Signature_ for purpose `TALER_SIGNATURE_MINT_CONFIRM_MELT`
      // whereby the mint affirms the successful melt and confirming the
      // `noreveal_index`
      mint_sig: EddsaSignature;

      // public EdDSA key of the mint that was used to generate the signature.
      // Should match one of the mint'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.
      mint_pub: EddsaPublicKey;
    }


  .. _tsref-type-MeltForbiddenResponse:
  .. _MeltForbiddenResponse:
  .. code-block:: tsref

    interface MeltForbiddenResponse {
      // Always "insufficient funds"
      error: string;

      // public key of a melted coin that had insufficient funds
      coin_pub: EddsaPublicKey;

      // original total value of the coin
      original_value: Amount;

      // remaining value of the coin
      residual_value: Amount;

      // amount of the coin's value that was to be melted
      requested_value: Amount;

      // 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:: /refresh/reveal

  Reveal previously commited values to the mint, except for the values
  corresponding to the `noreveal_index` returned by the /mint/melt step.
  Request body contains a JSON object with the following fields:


  :status 200 OK:
    The transfer private keys matched the commitment and the original request was well-formed.
    The response body is a `RevealResponse`_
  :status 409 Conflict:
    There is a problem between the original commitment and the revealed private
    keys.  The returned information is proof of the missmatch, 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`_.



  .. code-block:: tsref

    interface RevealRequest {
      // Hash over most of the arguments to the /mint/melt step.  Used to
      // identify the corresponding melt operation.  For details on which elements
      // must be hashed in which order, please consult the source code of the mint
      // reference implementation.
      session_hash: HashCode;

      // 2D array of `kappa - 1` times number of melted coins ECDHE transfer
      // private keys.  The mint will use those to decrypt the transfer secrets,
      // check that they match across all coins, and then decrypt the private keys
      // of the coins to be generated and check all this against the commitments.
      transfer_privs: EddsaPrivateKey[][];
    }


  .. _RevealResponse:
  .. code-block:: tsref

    interface RevealResponse {
      // List of the mint's blinded RSA signatures on the new coins.  Each
      // element in the array is another JSON object which contains the signature
      // in the "ev_sig" field.
      ev_sigs: BlindedRsaSignature[];
    }


  .. _RevealConflictResponse:
  .. code-block:: tsref

    interface RevealConflictResponse {
      // Constant "commitment violation"
      error: string;

      // offset of in the array of `kappa` commitments where the error was detected
      offset: number;

      // index of in the with respect to the melted coin where the error was detected
      index: number;

      // name of the entity that failed the check (i.e. "transfer key")
      object: string;

      // Information about each melted coin
      oldcoin_infos: OldCoinInfo[];

      // array with RSA denomination public keys of the coins the original
      // refresh request asked to be minted
      newcoins_infos: RsaPublicKey[];

      // 2D array with `kappa` entries in the first dimension and the same
      // length as the `oldcoin_infos` in the 2nd dimension containing as elements
      // objects with the linkage information
      link_infos: LinkInfo[][];

      // 2D array with `kappa` entries in the first dimension and the same
      // length as `newcoin_infos` in the 2nd dimension containing as elements
      // objects with the commitment information
      commit_infos: CommitInfo[][];
    }


  .. _tsref-type-LinkInfo:
  .. code-block:: tsref

    interface LinkInfo {
      // the transfer ECDHE public key
      transfer_pub: EddsaPublicKey;

      // the encrypted shared secret
      shared_secret_enc: string;
    }

  .. _tsref-type-CommitInfo:
  .. code-block:: tsref

    interface CommitInfo {
      coin_ev: BlindedRsaSignature;

      // the encrypted private key of the coin
      coin_priv_env: string;

      // the encrypted blinding key
      blinding_key_enc: string;
    }


.. http:get:: /refresh/link

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

  **Request:**

  :query coin_pub: melted coin's public key

  **Response:**

  :status 200 OK:
    All commitments were revealed successfully.  The mint returns an array,
    typically consisting of only one element, in which each each element contains
    information about a melting session that the coin was used in.
  :status 404 Not Found:
    The mint has no linkage data for the given public key, as the coin has not
    yet been involved in a refresh operation.

  **Details:**

  .. _tsref-type-LinkResponse:
  .. code-block:: tsref

    interface LinkResponse {
      // transfer ECDHE public key corresponding to the `coin_pub`, used to
      // decrypt the `secret_enc` in combination with the private key of
      // `coin_pub`.
      transfer_pub: EcdhePublicKey;

      // ECDHE-encrypted link secret that, once decrypted, can be used to
      // decrypt/unblind the `new_coins`.
      secret_enc: Base32;

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

  .. _tsref-type-NewCoinInfo:
  .. code-block:: tsref
    
    interface NewCoinInfo {
      // Encrypted private key and blinding factor information of the fresh coin
      link_enc: Base32;

      // RSA public key of the minted coin.
      denom_pub: RsaPublicKey;

      // Mint's blinded signature over the minted coin.
      ev_sig: BlindedRsaSignature;
    }




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

This API is used by merchants that need to find out which wire
transfers (from the mint 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, least 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.)

  .. note::

     Wire transfer tracking is currently not implemented (#3888).


.. http:get:: /wire/deposits

  Provides deposits associated with a given wire transfer.

  **Request:**

  :query wtid: wire transfer identifier identifying the wire transfer (a base32-encoded value)

  **Response:**

  :status 200 OK:
    The wire transfer is known to the mint, details about it follow in the body.
    The body of the response is a `WireDepositsResponse`_.
  :status 404 Not Found: 
    The wire transfer identifier is unknown to the mint.

  .. _WireDepositsResponse:
  .. code-block:: tsref

    interface WireDepositsResponse {
      // Total amount transferred
      total: Amount;

      // hash of the wire details (identical for all deposits)
      H_wire: HashCode;

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

      deposits: DepositDetail[];
    }


  .. _tsref-type-DepositDetail:
  .. code-block:: tsref

    interface DepositDetail {
      // The total amount the original deposit was worth.
      deposit_value: Amount;

      // applicable fees for the deposit
      deposit_fee: Amount;

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

      // 64-bit transaction id for the transaction between merchant and
      // customer
      transaction_id: number;

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


.. http:post:: /deposit/wtid

  Provide the wire transfer identifier associated with an (existing) deposit operation.

  **Request:** The request body most be a `WtidRequest`_ JSON object.

  **Response:** 

  :status 200 OK:
    The deposit has been executed by the mint and we have a wire transfer identifier.
    The response body is a `WtidResponse`_ object.
  :status 202 Accepted:
    The deposit request has been accepted for processing, but was not yet
    executed.  Hence the mint does not yet have a wire transfer identifier.  The
    merchant should come back later and ask again.
    The response body is a `WtidAcceptedResponse`_.
  :status 401 Unauthorized: The signature is invalid.
  :status 404 Not Found: The deposit operation is unknown to the mint

  **Details:**

  .. _tsref-type-WtidRequest:
  .. _WtidRequest:
  .. code-block:: tsref

    interface WtidRequest {
      // SHA-512 hash of the merchant's payment details.
      H_wire: HashCode;

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

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

      // 64-bit transaction id for the transaction between merchant and customer
      transaction_id: number;

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

      // the EdDSA signature of the merchant made with purpose
      // `TALER_SIGNATURE_MERCHANT_DEPOSIT_WTID` , affirming that it is really the
      // merchant who requires obtaining the wire transfer identifier.
      merchant_sig: EddsaSignature;
    }


  .. _tsref-type-WtidResponse:
  .. _WtidResponse:
  .. code-block:: tsref

    interface WtidResponse {
      // wire transfer identifier of the deposit.
      wtid: Base32;

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

      // binary-only Signature_ for purpose `TALER_SIGNATURE_MINT_CONFIRM_WIRE`
      // whereby the mint affirms the successful wire transfer.
      mint_sig: EddsaSignature;

      // public EdDSA key of the mint that was used to generate the signature.
      // Should match one of the mint'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.
      mint_pub: EddsaPublicKey;
    }

  .. _tsref-type-WtidAcceptedResponse:
  .. _WtidAcceptedResponse:
  .. code-block:: tsref

    interface WtidAcceptedResponse {
      // time by which the mint currently thinks the deposit will be executed.
      execution_time: Timestamp;    
    }



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

  .. note::

     Refunds are currently not implemented (#3641), this documentation is thus
     rather preliminary and subject to change.

.. _refund:
.. http:POST:: /refund

  Undo deposit of the given coin, restoring its value.

  **Request:**

  .. code-block:: tsref

    interface RefundRequest {
      // If the coin was claimed as a refund, this field should contain the
      // retract permission obtained from the merchant, otherwise it should not be
      // present.
      // TODO: document what the type
      retract_perm: any;

      // Value returned due to the retraction.
      retract_value: string;
    }


------------------------------
Administrative API: Key update
------------------------------

  .. note::

     This is not yet implemented (no bug number yet, as we are not sure we will
     implement this; for now, adding new files to the directory and sending a
     signal to the mint process seems to work fine).

New denomination and signing keys can be uploaded to the mint via the
HTTP interface.  It is, of course, only possible to upload keys signed
by the mint's master key.  Furthermore, this API should probably only
be used via loopback, as we want to protect the private keys from
interception.

.. http:POST:: /admin/add/denomination_key

  Upload a new denomination key.

  **Request:**

  .. code-block:: tsref

    {
      // Public part of the denomination key
      denom_info: any:

      // Private RSA key
      denom_priv: RsaPrivateKey;
    }


.. http:POST:: /admin/add/sign_key

  Upload a new signing key.

  **Request:**

  .. code-block:: tsref

    {
      // Public part of the signing key
      sign_info: any;

      // Private EdDSA key
      sign_priv: EddsaPrivateKey;
    }

.. _add-incoming:

-------------------------------------
Administrative API: Bank transactions
-------------------------------------

.. http:POST:: /admin/add/incoming

  Notify mint of an incoming transaction to fill a reserve.

  **Request:**

  .. code-block:: tsref

    {
      // Reserve public key
      reserve_pub: EddsaPublicKey;

      // Amount transferred to the reserve
      amount: Amount;

      // When was the transaction executed
      execution_date: Timestamp;
      
      // Wire details
      wire: any;
    }

  **Response:**

  :status 200:
    The operation succeeded. The body is an `AddIncomingResponse`_ object.
  :status 403:
    the client is not permitted to add incoming transactions. The request may
    be disallowed by the configuration in general or restricted to certain IP
    addresses (i.e. loopback-only).


  .. _AddIncomingResponse:
  .. code-block:: tsref

    interface AddIncomingResponse {
      // The string constant `NEW` or `DUP` to indicate whether the transaction
      // was truly added to the DB or whether it already existed in the DB
      status: string;
    }

.. http:POST:: /admin/add/outgoing

  Notify mint about the completion of an outgoing transaction satisfying a
  /deposit request.  In the future, this will allow merchants to obtain details
  about the /deposit requests they send to the mint.

  .. note::

     This is not yet implemented (no bug number yet either).

  **Request:**

  .. code-block:: tsref

    {
      coin_pub: CoinPublicKey;

      // Amount transferred to the merchant
      amount: Amount;

      // Transaction identifier in the wire details
      transaction: number;

      // Wire transaction details, as originally specified by the merchant
      wire: any;
    }

  **Response**

  :status 200: The request was successful.
  :status 403: the client is not permitted to add outgoing transactions

  If the request was successful, the response has the following format:

  .. code-block:: tsref

    {
      // The string constant `NEW` or `DUP` to indicate whether the transaction
      // was truly added to the DB or whether it already existed in the DB
      status: string;
    }

------------
The Test API
------------

The test API is not there to test the mint, but to allow
clients of the mint (merchant and wallet implementations)
to test if their implemenation of the cryptography is
binary-compatible with the implementation of the mint.

.. http:POST:: /test/base32

  Test hashing and Crockford :ref:`base32` encoding.

  **Request:**

  .. code-block:: tsref

    {
      // some base32-encoded value
      input: Base32;
    }

  **Response:**

  .. code-block:: tsref

    {
      // the base32_-encoded hash of the input value
      output: Base32;
    }

.. http:POST:: /test/encrypt

  Test symmetric encryption.

  **Request:**

  .. code-block:: tsref

    {
      // Some `base32`_-encoded value
      input: Base32;

      // some `base32`_-encoded hash that is used to derive the symmetric key and
      // initialization vector for the encryption using the HKDF with "skey" and
      // "iv" as the salt.
      key_hash: Base32;
    }

  **Response:**


  .. code-block:: tsref

    {
      // the encrypted value
      output: Base32;
    }

.. http:POST:: /test/hkdf

  Test Hash Key Deriviation Function.

  **Request:**


  .. code-block:: tsref

    {
      // Some `base32`_-encoded value
      input: Base32;
    }

  **Response:**


  .. code-block:: tsref

    {
      // the HKDF of the input using "salty" as salt
      output: Base32;
    }

.. http:POST:: /test/ecdhe

  Test ECDHE.

  **Request:**

  .. code-block:: tsref

    {
      ecdhe_pub: EcdhePublicKey;
      ecdhe_priv: EcdhePrivateKey;
    }

  **Response:**

  .. code-block:: tsref

    {
      // ECDH result from the two keys
      ecdhe_hash: HashCode;
    }


.. http:POST:: /test/eddsa

  Test EdDSA.

  **Request:**

  .. code-block:: tsref

    {
      eddsa_pub: EddsaPublicKey;

      // EdDSA signature using purpose TALER_SIGNATURE_CLIENT_TEST_EDDSA. Note:
      // the signed payload must be empty, we sign just the purpose here.
      eddsa_sig: EddsaSignature;
    }

  **Response:**

  :status 200: the signature was valid
  :status 401 Unauthorized: the signature was invalid

  The mint responds with another valid signature, which gives the
  client the opportunity to test its signature verification implementation.

  .. code-block:: tsref

    {
      // Another EdDSA public key
      eddsa_pub: EddsaPublicKey;

      // EdDSA signature using purpose TALER_SIGNATURE_MINT_TEST_EDDSA
      eddsa_sig: EddsaSignature;
    }


.. http:GET:: /test/rsa/get

  Obtain the RSA public key used for signing in /test/rsa/sign.

  **Response:**

  .. code-block:: tsref

    {
      // The RSA public key the client should use when blinding a value for the /test/rsa/sign API.
      rsa_pub: RsaPublicKey;
    }

.. http:POST:: /test/rsa/sign

  Test RSA blind signatures.

  **Request:**

  .. code-block:: tsref

    {
      // Blinded value to sign.
      blind_ev: BlindedRsaSignature;
    }

  **Response:**


  .. code-block:: tsref

    {
      // Blind RSA signature over the `blind_ev` using the private key
      // corresponding to the RSA public key returned by /test/rsa/get.
      rsa_blind_sig: BlindedRsaSignature;
    }

.. http:POST:: /test/transfer

  Test Transfer decryption.

  **Request:**

  .. code-block:: tsref

    {
      // Encrypted transfer secret
      secret_enc: string;

      // Private transfer key
      trans_priv: string;

      // Coin public ket
      coin_pub: string;
    }

  **Response:**

  :status 200: the operation succeeded

  .. code-block:: tsref

    {
      // Decrypted transfer secret
      secret: string;
    }