From 26ee8e3c717701be9170d45da94c46ae850e1f21 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 24 Jan 2022 21:14:21 +0100 Subject: fix exchange-timetravel test case with latest exchange version --- packages/taler-util/src/talerTypes.ts | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (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 2f2576d82..37350c661 100644 --- a/packages/taler-util/src/talerTypes.ts +++ b/packages/taler-util/src/talerTypes.ts @@ -47,6 +47,7 @@ import { codecForDuration, } from "./time.js"; import { Amounts, codecForAmountString } from "./amounts.js"; +import { strcmp } from "./helpers.js"; /** * Denomination as found in the /keys response from the exchange. @@ -1125,6 +1126,47 @@ export interface CsDenominationPubKey { // FIXME: finish definition } +export namespace DenominationPubKey { + export function cmp( + p1: DenominationPubKey, + p2: DenominationPubKey, + ): -1 | 0 | 1 { + if (p1.cipher < p2.cipher) { + return -1; + } else if (p1.cipher > p2.cipher) { + return +1; + } + if ( + p1.cipher === DenomKeyType.LegacyRsa && + p2.cipher === DenomKeyType.LegacyRsa + ) { + return strcmp(p1.rsa_public_key, p2.rsa_public_key); + } else if ( + p1.cipher === DenomKeyType.Rsa && + p2.cipher === DenomKeyType.Rsa + ) { + if ((p1.age_mask ?? 0) < (p2.age_mask ?? 0)) { + return -1; + } else if ((p1.age_mask ?? 0) > (p2.age_mask ?? 0)) { + return 1; + } + return strcmp(p1.rsa_public_key, p2.rsa_public_key); + } else { + throw Error("unsupported cipher"); + } + } + + export function lift(p1: DenominationPubKey | string): DenominationPubKey { + if (typeof p1 === "string") { + return { + cipher: DenomKeyType.LegacyRsa, + rsa_public_key: p1, + }; + } + return p1; + } +} + export const codecForDenominationPubKey = () => buildCodecForUnion() .discriminateOn("cipher") -- cgit v1.2.3