From a05e891d6e1468fdd99f710301e286857a46aea3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 11 Jan 2022 12:48:32 +0100 Subject: towards new recoup API --- packages/taler-util/src/talerTypes.ts | 310 +++++++++++++++++++--------------- 1 file changed, 174 insertions(+), 136 deletions(-) (limited to 'packages/taler-util/src/talerTypes.ts') diff --git a/packages/taler-util/src/talerTypes.ts b/packages/taler-util/src/talerTypes.ts index e7d8a8c18..5f72e08ce 100644 --- a/packages/taler-util/src/talerTypes.ts +++ b/packages/taler-util/src/talerTypes.ts @@ -46,7 +46,7 @@ import { Duration, codecForDuration, } from "./time.js"; -import { codecForAmountString } from "./amounts.js"; +import { Amounts, codecForAmountString } from "./amounts.js"; /** * Denomination as found in the /keys response from the exchange. @@ -149,9 +149,6 @@ export class ExchangeAuditor { denomination_keys: AuditorDenomSig[]; } -/** - * Request that we send to the exchange to get a payback. - */ export interface RecoupRequest { /** * Hashed enomination public key of the coin we want to get @@ -161,31 +158,57 @@ export interface RecoupRequest { /** * Signature over the coin public key by the denomination. - * + * * The string variant is for the legacy exchange protocol. */ denom_sig: UnblindedSignature | string; /** - * Coin public key of the coin we want to refund. + * Blinding key that was used during withdraw, + * used to prove that we were actually withdrawing the coin. */ - coin_pub: string; + coin_blind_key_secret: string; /** - * Blinding key that was used during withdraw, - * used to prove that we were actually withdrawing the coin. + * Signature of TALER_RecoupRequestPS created with the coin's private key. + */ + coin_sig: string; + + /** + * Amount being recouped. + */ + amount: AmountString; +} + +export interface RecoupRefreshRequest { + /** + * Hashed enomination public key of the coin we want to get + * paid back. + */ + denom_pub_hash: string; + + /** + * Signature over the coin public key by the denomination. + * + * The string variant is for the legacy exchange protocol. + */ + denom_sig: UnblindedSignature | string; + + /** + * Coin's blinding factor. */ coin_blind_key_secret: string; /** - * Signature made by the coin, authorizing the payback. + * Signature of TALER_RecoupRefreshRequestPS created with + * the coin's private key. */ coin_sig: string; /** - * Was the coin refreshed (and thus the recoup should go to the old coin)? + * Amount being recouped. */ - refreshed: boolean; + amount: AmountString; } /** @@ -1131,10 +1154,11 @@ export const codecForLegacyRsaDenominationPubKey = () => .property("rsa_public_key", codecForString()) .build("LegacyRsaDenominationPubKey"); -export const codecForBankWithdrawalOperationPostResponse = (): Codec => - buildCodecForObject() - .property("transfer_done", codecForBoolean()) - .build("BankWithdrawalOperationPostResponse"); +export const codecForBankWithdrawalOperationPostResponse = + (): Codec => + buildCodecForObject() + .property("transfer_done", codecForBoolean()) + .build("BankWithdrawalOperationPostResponse"); export type AmountString = string; export type Base32String = string; @@ -1213,8 +1237,8 @@ export const codecForTax = (): Codec => .property("tax", codecForString()) .build("Tax"); -export const codecForInternationalizedString = (): Codec => - codecForMap(codecForString()); +export const codecForInternationalizedString = + (): Codec => codecForMap(codecForString()); export const codecForProduct = (): Codec => buildCodecForObject() @@ -1262,30 +1286,33 @@ export const codecForContractTerms = (): Codec => .property("extra", codecForAny()) .build("ContractTerms"); -export const codecForMerchantRefundPermission = (): Codec => - buildCodecForObject() - .property("refund_amount", codecForAmountString()) - .property("refund_fee", codecForAmountString()) - .property("coin_pub", codecForString()) - .property("rtransaction_id", codecForNumber()) - .property("exchange_http_status", codecForNumber()) - .property("exchange_code", codecOptional(codecForNumber())) - .property("exchange_reply", codecOptional(codecForAny())) - .property("exchange_sig", codecOptional(codecForString())) - .property("exchange_pub", codecOptional(codecForString())) - .build("MerchantRefundPermission"); - -export const codecForMerchantRefundResponse = (): Codec => - buildCodecForObject() - .property("merchant_pub", codecForString()) - .property("h_contract_terms", codecForString()) - .property("refunds", codecForList(codecForMerchantRefundPermission())) - .build("MerchantRefundResponse"); - -export const codecForMerchantBlindSigWrapperV1 = (): Codec => - buildCodecForObject() - .property("blind_sig", codecForString()) - .build("BlindSigWrapper"); +export const codecForMerchantRefundPermission = + (): Codec => + buildCodecForObject() + .property("refund_amount", codecForAmountString()) + .property("refund_fee", codecForAmountString()) + .property("coin_pub", codecForString()) + .property("rtransaction_id", codecForNumber()) + .property("exchange_http_status", codecForNumber()) + .property("exchange_code", codecOptional(codecForNumber())) + .property("exchange_reply", codecOptional(codecForAny())) + .property("exchange_sig", codecOptional(codecForString())) + .property("exchange_pub", codecOptional(codecForString())) + .build("MerchantRefundPermission"); + +export const codecForMerchantRefundResponse = + (): Codec => + buildCodecForObject() + .property("merchant_pub", codecForString()) + .property("h_contract_terms", codecForString()) + .property("refunds", codecForList(codecForMerchantRefundPermission())) + .build("MerchantRefundResponse"); + +export const codecForMerchantBlindSigWrapperV1 = + (): Codec => + buildCodecForObject() + .property("blind_sig", codecForString()) + .build("BlindSigWrapper"); export const codecForMerchantTipResponseV1 = (): Codec => buildCodecForObject() @@ -1365,17 +1392,18 @@ export const codecForCheckPaymentResponse = (): Codec => .property("contract_url", codecOptional(codecForString())) .build("CheckPaymentResponse"); -export const codecForWithdrawOperationStatusResponse = (): Codec => - buildCodecForObject() - .property("selection_done", codecForBoolean()) - .property("transfer_done", codecForBoolean()) - .property("aborted", codecForBoolean()) - .property("amount", codecForString()) - .property("sender_wire", codecOptional(codecForString())) - .property("suggested_exchange", codecOptional(codecForString())) - .property("confirm_transfer_url", codecOptional(codecForString())) - .property("wire_types", codecForList(codecForString())) - .build("WithdrawOperationStatusResponse"); +export const codecForWithdrawOperationStatusResponse = + (): Codec => + buildCodecForObject() + .property("selection_done", codecForBoolean()) + .property("transfer_done", codecForBoolean()) + .property("aborted", codecForBoolean()) + .property("amount", codecForString()) + .property("sender_wire", codecOptional(codecForString())) + .property("suggested_exchange", codecOptional(codecForString())) + .property("confirm_transfer_url", codecOptional(codecForString())) + .property("wire_types", codecForList(codecForString())) + .build("WithdrawOperationStatusResponse"); export const codecForTipPickupGetResponse = (): Codec => buildCodecForObject() @@ -1419,60 +1447,67 @@ export const codecForExchangeRevealItem = (): Codec => ) .build("ExchangeRevealItem"); -export const codecForExchangeRevealResponse = (): Codec => - buildCodecForObject() - .property("ev_sigs", codecForList(codecForExchangeRevealItem())) - .build("ExchangeRevealResponse"); - -export const codecForMerchantCoinRefundSuccessStatus = (): Codec => - buildCodecForObject() - .property("type", codecForConstString("success")) - .property("coin_pub", codecForString()) - .property("exchange_status", codecForConstNumber(200)) - .property("exchange_sig", codecForString()) - .property("rtransaction_id", codecForNumber()) - .property("refund_amount", codecForString()) - .property("exchange_pub", codecForString()) - .property("execution_time", codecForTimestamp) - .build("MerchantCoinRefundSuccessStatus"); - -export const codecForMerchantCoinRefundFailureStatus = (): Codec => - buildCodecForObject() - .property("type", codecForConstString("failure")) - .property("coin_pub", codecForString()) - .property("exchange_status", codecForNumber()) - .property("rtransaction_id", codecForNumber()) - .property("refund_amount", codecForString()) - .property("exchange_code", codecOptional(codecForNumber())) - .property("exchange_reply", codecOptional(codecForAny())) - .property("execution_time", codecForTimestamp) - .build("MerchantCoinRefundFailureStatus"); - -export const codecForMerchantCoinRefundStatus = (): Codec => - buildCodecForUnion() - .discriminateOn("type") - .alternative("success", codecForMerchantCoinRefundSuccessStatus()) - .alternative("failure", codecForMerchantCoinRefundFailureStatus()) - .build("MerchantCoinRefundStatus"); - -export const codecForMerchantOrderStatusPaid = (): Codec => - buildCodecForObject() - .property("refund_amount", codecForString()) - .property("refunded", codecForBoolean()) - .build("MerchantOrderStatusPaid"); - -export const codecForMerchantOrderRefundPickupResponse = (): Codec => - buildCodecForObject() - .property("merchant_pub", codecForString()) - .property("refund_amount", codecForString()) - .property("refunds", codecForList(codecForMerchantCoinRefundStatus())) - .build("MerchantOrderRefundPickupResponse"); - -export const codecForMerchantOrderStatusUnpaid = (): Codec => - buildCodecForObject() - .property("taler_pay_uri", codecForString()) - .property("already_paid_order_id", codecOptional(codecForString())) - .build("MerchantOrderStatusUnpaid"); +export const codecForExchangeRevealResponse = + (): Codec => + buildCodecForObject() + .property("ev_sigs", codecForList(codecForExchangeRevealItem())) + .build("ExchangeRevealResponse"); + +export const codecForMerchantCoinRefundSuccessStatus = + (): Codec => + buildCodecForObject() + .property("type", codecForConstString("success")) + .property("coin_pub", codecForString()) + .property("exchange_status", codecForConstNumber(200)) + .property("exchange_sig", codecForString()) + .property("rtransaction_id", codecForNumber()) + .property("refund_amount", codecForString()) + .property("exchange_pub", codecForString()) + .property("execution_time", codecForTimestamp) + .build("MerchantCoinRefundSuccessStatus"); + +export const codecForMerchantCoinRefundFailureStatus = + (): Codec => + buildCodecForObject() + .property("type", codecForConstString("failure")) + .property("coin_pub", codecForString()) + .property("exchange_status", codecForNumber()) + .property("rtransaction_id", codecForNumber()) + .property("refund_amount", codecForString()) + .property("exchange_code", codecOptional(codecForNumber())) + .property("exchange_reply", codecOptional(codecForAny())) + .property("execution_time", codecForTimestamp) + .build("MerchantCoinRefundFailureStatus"); + +export const codecForMerchantCoinRefundStatus = + (): Codec => + buildCodecForUnion() + .discriminateOn("type") + .alternative("success", codecForMerchantCoinRefundSuccessStatus()) + .alternative("failure", codecForMerchantCoinRefundFailureStatus()) + .build("MerchantCoinRefundStatus"); + +export const codecForMerchantOrderStatusPaid = + (): Codec => + buildCodecForObject() + .property("refund_amount", codecForString()) + .property("refunded", codecForBoolean()) + .build("MerchantOrderStatusPaid"); + +export const codecForMerchantOrderRefundPickupResponse = + (): Codec => + buildCodecForObject() + .property("merchant_pub", codecForString()) + .property("refund_amount", codecForString()) + .property("refunds", codecForList(codecForMerchantCoinRefundStatus())) + .build("MerchantOrderRefundPickupResponse"); + +export const codecForMerchantOrderStatusUnpaid = + (): Codec => + buildCodecForObject() + .property("taler_pay_uri", codecForString()) + .property("already_paid_order_id", codecOptional(codecForString())) + .build("MerchantOrderStatusUnpaid"); export interface AbortRequest { // hash of the order's contract terms (this is used to authenticate the @@ -1550,28 +1585,31 @@ export interface MerchantAbortPayRefundSuccessStatus { exchange_pub: string; } -export const codecForMerchantAbortPayRefundSuccessStatus = (): Codec => - buildCodecForObject() - .property("exchange_pub", codecForString()) - .property("exchange_sig", codecForString()) - .property("exchange_status", codecForConstNumber(200)) - .property("type", codecForConstString("success")) - .build("MerchantAbortPayRefundSuccessStatus"); - -export const codecForMerchantAbortPayRefundFailureStatus = (): Codec => - buildCodecForObject() - .property("exchange_code", codecForNumber()) - .property("exchange_reply", codecForAny()) - .property("exchange_status", codecForNumber()) - .property("type", codecForConstString("failure")) - .build("MerchantAbortPayRefundFailureStatus"); - -export const codecForMerchantAbortPayRefundStatus = (): Codec => - buildCodecForUnion() - .discriminateOn("type") - .alternative("success", codecForMerchantAbortPayRefundSuccessStatus()) - .alternative("failure", codecForMerchantAbortPayRefundFailureStatus()) - .build("MerchantAbortPayRefundStatus"); +export const codecForMerchantAbortPayRefundSuccessStatus = + (): Codec => + buildCodecForObject() + .property("exchange_pub", codecForString()) + .property("exchange_sig", codecForString()) + .property("exchange_status", codecForConstNumber(200)) + .property("type", codecForConstString("success")) + .build("MerchantAbortPayRefundSuccessStatus"); + +export const codecForMerchantAbortPayRefundFailureStatus = + (): Codec => + buildCodecForObject() + .property("exchange_code", codecForNumber()) + .property("exchange_reply", codecForAny()) + .property("exchange_status", codecForNumber()) + .property("type", codecForConstString("failure")) + .build("MerchantAbortPayRefundFailureStatus"); + +export const codecForMerchantAbortPayRefundStatus = + (): Codec => + buildCodecForUnion() + .discriminateOn("type") + .alternative("success", codecForMerchantAbortPayRefundSuccessStatus()) + .alternative("failure", codecForMerchantAbortPayRefundFailureStatus()) + .build("MerchantAbortPayRefundStatus"); export interface TalerConfigResponse { name: string; @@ -1614,13 +1652,13 @@ export interface MerchantConfigResponse { version: string; } -export const codecForMerchantConfigResponse = (): Codec => - buildCodecForObject() - .property("currency", codecForString()) - .property("name", codecForString()) - .property("version", codecForString()) - .build("MerchantConfigResponse"); - +export const codecForMerchantConfigResponse = + (): Codec => + buildCodecForObject() + .property("currency", codecForString()) + .property("name", codecForString()) + .property("version", codecForString()) + .build("MerchantConfigResponse"); export enum ExchangeProtocolVersion { V9 = 9, -- cgit v1.2.3