diff options
| author | Florian Dold <florian@dold.me> | 2021-05-20 13:14:47 +0200 |
|---|---|---|
| committer | Florian Dold <florian@dold.me> | 2021-05-20 13:15:11 +0200 |
| commit | 851ac5602cea0beb7b3e29dc9a95c2093a0ed906 (patch) | |
| tree | 294e00a40e752c52706b65c86807028ffc450938 /packages/taler-wallet-core/src/operations/currencies.ts | |
| parent | 0299e719ce4c97748090fa238cb5f68303fb4abf (diff) | |
add UIDs for deletion tombstones to auditor/exchange trust management
Diffstat (limited to 'packages/taler-wallet-core/src/operations/currencies.ts')
| -rw-r--r-- | packages/taler-wallet-core/src/operations/currencies.ts | 68 |
1 files changed, 68 insertions, 0 deletions
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 <http://www.gnu.org/licenses/> + */ + +/** + * 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<TrustInfo> { + 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 }; +} |
