taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 7ad9477b5b5410a1f29ff011f12c4d0108546b59
parent a5e2deeffd815dbc9b7eb3358b469e34090aa9a5
Author: Florian Dold <florian@dold.me>
Date:   Wed, 15 Jul 2026 15:02:33 +0200

fix parsing of precise timestamps

Diffstat:
Mpackages/taler-util/src/time.ts | 20+++++++++++++++-----
Mpackages/taler-util/src/types-taler-merchant.ts | 6++----
2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts @@ -760,14 +760,24 @@ export const codecForTimestamp: Codec<TalerProtocolTimestamp> = { export const codecForPreciseTimestamp: Codec<TalerPreciseTimestamp> = { decode(x: any, c?: Context): TalerPreciseTimestamp { - const t_ms = x.t_ms; - if (typeof t_ms === "string") { - if (t_ms === "never") { + const t_s = x.t_s; + if (typeof t_s === "string") { + if (t_s === "never") { return { t_s: "never" }; } - } else if (typeof t_ms === "number") { - return { t_s: Math.floor(t_ms / 1000) }; + throw Error(`expected precise timestamp at ${renderContext(c)}`); + } + if (typeof t_s === "number") { + const off_us = x.off_us; + if (off_us === undefined) { + return { t_s }; + } + if (typeof off_us === "number") { + return { t_s, off_us }; + } + throw Error(`expected precise timestamp at ${renderContext(c)}`); } + throw Error(`expected precise timestamp at ${renderContext(c)}`); }, }; diff --git a/packages/taler-util/src/types-taler-merchant.ts b/packages/taler-util/src/types-taler-merchant.ts @@ -35,7 +35,6 @@ import { ExchangeWireAccount, ObjectCodec, PaytoString, - TalerPreciseTimestamp, UnblindedDenominationSignature, assertUnreachable, buildCodecForUnion, @@ -46,7 +45,6 @@ import { codecForExchangeWireAccount, codecForMap, codecForPaytoString, - codecForPreciseTimestamp, codecForStringURL, codecForTalerUriString, codecOptionalDefault, @@ -4123,7 +4121,7 @@ export interface OrderOutputToken { // desired validity period should be in the future (like selling // a subscription for the next month). Optional. If not given, // the validity is supposed to be "now" (time of order creation). - valid_at?: TalerPreciseTimestamp; + valid_at?: TalerProtocolTimestamp; } export interface OrderOutputTaxReceipt { @@ -5098,7 +5096,7 @@ export const codecForOrderOutputToken = (): Codec<OrderOutputToken> => .property("type", codecForConstString(OrderOutputType.Token)) .property("token_family_slug", codecForString()) .property("count", codecOptional(codecForNumber())) - .property("valid_at", codecOptional(codecForPreciseTimestamp)) + .property("valid_at", codecOptional(codecForTimestamp)) .build("TalerMerchantApi.OrderOutputToken"); export const codecForOrderOutputTaxReceipt = (): Codec<OrderOutputTaxReceipt> =>