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
|
import { codecForAmountString } from "../amounts.js";
import { Codec, buildCodecForObject, buildCodecForUnion, codecForBoolean, codecForConstString, codecForEither, codecForList, codecForMap, codecForNumber, codecForString, codecOptional } from "../codec.js";
import { codecForTimestamp } from "../time.js";
///
/// HASH
///
// 64-byte hash code.
type HashCode = string;
// 32-byte hash code.
type ShortHashCode = string;
// 16-byte salt.
type WireSalt = string;
type SHA256HashCode = ShortHashCode;
type SHA512HashCode = HashCode;
// 32-byte nonce value, must only be used once.
type CSNonce = string;
// 32-byte nonce value, must only be used once.
type RefreshMasterSeed = string;
// 32-byte value representing a point on Curve25519.
type Cs25519Point = string;
// 32-byte value representing a scalar multiplier
// for scalar operations on points on Curve25519.
type Cs25519Scalar = string;
///
/// KEYS
///
// 16-byte access token used to authorize access.
type ClaimToken = string;
// EdDSA and ECDHE public keys always point on Curve25519
// and represented using the standard 256 bits Ed25519 compact format,
// converted to Crockford Base32.
type EddsaPublicKey = string;
// EdDSA and ECDHE public keys always point on Curve25519
// and represented using the standard 256 bits Ed25519 compact format,
// converted to Crockford Base32.
type EddsaPrivateKey = string;
// Edx25519 public keys are points on Curve25519 and represented using the
// standard 256 bits Ed25519 compact format converted to Crockford
// Base32.
type Edx25519PublicKey = string;
// Edx25519 private keys are always points on Curve25519
// and represented using the standard 256 bits Ed25519 compact format,
// converted to Crockford Base32.
type Edx25519PrivateKey = string;
// EdDSA and ECDHE public keys always point on Curve25519
// and represented using the standard 256 bits Ed25519 compact format,
// converted to Crockford Base32.
type EcdhePublicKey = string;
// Point on Curve25519 represented using the standard 256 bits Ed25519 compact format,
// converted to Crockford Base32.
type CsRPublic = string;
// EdDSA and ECDHE public keys always point on Curve25519
// and represented using the standard 256 bits Ed25519 compact format,
// converted to Crockford Base32.
type EcdhePrivateKey = string;
type CoinPublicKey = EddsaPublicKey;
// RSA public key converted to Crockford Base32.
type RsaPublicKey = string;
type Integer = number;
type WireTransferIdentifierRawP = string;
// Subset of numbers: Integers in the
// inclusive range 0 .. (2^53 - 1).
type SafeUint64 = number;
// The string must be a data URL according to RFC 2397
// with explicit mediatype and base64 parameters.
//
// data:<mediatype>;base64,<data>
//
// Supported mediatypes are image/jpeg and image/png.
// Invalid strings will be rejected by the wallet.
type ImageDataUrl = string;
// <Currency>:<DecimalAmount>.
type Amount = string;
type WadId = string;
interface Timestamp {
// Seconds since epoch, or the special
// value "never" to represent an event that will
// never happen.
t_s: number | "never";
}
interface RelativeTime {
// Duration in microseconds or "forever"
// to represent an infinite duration. Numeric
// values are capped at 2^53 - 1 inclusive.
d_us: number | "forever";
}
export interface LoginToken {
token: AccessToken,
expiration: Timestamp,
}
// token used to get loginToken
// must forget after used
declare const __ac_token: unique symbol;
export type AccessToken = string & {
[__ac_token]: true;
};
export namespace TalerAuthentication {
export interface TokenRequest {
// Service-defined scope for the token.
// Typical scopes would be "readonly" or "readwrite".
scope: string;
// Server may impose its own upper bound
// on the token validity duration
duration?: RelativeTime;
// Is the token refreshable into a new token during its
// validity?
// Refreshable tokens effectively provide indefinite
// access if they are refreshed in time.
refreshable?: boolean;
}
export interface TokenSuccessResponse {
// Expiration determined by the server.
// Can be based on the token_duration
// from the request, but ultimately the
// server decides the expiration.
expiration: Timestamp;
// Opque access token.
access_token: AccessToken;
}
}
export interface CurrencySpecification {
// Name of the currency.
name: string;
// Decimal separator for fractional digits.
decimal_separator: 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;
// Whether the currency name should be rendered before (true) or
// after (false) the numeric value
is_currency_name_leading: boolean;
// 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]: string };
}
export const codecForAccessToken = codecForString as () => Codec<AccessToken>;
export const codecForTokenSuccessResponse =
(): Codec<TalerAuthentication.TokenSuccessResponse> =>
buildCodecForObject<TalerAuthentication.TokenSuccessResponse>()
.property("access_token", codecForAccessToken())
.property("expiration", codecForTimestamp)
.build("TalerAuthentication.TokenSuccessResponse")
export const codecForCurrencySpecificiation =
(): Codec<CurrencySpecification> =>
buildCodecForObject<CurrencySpecification>()
.property("name", codecForString())
.property("decimal_separator", codecForString())
.property("num_fractional_input_digits", codecForNumber())
.property("num_fractional_normal_digits", codecForNumber())
.property("num_fractional_trailing_zero_digits", codecForNumber())
.property("is_currency_name_leading", codecForBoolean())
.property("alt_unit_names", codecForMap(codecForString()))
.build("CurrencySpecification")
export const codecForCoreBankConfig =
(): Codec<TalerCorebankApi.Config> =>
buildCodecForObject<TalerCorebankApi.Config>()
.property("name", codecForString())
.property("version", codecForString())
.property("have_cashout", codecOptional(codecForBoolean()))
.property("currency", codecForCurrencySpecificiation())
.property("fiat_currency", codecOptional(codecForCurrencySpecificiation()))
.build("TalerCorebankApi.Config")
const codecForBalance = (): Codec<TalerCorebankApi.Balance> =>
buildCodecForObject<TalerCorebankApi.Balance>()
.property("amount", codecForAmountString())
.property("credit_debit_indicator", codecForEither(codecForConstString("credit"), codecForConstString("debit")))
.build("TalerCorebankApi.Balance")
const codecForPublicAccount = (): Codec<TalerCorebankApi.PublicAccount> =>
buildCodecForObject<TalerCorebankApi.PublicAccount>()
.property("account_name", codecForString())
.property("balance", codecForBalance())
.property("payto_uri", codecForPaytoURI())
.build("TalerCorebankApi.PublicAccount")
export const codecForPublicAccountsResponse =
(): Codec<TalerCorebankApi.PublicAccountsResponse> =>
buildCodecForObject<TalerCorebankApi.PublicAccountsResponse>()
.property("public_accounts", codecForList(codecForPublicAccount()))
.build("TalerCorebankApi.PublicAccountsResponse")
export const codecForAccountMinimalData =
(): Codec<TalerCorebankApi.AccountMinimalData> =>
buildCodecForObject<TalerCorebankApi.AccountMinimalData>()
.property("balance", codecForBalance())
.property("debit_threshold", codecForAmountString())
.property("name", codecForString())
.property("username", codecForString())
.build("TalerCorebankApi.AccountMinimalData")
export const codecForListBankAccountsResponse =
(): Codec<TalerCorebankApi.ListBankAccountsResponse> =>
buildCodecForObject<TalerCorebankApi.ListBankAccountsResponse>()
.property("accounts", codecForList(codecForAccountMinimalData()))
.build("TalerCorebankApi.ListBankAccountsResponse")
export const codecForAccountData =
(): Codec<TalerCorebankApi.AccountData> =>
buildCodecForObject<TalerCorebankApi.AccountData>()
.property("name", codecForString())
.property("balance", codecForBalance())
.property("payto_uri", codecForPaytoURI())
.property("debit_threshold", codecForAmountString())
.property("contact_data", codecOptional(codecForChallengeContactData()))
.property("cashout_payto_uri", codecOptional(codecForPaytoURI()))
.build("TalerCorebankApi.AccountData")
export const codecForChallengeContactData =
(): Codec<TalerCorebankApi.ChallengeContactData> =>
buildCodecForObject<TalerCorebankApi.ChallengeContactData>()
.property("email", codecOptional(codecForString()))
.property("phone", codecOptional(codecForString()))
.build("TalerCorebankApi.ChallengeContactData")
export const codecForBankAccountTransactionsResponse =
(): Codec<TalerCorebankApi.BankAccountTransactionsResponse> =>
buildCodecForObject<TalerCorebankApi.BankAccountTransactionsResponse>()
.property("transactions", codecForList(codecForBankAccountTransactionInfo()))
.build("TalerCorebankApi.BankAccountTransactionsResponse");
export const codecForBankAccountTransactionInfo =
(): Codec<TalerCorebankApi.BankAccountTransactionInfo> =>
buildCodecForObject<TalerCorebankApi.BankAccountTransactionInfo>()
.property("amount", codecForAmountString())
.property("creditor_payto_uri", codecForPaytoURI())
.property("date", codecForTimestamp)
.property("debtor_payto_uri", codecForPaytoURI())
.property("direction", codecForEither(codecForConstString("debit"), codecForConstString("credit")))
.property("row_id", codecForNumber())
.property("subject", codecForString())
.build("TalerCorebankApi.BankAccountTransactionInfo");
export const codecForBankAccountCreateWithdrawalResponse =
(): Codec<TalerCorebankApi.BankAccountCreateWithdrawalResponse> =>
buildCodecForObject<TalerCorebankApi.BankAccountCreateWithdrawalResponse>()
.property("taler_withdraw_uri", codecForTalerWithdrawalURI())
.property("withdrawal_id", codecForString())
.build("TalerCorebankApi.BankAccountCreateWithdrawalResponse");
export const codecForBankAccountGetWithdrawalResponse =
(): Codec<TalerCorebankApi.BankAccountGetWithdrawalResponse> =>
buildCodecForObject<TalerCorebankApi.BankAccountGetWithdrawalResponse>()
.property("aborted", codecForBoolean())
.property("amount", codecForAmountString())
.property("confirmation_done", codecForBoolean())
.property("selected_exchange_account", codecOptional(codecForString()))
.property("selected_reserve_pub", codecOptional(codecForString()))
.property("selection_done", (codecForBoolean()))
.build("TalerCorebankApi.BankAccountGetWithdrawalResponse");
export const codecForCashoutPending =
(): Codec<TalerCorebankApi.CashoutPending> =>
buildCodecForObject<TalerCorebankApi.CashoutPending>()
.property("cashout_id", codecForString())
.build("TalerCorebankApi.CashoutPending");
export const codecForCashoutConversionResponse =
(): Codec<TalerCorebankApi.CashoutConversionResponse> =>
buildCodecForObject<TalerCorebankApi.CashoutConversionResponse>()
.property("amount_credit", codecForAmountString())
.property("amount_debit", codecForAmountString())
.build("TalerCorebankApi.CashoutConversionResponse");
export const codecForCashouts =
(): Codec<TalerCorebankApi.Cashouts> =>
buildCodecForObject<TalerCorebankApi.Cashouts>()
.property("cashouts", codecForList(codecForCashoutInfo()))
.build("TalerCorebankApi.Cashouts");
export const codecForCashoutInfo =
(): Codec<TalerCorebankApi.CashoutInfo> =>
buildCodecForObject<TalerCorebankApi.CashoutInfo>()
.property("cashout_id", codecForString())
.property("status", codecForEither(codecForConstString("pending"), codecForConstString("confirmed"),))
.build("TalerCorebankApi.CashoutInfo");
export const codecForGlobalCashouts =
(): Codec<TalerCorebankApi.GlobalCashouts> =>
buildCodecForObject<TalerCorebankApi.GlobalCashouts>()
.property("cashouts", codecForList(codecForGlobalCashoutInfo()))
.build("TalerCorebankApi.GlobalCashouts");
export const codecForGlobalCashoutInfo =
(): Codec<TalerCorebankApi.GlobalCashoutInfo> =>
buildCodecForObject<TalerCorebankApi.GlobalCashoutInfo>()
.property("cashout_id", codecForString())
.property("username", codecForString())
.property("status", codecForEither(codecForConstString("pending"), codecForConstString("confirmed"),))
.build("TalerCorebankApi.GlobalCashoutInfo");
export const codecForCashoutStatusResponse =
(): Codec<TalerCorebankApi.CashoutStatusResponse> =>
buildCodecForObject<TalerCorebankApi.CashoutStatusResponse>()
.property("amount_credit", codecForAmountString())
.property("amount_debit", codecForAmountString())
.property("confirmation_time", codecForTimestamp)
.property("creation_time", codecForTimestamp)
.property("credit_payto_uri", codecForPaytoURI())
.property("status", codecForEither(codecForConstString("pending"), codecForConstString("confirmed")))
.property("subject", codecForString())
.build("TalerCorebankApi.CashoutStatusResponse");
export const codecForConversionRatesResponse =
(): Codec<TalerCorebankApi.ConversionRatesResponse> =>
buildCodecForObject<TalerCorebankApi.ConversionRatesResponse>()
.property("buy_at_ratio", codecForDecimalNumber())
.property("buy_in_fee", codecForDecimalNumber())
.property("sell_at_ratio", codecForDecimalNumber())
.property("sell_out_fee", codecForDecimalNumber())
.build("TalerCorebankApi.ConversionRatesResponse");
export const codecForMonitorResponse =
(): Codec<TalerCorebankApi.MonitorResponse> =>
buildCodecForObject<TalerCorebankApi.MonitorResponse>()
.property("cashinCount", codecForNumber())
.property("cashinExternalVolume", codecForAmountString())
.property("cashoutCount", codecForNumber())
.property("cashoutExternalVolume", codecForAmountString())
.property("talerPayoutCount", codecForNumber())
.property("talerPayoutInternalVolume", codecForAmountString())
.build("TalerCorebankApi.MonitorResponse");
export const codecForBankVersion =
(): Codec<TalerBankIntegrationApi.BankVersion> =>
buildCodecForObject<TalerBankIntegrationApi.BankVersion>()
.property("currency", codecForCurrencyName())
.property("currency_specification", codecForCurrencySpecificiation())
.property("name", codecForConstString("taler-bank-integration"))
.property("version", codecForLibtoolVersion())
.build("TalerBankIntegrationApi.BankVersion");
export const codecForBankWithdrawalOperationStatus =
(): Codec<TalerBankIntegrationApi.BankWithdrawalOperationStatus> =>
buildCodecForObject<TalerBankIntegrationApi.BankWithdrawalOperationStatus>()
.property("aborted", codecForBoolean())
.property("amount", codecForAmountString())
.property("confirm_transfer_url", codecOptional(codecForURL()))
.property("selection_done", codecForBoolean())
.property("sender_wire", codecForPaytoURI())
.property("suggested_exchange", codecOptional(codecForString()))
.property("transfer_done", codecForBoolean())
.property("wire_types", codecForList(codecForString()))
.build("TalerBankIntegrationApi.BankWithdrawalOperationStatus");
export const codecForBankWithdrawalOperationPostResponse =
(): Codec<TalerBankIntegrationApi.BankWithdrawalOperationPostResponse> =>
buildCodecForObject<TalerBankIntegrationApi.BankWithdrawalOperationPostResponse>()
.property("confirm_transfer_url", codecForURL())
.property("transfer_done", codecForBoolean())
.build("TalerBankIntegrationApi.BankWithdrawalOperationPostResponse");
export const codecForMerchantIncomingHistory =
(): Codec<TalerRevenueApi.MerchantIncomingHistory> =>
buildCodecForObject<TalerRevenueApi.MerchantIncomingHistory>()
.property("credit_account", codecForPaytoURI())
.property("incoming_transactions", codecForList(codecForMerchantIncomingBankTransaction()))
.build("TalerRevenueApi.MerchantIncomingHistory");
export const codecForMerchantIncomingBankTransaction =
(): Codec<TalerRevenueApi.MerchantIncomingBankTransaction> =>
buildCodecForObject<TalerRevenueApi.MerchantIncomingBankTransaction>()
.property("amount", codecForAmountString())
.property("date", codecForTimestamp)
.property("debit_account", codecForPaytoURI())
.property("exchange_url", codecForURL())
.property("row_id", codecForNumber())
.property("wtid", codecForString())
.build("TalerRevenueApi.MerchantIncomingBankTransaction");
export const codecForTransferResponse =
(): Codec<TalerWireGatewayApi.TransferResponse> =>
buildCodecForObject<TalerWireGatewayApi.TransferResponse>()
.property("row_id", codecForNumber())
.property("timestamp", codecForTimestamp)
.build("TalerWireGatewayApi.TransferResponse");
export const codecForIncomingHistory =
(): Codec<TalerWireGatewayApi.IncomingHistory> =>
buildCodecForObject<TalerWireGatewayApi.IncomingHistory>()
.property("credit_account", codecForString())
.property("incoming_transactions", codecForList(codecForIncomingBankTransaction()))
.build("TalerWireGatewayApi.IncomingHistory");
export const codecForIncomingBankTransaction = (): Codec<TalerWireGatewayApi.IncomingBankTransaction> => buildCodecForUnion<TalerWireGatewayApi.IncomingBankTransaction>()
.discriminateOn("type")
.alternative("RESERVE", codecForIncomingReserveTransaction())
.alternative("WAD", codecForIncomingWadTransaction())
.build("TalerWireGatewayApi.IncomingBankTransaction");
export const codecForIncomingReserveTransaction =
(): Codec<TalerWireGatewayApi.IncomingReserveTransaction> =>
buildCodecForObject<TalerWireGatewayApi.IncomingReserveTransaction>()
.property("amount", codecForAmountString())
.property("date", codecForTimestamp)
.property("debit_account", codecForPaytoURI())
.property("reserve_pub", codecForString())
.property("row_id", codecForNumber())
.property("type", codecForConstString("RESERVE"))
.build("TalerWireGatewayApi.IncomingReserveTransaction");
export const codecForIncomingWadTransaction =
(): Codec<TalerWireGatewayApi.IncomingWadTransaction> =>
buildCodecForObject<TalerWireGatewayApi.IncomingWadTransaction>()
.property("amount", codecForAmountString())
.property("credit_account", codecForPaytoURI())
.property("date", codecForTimestamp)
.property("debit_account", codecForPaytoURI())
.property("origin_exchange_url", codecForURL())
.property("row_id", codecForNumber())
.property("type", codecForConstString("WAD"))
.property("wad_id", codecForString())
.build("TalerWireGatewayApi.IncomingWadTransaction");
export const codecForOutgoingHistory =
(): Codec<TalerWireGatewayApi.OutgoingHistory> =>
buildCodecForObject<TalerWireGatewayApi.OutgoingHistory>()
.property("debit_account", codecForString())
.property("outgoing_transactions", codecForList(codecForOutgoingBankTransaction()))
.build("TalerWireGatewayApi.OutgoingHistory");
export const codecForOutgoingBankTransaction =
(): Codec<TalerWireGatewayApi.OutgoingBankTransaction> =>
buildCodecForObject<TalerWireGatewayApi.OutgoingBankTransaction>()
.property("amount", codecForAmountString())
.property("credit_account", codecForPaytoURI())
.property("date", codecForTimestamp)
.property("exchange_base_url", codecForURL())
.property("row_id", codecForNumber())
.property("wtid", codecForString())
.build("TalerWireGatewayApi.OutgoingBankTransaction");
export const codecForAddIncomingResponse =
(): Codec<TalerWireGatewayApi.AddIncomingResponse> =>
buildCodecForObject<TalerWireGatewayApi.AddIncomingResponse>()
.property("row_id", codecForNumber())
.property("timestamp", codecForTimestamp)
.build("TalerWireGatewayApi.AddIncomingResponse");
// export const codecFor =
// (): Codec<TalerWireGatewayApi.PublicAccountsResponse> =>
// buildCodecForObject<TalerWireGatewayApi.PublicAccountsResponse>()
// .property("", codecForString())
// .build("TalerWireGatewayApi.PublicAccountsResponse");
type EmailAddress = string;
type PhoneNumber = string;
type DecimalNumber = string;
const codecForURL = codecForString
const codecForLibtoolVersion = codecForString
const codecForCurrencyName = codecForString
const codecForPaytoURI = codecForString
const codecForTalerWithdrawalURI = codecForString
const codecForDecimalNumber = codecForString
enum TanChannel {
SMS = "sms",
EMAIL = "email",
FILE = "file"
}
export namespace TalerWireGatewayApi {
export interface TransferResponse {
// Timestamp that indicates when the wire transfer will be executed.
// In cases where the wire transfer gateway is unable to know when
// the wire transfer will be executed, the time at which the request
// has been received and stored will be returned.
// The purpose of this field is for debugging (humans trying to find
// the transaction) as well as for taxation (determining which
// time period a transaction belongs to).
timestamp: Timestamp;
// Opaque ID of the transaction that the bank has made.
row_id: SafeUint64;
}
export interface TransferRequest {
// Nonce to make the request idempotent. Requests with the same
// transaction_uid that differ in any of the other fields
// are rejected.
request_uid: HashCode;
// Amount to transfer.
amount: Amount;
// Base URL of the exchange. Shall be included by the bank gateway
// in the appropriate section of the wire transfer details.
exchange_base_url: string;
// Wire transfer identifier chosen by the exchange,
// used by the merchant to identify the Taler order(s)
// associated with this wire transfer.
wtid: ShortHashCode;
// The recipient's account identifier as a payto URI.
credit_account: string;
}
export interface IncomingHistory {
// Array of incoming transactions.
incoming_transactions: IncomingBankTransaction[];
// Payto URI to identify the receiver of funds.
// This must be one of the exchange's bank accounts.
// Credit account is shared by all incoming transactions
// as per the nature of the request.
credit_account: string;
}
// Union discriminated by the "type" field.
export type IncomingBankTransaction =
| IncomingReserveTransaction
| IncomingWadTransaction;
export interface IncomingReserveTransaction {
type: "RESERVE";
// Opaque identifier of the returned record.
row_id: SafeUint64;
// Date of the transaction.
date: Timestamp;
// Amount transferred.
amount: Amount;
// Payto URI to identify the sender of funds.
debit_account: string;
// The reserve public key extracted from the transaction details.
reserve_pub: EddsaPublicKey;
}
export interface IncomingWadTransaction {
type: "WAD";
// Opaque identifier of the returned record.
row_id: SafeUint64;
// Date of the transaction.
date: Timestamp;
// Amount transferred.
amount: Amount;
// Payto URI to identify the receiver of funds.
// This must be one of the exchange's bank accounts.
credit_account: string;
// Payto URI to identify the sender of funds.
debit_account: string;
// Base URL of the exchange that originated the wad.
origin_exchange_url: string;
// The reserve public key extracted from the transaction details.
wad_id: WadId;
}
export interface OutgoingHistory {
// Array of outgoing transactions.
outgoing_transactions: OutgoingBankTransaction[];
// Payto URI to identify the sender of funds.
// This must be one of the exchange's bank accounts.
// Credit account is shared by all incoming transactions
// as per the nature of the request.
debit_account: string;
}
export interface OutgoingBankTransaction {
// Opaque identifier of the returned record.
row_id: SafeUint64;
// Date of the transaction.
date: Timestamp;
// Amount transferred.
amount: Amount;
// Payto URI to identify the receiver of funds.
credit_account: string;
// The wire transfer ID in the outgoing transaction.
wtid: ShortHashCode;
// Base URL of the exchange.
exchange_base_url: string;
}
export interface AddIncomingRequest {
// Amount to transfer.
amount: Amount;
// Reserve public key that is included in the wire transfer details
// to identify the reserve that is being topped up.
reserve_pub: EddsaPublicKey;
// Account (as payto URI) that makes the wire transfer to the exchange.
// Usually this account must be created by the test harness before this API is
// used. An exception is the "exchange-fakebank", where any debit account can be
// specified, as it is automatically created.
debit_account: string;
}
export interface AddIncomingResponse {
// Timestamp that indicates when the wire transfer will be executed.
// In cases where the wire transfer gateway is unable to know when
// the wire transfer will be executed, the time at which the request
// has been received and stored will be returned.
// The purpose of this field is for debugging (humans trying to find
// the transaction) as well as for taxation (determining which
// time period a transaction belongs to).
timestamp: Timestamp;
// Opaque ID of the transaction that the bank has made.
row_id: SafeUint64;
}
}
export namespace TalerRevenueApi {
export interface MerchantIncomingHistory {
// Array of incoming transactions.
incoming_transactions: MerchantIncomingBankTransaction[];
// Payto URI to identify the receiver of funds.
// This must be one of the merchant's bank accounts.
// Credit account is shared by all incoming transactions
// as per the nature of the request.
credit_account: string;
}
export interface MerchantIncomingBankTransaction {
// Opaque identifier of the returned record.
row_id: SafeUint64;
// Date of the transaction.
date: Timestamp;
// Amount transferred.
amount: Amount;
// Payto URI to identify the sender of funds.
debit_account: string;
// Base URL of the exchange where the transfer originated form.
exchange_url: string;
// The wire transfer identifier.
wtid: WireTransferIdentifierRawP;
}
}
export namespace TalerBankIntegrationApi {
export interface BankVersion {
// libtool-style representation of the Bank protocol version, see
// https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning
// The format is "current:revision:age".
version: string;
// Currency used by this bank.
currency: string;
// How the bank SPA should render this currency.
currency_specification: CurrencySpecification;
// Name of the API.
name: "taler-bank-integration";
}
export interface BankWithdrawalOperationStatus {
// Indicates whether the withdrawal was aborted.
aborted: boolean;
// Has the wallet selected parameters for the withdrawal operation
// (exchange and reserve public key) and successfully sent it
// to the bank?
selection_done: boolean;
// The transfer has been confirmed and registered by the bank.
// Does not guarantee that the funds have arrived at the exchange already.
transfer_done: boolean;
// Amount that will be withdrawn with this operation
// (raw amount without fee considerations).
amount: Amount;
// Bank account of the customer that is withdrawing, as a
// payto URI.
sender_wire?: string;
// Suggestion for an exchange given by the bank.
suggested_exchange?: string;
// URL that the user needs to navigate to in order to
// complete some final confirmation (e.g. 2FA).
// It may contain withdrawal operation id
confirm_transfer_url?: string;
// Wire transfer types supported by the bank.
wire_types: string[];
}
export interface BankWithdrawalOperationPostRequest {
// Reserve public key.
reserve_pub: string;
// Payto address of the exchange selected for the withdrawal.
selected_exchange: string;
}
export interface BankWithdrawalOperationPostResponse {
// The transfer has been confirmed and registered by the bank.
// Does not guarantee that the funds have arrived at the exchange already.
transfer_done: boolean;
// URL that the user needs to navigate to in order to
// complete some final confirmation (e.g. 2FA).
//
// Only applicable when transfer_done is false.
// It may contain withdrawal operation id
confirm_transfer_url?: string;
}
}
export namespace TalerCorebankApi {
export interface Config {
// Name of this API, always "circuit".
name: string;
// API version in the form $n:$n:$n
version: string;
// If 'true', the server provides local currency
// conversion support.
// If missing or false, some parts of the API
// are not supported and return 404.
have_cashout?: boolean;
// How the bank SPA should render the currency.
currency: CurrencySpecification;
// Fiat currency. That is the currency in which
// cash-out operations ultimately wire money.
// Only applicable if have_cashout=true.
fiat_currency?: CurrencySpecification;
}
export interface BankAccountCreateWithdrawalRequest {
// Amount to withdraw.
amount: Amount;
}
export interface BankAccountCreateWithdrawalResponse {
// ID of the withdrawal, can be used to view/modify the withdrawal operation.
withdrawal_id: string;
// URI that can be passed to the wallet to initiate the withdrawal.
taler_withdraw_uri: string;
}
export interface BankAccountGetWithdrawalResponse {
// Amount that will be withdrawn with this withdrawal operation.
amount: Amount;
// Was the withdrawal aborted?
aborted: boolean;
// Has the withdrawal been confirmed by the bank?
// The wire transfer for a withdrawal is only executed once
// both confirmation_done is true and selection_done is true.
confirmation_done: boolean;
// Did the wallet select reserve details?
selection_done: boolean;
// Reserve public key selected by the exchange,
// only non-null if selection_done is true.
selected_reserve_pub: string | undefined;
// Exchange account selected by the wallet, or by the bank
// (with the default exchange) in case the wallet did not provide one
// through the Integration API.
selected_exchange_account: string | undefined;
}
export interface BankAccountTransactionsResponse {
transactions: BankAccountTransactionInfo[];
}
export interface BankAccountTransactionInfo {
creditor_payto_uri: string;
debtor_payto_uri: string;
amount: Amount;
direction: "debit" | "credit";
subject: string;
// Transaction unique ID. Matches
// $transaction_id from the URI.
row_id: number;
date: Timestamp;
}
export interface CreateBankAccountTransactionCreate {
// Address in the Payto format of the wire transfer receiver.
// It needs at least the 'message' query string parameter.
payto_uri: string;
// Transaction amount (in the $currency:x.y format), optional.
// However, when not given, its value must occupy the 'amount'
// query string parameter of the 'payto' field. In case it
// is given in both places, the paytoUri's takes the precedence.
amount?: string;
}
export interface RegisterAccountRequest {
// Username
username: string;
// Password.
password: string;
// Legal name of the account owner
name: string;
// Defaults to false.
is_public?: boolean;
// Is this a taler exchange account?
// If true:
// - incoming transactions to the account that do not
// have a valid reserve public key are automatically
// - the account provides the taler-wire-gateway-api endpoints
// Defaults to false.
is_taler_exchange?: boolean;
// Addresses where to send the TAN for transactions.
// Currently only used for cashouts.
// If missing, cashouts will fail.
// In the future, might be used for other transactions
// as well.
challenge_contact_data?: ChallengeContactData;
// 'payto' address pointing a bank account
// external to the libeufin-bank.
// Payments will be sent to this bank account
// when the user wants to convert the local currency
// back to fiat currency outside libeufin-bank.
cashout_payto_uri?: string;
// Internal payto URI of this bank account.
// Used mostly for testing.
internal_payto_uri?: string;
}
export interface ChallengeContactData {
// E-Mail address
email?: EmailAddress;
// Phone number.
phone?: PhoneNumber;
}
export interface AccountReconfiguration {
// Addresses where to send the TAN for transactions.
// Currently only used for cashouts.
// If missing, cashouts will fail.
// In the future, might be used for other transactions
// as well.
challenge_contact_data?: ChallengeContactData;
// 'payto' address pointing a bank account
// external to the libeufin-bank.
// Payments will be sent to this bank account
// when the user wants to convert the local currency
// back to fiat currency outside libeufin-bank.
cashout_address?: string;
// Legal name associated with $username.
// When missing, the old name is kept.
name?: string;
// If present, change the is_exchange configuration.
// See RegisterAccountRequest
is_exchange?: boolean;
}
export interface AccountPasswordChange {
// New password.
new_password: string;
}
export interface PublicAccountsResponse {
public_accounts: PublicAccount[];
}
export interface PublicAccount {
payto_uri: string;
balance: Balance;
// The account name (=username) of the
// libeufin-bank account.
account_name: string;
}
export interface ListBankAccountsResponse {
accounts: AccountMinimalData[];
}
export interface Balance {
amount: Amount;
credit_debit_indicator: "credit" | "debit";
}
export interface AccountMinimalData {
// Username
username: string;
// Legal name of the account owner.
name: string;
// current balance of the account
balance: Balance;
// Number indicating the max debit allowed for the requesting user.
debit_threshold: Amount;
}
export interface AccountData {
// Legal name of the account owner.
name: string;
// Available balance on the account.
balance: Balance;
// payto://-URI of the account.
payto_uri: string;
// Number indicating the max debit allowed for the requesting user.
debit_threshold: Amount;
contact_data?: ChallengeContactData;
// 'payto' address pointing the bank account
// where to send cashouts. This field is optional
// because not all the accounts are required to participate
// in the merchants' circuit. One example is the exchange:
// that never cashouts. Registering these accounts can
// be done via the access API.
cashout_payto_uri?: string;
}
export interface CashoutRequest {
// Optional subject to associate to the
// cashout operation. This data will appear
// as the incoming wire transfer subject in
// the user's external bank account.
subject?: string;
// That is the plain amount that the user specified
// to cashout. Its $currency is the (regional) currency of the
// bank instance.
amount_debit: Amount;
// That is the amount that will effectively be
// transferred by the bank to the user's bank
// account, that is external to the regional currency.
// It is expressed in the fiat currency and
// is calculated after the cashout fee and the
// exchange rate. See the /cashout-rates call.
// The client needs to calculate this amount
// correctly based on the amount_debit and the cashout rate,
// otherwise the request will fail.
amount_credit: Amount;
// Which channel the TAN should be sent to. If
// this field is missing, it defaults to SMS.
// The default choice prefers to change the communication
// channel respect to the one used to issue this request.
tan_channel?: TanChannel;
}
export interface CashoutPending {
// ID identifying the operation being created
// and now waiting for the TAN confirmation.
cashout_id: string;
}
export interface CashoutConfirmRequest {
// the TAN that confirms $CASHOUT_ID.
tan: string;
}
export interface CashoutConversionResponse {
// Amount that the user will get deducted from their regional
// bank account, according to the 'amount_credit' value.
amount_debit: Amount;
// Amount that the user will receive in their fiat
// bank account, according to 'amount_debit'.
amount_credit: Amount;
}
export interface Cashouts {
// Every string represents a cash-out operation ID.
cashouts: CashoutInfo[];
}
export interface CashoutInfo {
cashout_id: string;
status: "pending" | "confirmed";
}
export interface GlobalCashouts {
// Every string represents a cash-out operation ID.
cashouts: GlobalCashoutInfo[];
}
export interface GlobalCashoutInfo {
cashout_id: string;
username: string;
status: "pending" | "confirmed";
}
export interface CashoutStatusResponse {
status: "pending" | "confirmed";
// Amount debited to the internal
// regional currency bank account.
amount_debit: Amount;
// Amount credited to the external bank account.
amount_credit: Amount;
// Transaction subject.
subject: string;
// Fiat bank account that will receive the cashed out amount.
// Specified as a payto URI.
credit_payto_uri: string;
// Time when the cashout was created.
creation_time: Timestamp;
// Time when the cashout was confirmed via its TAN.
// Missing when the operation wasn't confirmed yet.
confirmation_time?: Timestamp;
}
export interface ConversionRatesResponse {
// Exchange rate to buy the local currency from the external one
buy_at_ratio: DecimalNumber;
// Exchange rate to sell the local currency for the external one
sell_at_ratio: DecimalNumber;
// Fee to subtract after applying the buy ratio.
buy_in_fee: DecimalNumber;
// Fee to subtract after applying the sell ratio.
sell_out_fee: DecimalNumber;
}
export enum MonitorTimeframeParam {
hour, day, month, year, decade,
}
export interface MonitorResponse {
// This number identifies how many cashin operations
// took place in the timeframe specified in the request.
// This number corresponds to how many withdrawals have
// been initiated by a wallet owner. Note: wallet owners
// are NOT required to be customers of the libeufin-bank.
cashinCount: number;
// This amount accounts how much external currency has been
// spent to withdraw Taler coins in the internal currency.
// The exact amount of internal currency being created can be
// calculated using the advertised conversion rates.
cashinExternalVolume: Amount;
// This number identifies how many cashout operations were
// confirmed in the timeframe speficied in the request.
cashoutCount: number;
// This amount corresponds to how much *external* currency was
// paid by the libeufin-bank administrator to fulfill all the
// confirmed cashouts related to the timeframe specified in the
// request.
cashoutExternalVolume: Amount;
// This number identifies how many payments were made by a
// Taler exchange to a merchant bank account in the internal
// currency, in the timeframe specified in the request.
talerPayoutCount: number;
// This amount accounts the overall *internal* currency that
// has been paid by a Taler exchange to a merchant internal
// bank account, in the timeframe specified in the request.
talerPayoutInternalVolume: Amount;
}
}
|