From 71f9676fc9d80bccc7353487d8527af74d25a02c Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 28 Jun 2024 14:19:12 +0200 Subject: wallet-core: return currency specification from exchange --- packages/taler-util/src/taler-types.ts | 3 +++ packages/taler-util/src/taleruri.ts | 1 + packages/taler-util/src/wallet-types.ts | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) (limited to 'packages/taler-util') diff --git a/packages/taler-util/src/taler-types.ts b/packages/taler-util/src/taler-types.ts index 66f98ea9a..ac42ca278 100644 --- a/packages/taler-util/src/taler-types.ts +++ b/packages/taler-util/src/taler-types.ts @@ -723,6 +723,8 @@ export class ExchangeKeysJson { currency: string; + currency_specification?: CurrencySpecification; + /** * The exchange's master public key. */ @@ -1504,6 +1506,7 @@ export const codecForExchangeKeysJson = (): Codec => buildCodecForObject() .property("base_url", codecForString()) .property("currency", codecForString()) + .property("currency_specification", codecOptional(codecForCurrencySpecificiation())) .property("master_public_key", codecForString()) .property("auditors", codecForList(codecForAuditor())) .property("list_issue_date", codecForTimestamp) diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts index b22dc3c59..d3186d2f5 100644 --- a/packages/taler-util/src/taleruri.ts +++ b/packages/taler-util/src/taleruri.ts @@ -29,6 +29,7 @@ import { opFixedSuccess, opKnownTalerFailure } from "./operation.js"; import { TalerErrorCode } from "./taler-error-codes.js"; import { AmountString } from "./taler-types.js"; import { URL, URLSearchParams } from "./url.js"; + /** * A parsed taler URI. */ diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 2c92d9295..42c0148e7 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -558,11 +558,13 @@ export enum ScopeType { } export type ScopeInfoGlobal = { type: ScopeType.Global; currency: string }; + export type ScopeInfoExchange = { type: ScopeType.Exchange; currency: string; url: string; }; + export type ScopeInfoAuditor = { type: ScopeType.Auditor; currency: string; @@ -571,6 +573,22 @@ export type ScopeInfoAuditor = { export type ScopeInfo = ScopeInfoGlobal | ScopeInfoExchange | ScopeInfoAuditor; +/** + * Encode scope info as a string. + * + * Format must be stable as it's used in the database. + */ +export function stringifyScopeInfo(si: ScopeInfo): string { + switch (si.type) { + case ScopeType.Global: + return `taler-si:global/${si.currency}}`; + case ScopeType.Auditor: + return `taler-si:auditor/${si.currency}/${encodeURIComponent(si.url)}`; + case ScopeType.Exchange: + return `taler-si:exchange/${si.currency}/${encodeURIComponent(si.url)}`; + } +} + export interface BalancesResponse { balances: WalletBalance[]; } -- cgit v1.2.3