From 851ac5602cea0beb7b3e29dc9a95c2093a0ed906 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 May 2021 13:14:47 +0200 Subject: add UIDs for deletion tombstones to auditor/exchange trust management --- .../taler-wallet-core/src/operations/currencies.ts | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 packages/taler-wallet-core/src/operations/currencies.ts (limited to 'packages/taler-wallet-core/src/operations/currencies.ts') diff --git a/packages/taler-wallet-core/src/operations/currencies.ts b/packages/taler-wallet-core/src/operations/currencies.ts new file mode 100644 index 000000000..1af30dfb5 --- /dev/null +++ b/packages/taler-wallet-core/src/operations/currencies.ts @@ -0,0 +1,68 @@ +/* + This file is part of GNU Taler + (C) 2021 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** + * Imports. + */ +import { ExchangeRecord, Stores } from "../db.js"; +import { Logger } from "../index.js"; +import { InternalWalletState } from "./state.js"; + +const logger = new Logger("currencies.ts"); + +export interface TrustInfo { + isTrusted: boolean; + isAudited: boolean; +} + +/** + * Check if and how an exchange is trusted and/or audited. + */ +export async function getExchangeTrust( + ws: InternalWalletState, + exchangeInfo: ExchangeRecord, +): Promise { + let isTrusted = false; + let isAudited = false; + const exchangeDetails = exchangeInfo.details; + if (!exchangeDetails) { + throw Error(`exchange ${exchangeInfo.baseUrl} details not available`); + } + const exchangeTrustRecord = await ws.db.getIndexed( + Stores.exchangeTrustStore.exchangeMasterPubIndex, + exchangeDetails.masterPublicKey, + ); + if ( + exchangeTrustRecord && + exchangeTrustRecord.uids.length > 0 && + exchangeTrustRecord.currency === exchangeDetails.currency + ) { + isTrusted = true; + } + + for (const auditor of exchangeDetails.auditors) { + const auditorTrustRecord = await ws.db.getIndexed( + Stores.auditorTrustStore.auditorPubIndex, + auditor.auditor_pub, + ); + if (auditorTrustRecord && auditorTrustRecord.uids.length > 0) { + isAudited = true; + break; + } + } + + return { isTrusted, isAudited }; +} -- cgit v1.2.3