make tipping work with latest merchant protocol

This commit is contained in:
Florian Dold 2022-01-24 20:51:44 +01:00
parent ee492b2552
commit 171d070a83
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 19 additions and 3 deletions

View File

@ -1654,3 +1654,14 @@ export enum ExchangeProtocolVersion {
V9 = 9, V9 = 9,
V12 = 12, V12 = 12,
} }
export enum MerchantProtocolVersion {
/**
* Legacy version that is still supported.
*/
V1 = 1,
/**
* Current version supported by the wallet.
*/
V3 = 3,
}

View File

@ -33,6 +33,7 @@ import {
DenomKeyType, DenomKeyType,
BlindedDenominationSignature, BlindedDenominationSignature,
codecForMerchantTipResponseV2, codecForMerchantTipResponseV2,
MerchantProtocolVersion,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { DerivedTipPlanchet } from "../crypto/cryptoTypes.js"; import { DerivedTipPlanchet } from "../crypto/cryptoTypes.js";
import { import {
@ -314,13 +315,15 @@ async function processTipImpl(
let blindedSigs: BlindedDenominationSignature[] = []; let blindedSigs: BlindedDenominationSignature[] = [];
if (merchantInfo.protocolVersionCurrent === 2) { if (merchantInfo.protocolVersionCurrent === MerchantProtocolVersion.V3) {
const response = await readSuccessResponseJsonOrThrow( const response = await readSuccessResponseJsonOrThrow(
merchantResp, merchantResp,
codecForMerchantTipResponseV2(), codecForMerchantTipResponseV2(),
); );
blindedSigs = response.blind_sigs.map((x) => x.blind_sig); blindedSigs = response.blind_sigs.map((x) => x.blind_sig);
} else if (merchantInfo.protocolVersionCurrent === 1) { } else if (
merchantInfo.protocolVersionCurrent === MerchantProtocolVersion.V1
) {
const response = await readSuccessResponseJsonOrThrow( const response = await readSuccessResponseJsonOrThrow(
merchantResp, merchantResp,
codecForMerchantTipResponseV1(), codecForMerchantTipResponseV1(),
@ -330,7 +333,9 @@ async function processTipImpl(
blinded_rsa_signature: x.blind_sig, blinded_rsa_signature: x.blind_sig,
})); }));
} else { } else {
throw Error("unsupported merchant protocol version"); throw Error(
`unsupported merchant protocol version (${merchantInfo.protocolVersionCurrent})`,
);
} }
if (blindedSigs.length !== planchets.length) { if (blindedSigs.length !== planchets.length) {