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
|
/*
This file is part of TALER
(C) 2018 GNUnet e.V. and INRIA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* Type and schema definitions for the base taler protocol.
*
* All types here should be "@Checkable".
*
* Even though the rest of the wallet uses camelCase for fields, use snake_case
* here, since that's the convention for the Taler JSON+HTTP API.
*/
/**
* Imports.
*/
import { AmountJson } from "./amounts";
import { Checkable } from "./checkable";
/**
* Denomination as found in the /keys response from the exchange.
*/
@Checkable.Class()
export class Denomination {
/**
* Value of one coin of the denomination.
*/
@Checkable.Value(AmountJson)
value: AmountJson;
/**
* Public signing key of the denomination.
*/
@Checkable.String
denom_pub: string;
/**
* Fee for withdrawing.
*/
@Checkable.Value(AmountJson)
fee_withdraw: AmountJson;
/**
* Fee for depositing.
*/
@Checkable.Value(AmountJson)
fee_deposit: AmountJson;
/**
* Fee for refreshing.
*/
@Checkable.Value(AmountJson)
fee_refresh: AmountJson;
/**
* Fee for refunding.
*/
@Checkable.Value(AmountJson)
fee_refund: AmountJson;
/**
* Start date from which withdraw is allowed.
*/
@Checkable.String
stamp_start: string;
/**
* End date for withdrawing.
*/
@Checkable.String
stamp_expire_withdraw: string;
/**
* Expiration date after which the exchange can forget about
* the currency.
*/
@Checkable.String
stamp_expire_legal: string;
/**
* Date after which the coins of this denomination can't be
* deposited anymore.
*/
@Checkable.String
stamp_expire_deposit: string;
/**
* Signature over the denomination information by the exchange's master
* signing key.
*/
@Checkable.String
master_sig: string;
/**
* Verify that a value matches the schema of this class and convert it into a
* member.
*/
static checked: (obj: any) => Denomination;
}
/**
* Signature by the auditor that a particular denomination key is audited.
*/
@Checkable.Class()
export class AuditorDenomSig {
/**
* Denomination public key's hash.
*/
@Checkable.String
denom_pub_h: string;
/**
* The signature.
*/
@Checkable.String
auditor_sig: string;
}
/**
* Auditor information as given by the exchange in /keys.
*/
@Checkable.Class()
export class Auditor {
/**
* Auditor's public key.
*/
@Checkable.String
auditor_pub: string;
/**
* Base URL of the auditor.
*/
@Checkable.String
auditor_url: string;
/**
* List of signatures for denominations by the auditor.
*/
@Checkable.List(Checkable.Value(AuditorDenomSig))
denomination_keys: AuditorDenomSig[];
}
/**
* Request that we send to the exchange to get a payback.
*/
export interface PaybackRequest {
/**
* Denomination public key of the coin we want to get
* paid back.
*/
denom_pub: string;
/**
* Signature over the coin public key by the denomination.
*/
denom_sig: string;
/**
* Coin public key of the coin we want to refund.
*/
coin_pub: string;
/**
* Blinding key that was used during withdraw,
* used to prove that we were actually withdrawing the coin.
*/
coin_blind_key_secret: string;
/**
* Signature made by the coin, authorizing the payback.
*/
coin_sig: string;
}
/**
* Response that we get from the exchange for a payback request.
*/
@Checkable.Class()
export class PaybackConfirmation {
/**
* public key of the reserve that will receive the payback.
*/
@Checkable.String
reserve_pub: string;
/**
* How much will the exchange pay back (needed by wallet in
* case coin was partially spent and wallet got restored from backup)
*/
@Checkable.Value(AmountJson)
amount: AmountJson;
/**
* Time by which the exchange received the /payback request.
*/
@Checkable.String
timestamp: string;
/**
* the EdDSA signature of TALER_PaybackConfirmationPS using a current
* signing key of the exchange affirming the successful
* payback request, and that the exchange promises to transfer the funds
* by the date specified (this allows the exchange delaying the transfer
* a bit to aggregate additional payback requests into a larger one).
*/
@Checkable.String
exchange_sig: string;
/**
* Public EdDSA key of the exchange that was used to generate the signature.
* Should match one of the exchange's signing keys from /keys. It is given
* explicitly as the client might otherwise be confused by clock skew as to
* which signing key was used.
*/
@Checkable.String
exchange_pub: string;
/**
* Verify that a value matches the schema of this class and convert it into a
* member.
*/
static checked: (obj: any) => PaybackConfirmation;
}
/**
* Deposit permission for a single coin.
*/
export interface CoinPaySig {
/**
* Signature by the coin.
*/
coin_sig: string;
/**
* Public key of the coin being spend.
*/
coin_pub: string;
/**
* Signature made by the denomination public key.
*/
ub_sig: string;
/**
* The denomination public key associated with this coin.
*/
denom_pub: string;
/**
* The amount that is subtracted from this coin with this payment.
*/
contribution: AmountJson;
/**
* URL of the exchange this coin was withdrawn from.
*/
exchange_url: string;
}
/**
* Information about an exchange as stored inside a
* merchant's contract terms.
*/
@Checkable.Class()
export class ExchangeHandle {
/**
* Master public signing key of the exchange.
*/
@Checkable.String
master_pub: string;
/**
* Base URL of the exchange.
*/
@Checkable.String
url: string;
/**
* Verify that a value matches the schema of this class and convert it into a
* member.
*/
static checked: (obj: any) => ExchangeHandle;
}
/**
* Contract terms from a merchant.
*/
@Checkable.Class({validate: true})
export class ContractTerms {
static validate(x: ContractTerms) {
if (x.exchanges.length === 0) {
throw Error("no exchanges in contract terms");
}
}
/**
* Hash of the merchant's wire details.
*/
@Checkable.String
H_wire: string;
/**
* Wire method the merchant wants to use.
*/
@Checkable.String
wire_method: string;
/**
* Human-readable short summary of the contract.
*/
@Checkable.Optional(Checkable.String)
summary?: string;
/**
* Nonce used to ensure freshness.
*/
@Checkable.Optional(Checkable.String)
nonce?: string;
/**
* Total amount payable.
*/
@Checkable.Value(AmountJson)
amount: AmountJson;
/**
* Auditors accepted by the merchant.
*/
@Checkable.List(Checkable.AnyObject)
auditors: any[];
/**
* Deadline to pay for the contract.
*/
@Checkable.Optional(Checkable.String)
pay_deadline: string;
/**
* Delivery locations.
*/
@Checkable.Any
locations: any;
/**
* Maximum deposit fee covered by the merchant.
*/
@Checkable.Value(AmountJson)
max_fee: AmountJson;
/**
* Information about the merchant.
*/
@Checkable.Any
merchant: any;
/**
* Public key of the merchant.
*/
@Checkable.String
merchant_pub: string;
/**
* List of accepted exchanges.
*/
@Checkable.List(Checkable.Value(ExchangeHandle))
exchanges: ExchangeHandle[];
/**
* Products that are sold in this contract.
*/
@Checkable.List(Checkable.AnyObject)
products: any[];
/**
* Deadline for refunds.
*/
@Checkable.String
refund_deadline: string;
/**
* Time when the contract was generated by the merchant.
*/
@Checkable.String
timestamp: string;
/**
* Order id to uniquely identify the purchase within
* one merchant instance.
*/
@Checkable.String
order_id: string;
/**
* URL to post the payment to.
*/
@Checkable.String
pay_url: string;
/**
* Fulfillment URL to view the product or
* delivery status.
*/
@Checkable.String
fulfillment_url: string;
/**
* Share of the wire fee that must be settled with one payment.
*/
@Checkable.Optional(Checkable.Number)
wire_fee_amortization?: number;
/**
* Maximum wire fee that the merchant agrees to pay for.
*/
@Checkable.Optional(Checkable.Value(AmountJson))
max_wire_fee?: AmountJson;
/**
* Extra data, interpreted by the mechant only.
*/
@Checkable.Any
extra: any;
/**
* Verify that a value matches the schema of this class and convert it into a
* member.
*/
static checked: (obj: any) => ContractTerms;
}
/**
* Payment body sent to the merchant's /pay.
*/
export interface PayReq {
/**
* Coins with signature.
*/
coins: CoinPaySig[];
/**
* The merchant public key, used to uniquely
* identify the merchant instance.
*/
merchant_pub: string;
/**
* Order ID that's being payed for.
*/
order_id: string;
/**
* Mode for /pay (pay or refund)
*/
mode: string;
}
/**
* Refund permission in the format that the merchant gives it to us.
*/
export interface RefundPermission {
/**
* Amount to be refunded.
*/
refund_amount: AmountJson;
/**
* Fee for the refund.
*/
refund_fee: AmountJson;
/**
* Contract terms hash to identify the contract that this
* refund is for.
*/
h_contract_terms: string;
/**
* Public key of the coin being refunded.
*/
coin_pub: string;
/**
* Refund transaction ID between merchant and exchange.
*/
rtransaction_id: number;
/**
* Public key of the merchant.
*/
merchant_pub: string;
/**
* Signature made by the merchant over the refund permission.
*/
merchant_sig: string;
}
/**
* Planchet detail sent to the merchant.
*/
export interface TipPlanchetDetail {
/**
* Hashed denomination public key.
*/
denom_pub_hash: string;
/**
* Coin's blinded public key.
*/
coin_ev: string;
}
/**
* Request sent to the merchant to pick up a tip.
*/
export interface TipPickupRequest {
/**
* Identifier of the tip.
*/
tip_id: string;
/**
* List of planchets the wallet wants to use for the tip.
*/
planchets: TipPlanchetDetail[];
}
/**
* Reserve signature, defined as separate class to facilitate
* schema validation with "@Checkable".
*/
@Checkable.Class()
export class ReserveSigSingleton {
/**
* Reserve signature.
*/
@Checkable.String
reserve_sig: string;
/**
* Create a ReserveSigSingleton from untyped JSON.
*/
static checked: (obj: any) => ReserveSigSingleton;
}
/**
* Response of the merchant
* to the TipPickupRequest.
*/
@Checkable.Class()
export class TipResponse {
/**
* Public key of the reserve
*/
@Checkable.String
reserve_pub: string;
/**
* The order of the signatures matches the planchets list.
*/
@Checkable.List(Checkable.Value(ReserveSigSingleton))
reserve_sigs: ReserveSigSingleton[];
/**
* Create a TipResponse from untyped JSON.
*/
static checked: (obj: any) => TipResponse;
}
/**
* Token containing all the information for the wallet
* to process a tip. Given by the merchant to the wallet.
*/
@Checkable.Class()
export class TipToken {
/**
* Expiration for the tip.
*/
@Checkable.String
expiration: string;
/**
* URL of the exchange that the tip can be withdrawn from.
*/
@Checkable.String
exchange_url: string;
/**
* Merchant's URL to pick up the tip.
*/
@Checkable.String
pickup_url: string;
/**
* Merchant-chosen tip identifier.
*/
@Checkable.String
tip_id: string;
/**
* Amount of tip.
*/
@Checkable.Value(AmountJson)
amount: AmountJson;
/**
* URL to navigate after finishing tip processing.
*/
@Checkable.String
next_url: string;
/**
* Create a TipToken from untyped JSON.
* Validates the schema and throws on error.
*/
static checked: (obj: any) => TipToken;
}
/**
* Element of the payback list that the
* exchange gives us in /keys.
*/
@Checkable.Class()
export class Payback {
/**
* The hash of the denomination public key for which the payback is offered.
*/
@Checkable.String
h_denom_pub: string;
}
/**
* Structure that the exchange gives us in /keys.
*/
@Checkable.Class({extra: true})
export class KeysJson {
/**
* List of offered denominations.
*/
@Checkable.List(Checkable.Value(Denomination))
denoms: Denomination[];
/**
* The exchange's master public key.
*/
@Checkable.String
master_public_key: string;
/**
* The list of auditors (partially) auditing the exchange.
*/
@Checkable.List(Checkable.Value(Auditor))
auditors: Auditor[];
/**
* Timestamp when this response was issued.
*/
@Checkable.String
list_issue_date: string;
/**
* List of paybacks for compromised denominations.
*/
@Checkable.Optional(Checkable.List(Checkable.Value(Payback)))
payback?: Payback[];
/**
* Short-lived signing keys used to sign online
* responses.
*/
@Checkable.Any
signkeys: any;
/**
* Protocol version.
*/
@Checkable.Optional(Checkable.String)
version?: string;
/**
* Verify that a value matches the schema of this class and convert it into a
* member.
*/
static checked: (obj: any) => KeysJson;
}
/**
* Wire fees as anounced by the exchange.
*/
@Checkable.Class()
export class WireFeesJson {
/**
* Cost of a wire transfer.
*/
@Checkable.Value(AmountJson)
wire_fee: AmountJson;
/**
* Cost of clising a reserve.
*/
@Checkable.Value(AmountJson)
closing_fee: AmountJson;
/**
* Signature made with the exchange's master key.
*/
@Checkable.String
sig: string;
/**
* Date from which the fee applies.
*/
@Checkable.String
start_date: string;
/**
* Data after which the fee doesn't apply anymore.
*/
@Checkable.String
end_date: string;
/**
* Verify that a value matches the schema of this class and convert it into a
* member.
*/
static checked: (obj: any) => WireFeesJson;
}
/**
* Information about wire transfer methods supported
* by the exchange.
*/
@Checkable.Class({extra: true})
export class WireDetailJson {
/**
* Name of the wire transfer method.
*/
@Checkable.String
type: string;
/**
* Fees associated with the wire transfer method.
*/
@Checkable.List(Checkable.Value(WireFeesJson))
fees: WireFeesJson[];
/**
* Verify that a value matches the schema of this class and convert it into a
* member.
*/
static checked: (obj: any) => WireDetailJson;
}
/**
* Wire detail, arbitrary object that must at least
* contain a "type" key.
*/
export type WireDetail = object & { type: string };
/**
* Type guard for wire details.
*/
export function isWireDetail(x: any): x is WireDetail {
return x && typeof x === "object" && typeof x.type === "string";
}
|