wallet-core/packages/taler-util/src/ReserveTransaction.ts

246 lines
6.3 KiB
TypeScript
Raw Normal View History

2019-12-16 16:59:09 +01:00
/*
This file is part of GNU Taler
(C) 2019 Taler Systems S.A.
GNU 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.
GNU 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
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
2020-12-07 22:54:36 +01:00
* Type declarations for the exchange's reserve transaction information.
*
2019-12-16 16:59:09 +01:00
* @author Florian Dold <dold@taler.net>
*/
/**
* Imports.
*/
import {
codecForString,
2020-08-12 12:32:58 +02:00
buildCodecForObject,
codecForConstString,
buildCodecForUnion,
2020-04-06 20:02:01 +02:00
Codec,
2021-01-10 23:59:11 +01:00
codecForNumber,
2021-03-17 17:56:37 +01:00
} from "./codec.js";
2019-12-16 16:59:09 +01:00
import {
AmountString,
Base32String,
EddsaSignatureString,
EddsaPublicKeyString,
CoinPublicKeyString,
} from "./talerTypes";
2021-03-17 17:56:37 +01:00
import { Timestamp, codecForTimestamp } from "./time.js";
2019-12-16 16:59:09 +01:00
export enum ReserveTransactionType {
2019-12-16 16:59:09 +01:00
Withdraw = "WITHDRAW",
Credit = "CREDIT",
Recoup = "RECOUP",
2019-12-16 16:59:09 +01:00
Closing = "CLOSING",
}
export interface ReserveWithdrawTransaction {
type: ReserveTransactionType.Withdraw;
/**
* Amount withdrawn.
*/
amount: AmountString;
/**
* Hash of the denomination public key of the coin.
*/
h_denom_pub: Base32String;
/**
* Hash of the blinded coin to be signed
*/
h_coin_envelope: Base32String;
/**
* Signature of 'TALER_WithdrawRequestPS' created with the reserves's
* private key.
*/
reserve_sig: EddsaSignatureString;
/**
* Fee that is charged for withdraw.
*/
withdraw_fee: AmountString;
}
export interface ReserveCreditTransaction {
type: ReserveTransactionType.Credit;
2019-12-16 16:59:09 +01:00
/**
* Amount withdrawn.
*/
amount: AmountString;
/**
* Sender account payto://-URL
*/
sender_account_url: string;
/**
* Transfer details uniquely identifying the transfer.
*/
2021-01-10 23:59:11 +01:00
wire_reference: number;
2019-12-16 16:59:09 +01:00
/**
* Timestamp of the incoming wire transfer.
*/
timestamp: Timestamp;
2019-12-16 16:59:09 +01:00
}
export interface ReserveClosingTransaction {
type: ReserveTransactionType.Closing;
/**
* Closing balance.
*/
amount: AmountString;
/**
* Closing fee charged by the exchange.
*/
closing_fee: AmountString;
/**
* Wire transfer subject.
*/
wtid: string;
/**
* Hash of the wire account into which the funds were returned to.
*/
h_wire: string;
/**
* This is a signature over a
* struct TALER_ReserveCloseConfirmationPS with purpose
* TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED.
*/
exchange_sig: EddsaSignatureString;
/**
* Public key used to create exchange_sig.
*/
exchange_pub: EddsaPublicKeyString;
/**
* Time when the reserve was closed.
*/
timestamp: Timestamp;
2019-12-16 16:59:09 +01:00
}
export interface ReserveRecoupTransaction {
type: ReserveTransactionType.Recoup;
2019-12-16 16:59:09 +01:00
/**
* Amount paid back.
*/
amount: AmountString;
/**
* This is a signature over
* a struct TALER_PaybackConfirmationPS with purpose
* TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK.
*/
exchange_sig: EddsaSignatureString;
/**
* Public key used to create exchange_sig.
*/
exchange_pub: EddsaPublicKeyString;
/**
* Time when the funds were paid back into the reserve.
*/
timestamp: Timestamp;
2019-12-16 16:59:09 +01:00
/**
* Public key of the coin that was paid back.
*/
coin_pub: CoinPublicKeyString;
}
/**
* Format of the exchange's transaction history for a reserve.
*/
export type ReserveTransaction =
| ReserveWithdrawTransaction
| ReserveCreditTransaction
2019-12-16 16:59:09 +01:00
| ReserveClosingTransaction
| ReserveRecoupTransaction;
2019-12-16 16:59:09 +01:00
2021-06-09 15:26:18 +02:00
export const codecForReserveWithdrawTransaction = (): Codec<ReserveWithdrawTransaction> =>
2020-08-12 12:32:58 +02:00
buildCodecForObject<ReserveWithdrawTransaction>()
.property("amount", codecForString())
.property("h_coin_envelope", codecForString())
.property("h_denom_pub", codecForString())
.property("reserve_sig", codecForString())
.property("type", codecForConstString(ReserveTransactionType.Withdraw))
.property("withdraw_fee", codecForString())
2020-04-07 10:07:32 +02:00
.build("ReserveWithdrawTransaction");
2021-06-09 15:26:18 +02:00
export const codecForReserveCreditTransaction = (): Codec<ReserveCreditTransaction> =>
2020-08-12 12:32:58 +02:00
buildCodecForObject<ReserveCreditTransaction>()
.property("amount", codecForString())
.property("sender_account_url", codecForString())
2020-04-07 10:07:32 +02:00
.property("timestamp", codecForTimestamp)
2021-01-10 23:59:11 +01:00
.property("wire_reference", codecForNumber())
2020-08-12 12:32:58 +02:00
.property("type", codecForConstString(ReserveTransactionType.Credit))
2020-04-07 10:07:32 +02:00
.build("ReserveCreditTransaction");
2021-06-09 15:26:18 +02:00
export const codecForReserveClosingTransaction = (): Codec<ReserveClosingTransaction> =>
2020-08-12 12:32:58 +02:00
buildCodecForObject<ReserveClosingTransaction>()
.property("amount", codecForString())
.property("closing_fee", codecForString())
.property("exchange_pub", codecForString())
.property("exchange_sig", codecForString())
.property("h_wire", codecForString())
2020-04-07 10:07:32 +02:00
.property("timestamp", codecForTimestamp)
2020-08-12 12:32:58 +02:00
.property("type", codecForConstString(ReserveTransactionType.Closing))
.property("wtid", codecForString())
2020-04-07 10:07:32 +02:00
.build("ReserveClosingTransaction");
2021-06-09 15:26:18 +02:00
export const codecForReserveRecoupTransaction = (): Codec<ReserveRecoupTransaction> =>
2020-08-12 12:32:58 +02:00
buildCodecForObject<ReserveRecoupTransaction>()
.property("amount", codecForString())
.property("coin_pub", codecForString())
.property("exchange_pub", codecForString())
.property("exchange_sig", codecForString())
2020-04-07 10:07:32 +02:00
.property("timestamp", codecForTimestamp)
2020-08-12 12:32:58 +02:00
.property("type", codecForConstString(ReserveTransactionType.Recoup))
2020-04-07 10:07:32 +02:00
.build("ReserveRecoupTransaction");
2019-12-16 16:59:09 +01:00
2020-04-06 20:02:01 +02:00
export const codecForReserveTransaction = (): Codec<ReserveTransaction> =>
2020-08-12 12:32:58 +02:00
buildCodecForUnion<ReserveTransaction>()
2020-04-07 10:07:32 +02:00
.discriminateOn("type")
.alternative(
ReserveTransactionType.Withdraw,
codecForReserveWithdrawTransaction(),
)
.alternative(
ReserveTransactionType.Closing,
codecForReserveClosingTransaction(),
)
.alternative(
ReserveTransactionType.Recoup,
codecForReserveRecoupTransaction(),
)
.alternative(
ReserveTransactionType.Credit,
codecForReserveCreditTransaction(),
)
.build<ReserveTransaction>("ReserveTransaction");