From cd9c3a143bc1ad88ce77d53c212a90f60660069a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 6 Sep 2023 18:35:43 +0200 Subject: remove deprecated auditor trust management --- .../taler-wallet-core/src/operations/exchanges.ts | 51 ---------------------- 1 file changed, 51 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts') diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 311a71a6e..690bc3cec 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -972,54 +972,3 @@ export async function getExchangePaytoUri( )}`, ); } - -/** - * Check if and how an exchange is trusted and/or audited. - */ -export async function getExchangeTrust( - ws: InternalWalletState, - exchangeInfo: ExchangeEntryRecord, -): Promise { - let isTrusted = false; - let isAudited = false; - - return await ws.db - .mktx((x) => [ - x.exchanges, - x.exchangeDetails, - x.exchangeTrust, - x.auditorTrust, - ]) - .runReadOnly(async (tx) => { - const exchangeDetails = await getExchangeDetails( - tx, - exchangeInfo.baseUrl, - ); - - if (!exchangeDetails) { - throw Error(`exchange ${exchangeInfo.baseUrl} details not available`); - } - const exchangeTrustRecord = - await tx.exchangeTrust.indexes.byExchangeMasterPub.get( - exchangeDetails.masterPublicKey, - ); - if ( - exchangeTrustRecord && - exchangeTrustRecord.uids.length > 0 && - exchangeTrustRecord.currency === exchangeDetails.currency - ) { - isTrusted = true; - } - - for (const auditor of exchangeDetails.auditors) { - const auditorTrustRecord = - await tx.auditorTrust.indexes.byAuditorPub.get(auditor.auditor_pub); - if (auditorTrustRecord && auditorTrustRecord.uids.length > 0) { - isAudited = true; - break; - } - } - - return { isTrusted, isAudited }; - }); -} -- cgit v1.2.3 From 1fcb55c84dc541e64ebbb2d16156bab275ff16c4 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 6 Sep 2023 18:43:37 +0200 Subject: remove ToS storage --- packages/taler-util/src/wallet-types.ts | 17 ----- packages/taler-wallet-core/src/db.ts | 7 -- .../taler-wallet-core/src/operations/exchanges.ts | 45 ----------- .../taler-wallet-core/src/operations/withdraw.ts | 1 - packages/taler-wallet-core/src/wallet.ts | 86 +++------------------- .../src/cta/Withdraw/state.ts | 1 - 6 files changed, 10 insertions(+), 147 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts') diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 353fb900d..0d78b405a 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -1076,13 +1076,6 @@ export interface KnownBankAccounts { accounts: KnownBankAccountsInfo[]; } -export interface ExchangeTosStatusDetails { - acceptedVersion?: string; - currentVersion?: string; - contentType?: string; - content?: string; -} - /** * Wire fee for one wire method */ @@ -1253,7 +1246,6 @@ export interface ExchangeFullDetails { exchangeBaseUrl: string; currency: string; paytoUris: string[]; - tos: ExchangeTosStatusDetails; auditors: ExchangeAuditor[]; wireInfo: WireInfo; denomFees: DenomOperationMap; @@ -1317,14 +1309,6 @@ const codecForExchangeAuditor = (): Codec => .property("denomination_keys", codecForList(codecForAuditorDenomSig())) .build("codecForExchangeAuditor"); -const codecForExchangeTos = (): Codec => - buildCodecForObject() - .property("acceptedVersion", codecOptional(codecForString())) - .property("currentVersion", codecOptional(codecForString())) - .property("contentType", codecOptional(codecForString())) - .property("content", codecOptional(codecForString())) - .build("ExchangeTos"); - export const codecForFeeDescriptionPair = (): Codec => buildCodecForObject() .property("group", codecForString()) @@ -1357,7 +1341,6 @@ export const codecForExchangeFullDetails = (): Codec => .property("currency", codecForString()) .property("exchangeBaseUrl", codecForString()) .property("paytoUris", codecForList(codecForString())) - .property("tos", codecForExchangeTos()) .property("auditors", codecForList(codecForExchangeAuditor())) .property("wireInfo", codecForWireInfo()) .property("denomFees", codecForFeesByOperations()) diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 4c0a6168d..2c7673267 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -2382,13 +2382,6 @@ export const WalletStoresV1 = { byReservePub: describeIndex("byReservePub", "reservePub", {}), }, ), - exchangeTos: describeStore( - "exchangeTos", - describeContents({ - keyPath: ["exchangeBaseUrl", "etag"], - }), - {}, - ), config: describeStore( "config", describeContents({ keyPath: "key" }), diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 690bc3cec..13e89b16c 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -157,35 +157,6 @@ export async function getExchangeDetails( getExchangeDetails.makeContext = (db: DbAccess) => db.mktx((x) => [x.exchanges, x.exchangeDetails]); -/** - * Update the database based on the download of the terms of service. - */ -export async function updateExchangeTermsOfService( - ws: InternalWalletState, - exchangeBaseUrl: string, - tos: ExchangeTosDownloadResult, -): Promise { - await ws.db - .mktx((x) => [x.exchanges, x.exchangeTos, x.exchangeDetails]) - .runReadWrite(async (tx) => { - const d = await getExchangeDetails(tx, exchangeBaseUrl); - let tosRecord = await tx.exchangeTos.get([exchangeBaseUrl, tos.tosEtag]); - if (!tosRecord) { - tosRecord = { - etag: tos.tosEtag, - exchangeBaseUrl, - termsOfServiceContentType: tos.tosContentType, - termsOfServiceText: tos.tosText, - }; - await tx.exchangeTos.put(tosRecord); - } - if (d) { - d.tosCurrentEtag = tos.tosEtag; - await tx.exchangeDetails.put(d); - } - }); -} - /** * Mark a ToS version as accepted by the user. * @@ -740,7 +711,6 @@ export async function updateExchangeFromUrlHandler( const updated = await ws.db .mktx((x) => [ x.exchanges, - x.exchangeTos, x.exchangeDetails, x.exchangeSignKeys, x.denominations, @@ -801,21 +771,6 @@ export async function updateExchangeFromUrlHandler( const drRowId = await tx.exchangeDetails.put(newDetails); checkDbInvariant(typeof drRowId.key === "number"); - let tosRecord = await tx.exchangeTos.get([ - exchangeBaseUrl, - tosDownload.tosEtag, - ]); - - if (!tosRecord || tosRecord.etag !== existingTosAccepted?.etag) { - tosRecord = { - etag: tosDownload.tosEtag, - exchangeBaseUrl, - termsOfServiceContentType: tosDownload.tosContentType, - termsOfServiceText: tosDownload.tosText, - }; - await tx.exchangeTos.put(tosRecord); - } - for (const sk of keysInfo.signingKeys) { // FIXME: validate signing keys before inserting them await tx.exchangeSignKeys.put({ diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 2b76613e7..b2b25144d 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -1856,7 +1856,6 @@ export async function getWithdrawalDetailsForUri( .mktx((x) => [ x.exchanges, x.exchangeDetails, - x.exchangeTos, x.denominations, x.operationRetries, ]) diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 7a1bd5a4f..cb82a3a43 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -34,7 +34,6 @@ import { Duration, ExchangeDetailedResponse, ExchangeListItem, - ExchangeTosStatusDetails, ExchangesListResponse, FeeDescription, GetExchangeTosResult, @@ -202,7 +201,6 @@ import { provideExchangeRecordInTx, updateExchangeFromUrl, updateExchangeFromUrlHandler, - updateExchangeTermsOfService, } from "./operations/exchanges.js"; import { getMerchantInfo } from "./operations/merchants.js"; import { @@ -557,33 +555,6 @@ async function getExchangeTos( ): Promise { // FIXME: download ToS in acceptable format if passed! const { exchangeDetails } = await updateExchangeFromUrl(ws, exchangeBaseUrl); - const tosDetails = await ws.db - .mktx((x) => [x.exchangeTos]) - .runReadOnly(async (tx) => { - return await getExchangeTosStatusDetails(tx, exchangeDetails); - }); - const content = tosDetails.content; - const currentEtag = tosDetails.currentVersion; - const contentType = tosDetails.contentType; - if ( - content === undefined || - currentEtag === undefined || - contentType === undefined - ) { - throw Error("exchange is in invalid state"); - } - if ( - acceptedFormat && - acceptedFormat.findIndex((f) => f === contentType) !== -1 - ) { - return { - acceptedEtag: exchangeDetails.tosAccepted?.etag, - currentEtag, - content, - contentType, - tosStatus: getExchangeTosStatus(exchangeDetails), - }; - } const tosDownload = await downloadTosFromAcceptedFormat( ws, @@ -592,17 +563,15 @@ async function getExchangeTos( acceptedFormat, ); - if (tosDownload.tosContentType === contentType) { - return { - acceptedEtag: exchangeDetails.tosAccepted?.etag, - currentEtag, - content, - contentType, - tosStatus: getExchangeTosStatus(exchangeDetails), - }; - } - - await updateExchangeTermsOfService(ws, exchangeBaseUrl, tosDownload); + await ws.db + .mktx((x) => [x.exchanges, x.exchangeDetails]) + .runReadWrite(async (tx) => { + const d = await getExchangeDetails(tx, exchangeBaseUrl); + if (d) { + d.tosCurrentEtag = tosDownload.tosEtag; + await tx.exchangeDetails.put(d); + } + }); return { acceptedEtag: exchangeDetails.tosAccepted?.etag, @@ -683,32 +652,6 @@ async function forgetKnownBankAccounts( return; } -async function getExchangeTosStatusDetails( - tx: GetReadOnlyAccess<{ exchangeTos: typeof WalletStoresV1.exchangeTos }>, - exchangeDetails: ExchangeDetailsRecord, -): Promise { - let exchangeTos = await tx.exchangeTos.get([ - exchangeDetails.exchangeBaseUrl, - exchangeDetails.tosCurrentEtag, - ]); - - if (!exchangeTos) { - exchangeTos = { - etag: "not-available", - termsOfServiceContentType: "text/plain", - termsOfServiceText: "terms of service unavailable", - exchangeBaseUrl: exchangeDetails.exchangeBaseUrl, - }; - } - - return { - acceptedVersion: exchangeDetails.tosAccepted?.etag, - content: exchangeTos.termsOfServiceText, - contentType: exchangeTos.termsOfServiceContentType, - currentVersion: exchangeTos.etag, - }; -} - async function getExchanges( ws: InternalWalletState, ): Promise { @@ -717,7 +660,6 @@ async function getExchanges( .mktx((x) => [ x.exchanges, x.exchangeDetails, - x.exchangeTos, x.denominations, x.operationRetries, ]) @@ -742,12 +684,7 @@ async function getExchangeDetailedInfo( ): Promise { //TODO: should we use the forceUpdate parameter? const exchange = await ws.db - .mktx((x) => [ - x.exchanges, - x.exchangeTos, - x.exchangeDetails, - x.denominations, - ]) + .mktx((x) => [x.exchanges, x.exchangeDetails, x.denominations]) .runReadOnly(async (tx) => { const ex = await tx.exchanges.get(exchangeBaseurl); const dp = ex?.detailsPointer; @@ -769,8 +706,6 @@ async function getExchangeDetailedInfo( return; } - const tos = await getExchangeTosStatusDetails(tx, exchangeDetails); - const denominations: DenominationInfo[] = denominationRecords.map((x) => DenominationRecord.toDenomInfo(x), ); @@ -779,7 +714,6 @@ async function getExchangeDetailedInfo( info: { exchangeBaseUrl: ex.baseUrl, currency, - tos, paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri), auditors: exchangeDetails.auditors, wireInfo: exchangeDetails.wireInfo, diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 72cabe5a4..a3855c2f4 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -23,7 +23,6 @@ import { ExchangeTosStatus, TalerError, parseWithdrawExchangeUri, - stringifyWithdrawUri, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; -- cgit v1.2.3 From 4898f50db777a68cd2ddd0c1e323ef55033f4af7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 8 Sep 2023 13:33:21 +0200 Subject: wallet-core: more DB cleanup --- packages/taler-util/src/transactions-types.ts | 17 ------ .../src/crypto/cryptoImplementation.ts | 6 +-- packages/taler-wallet-core/src/db.ts | 63 +++++++++------------- packages/taler-wallet-core/src/dbless.ts | 18 ++----- .../taler-wallet-core/src/operations/balance.ts | 18 ++----- .../taler-wallet-core/src/operations/common.ts | 27 +++++----- .../taler-wallet-core/src/operations/deposits.ts | 2 +- .../taler-wallet-core/src/operations/exchanges.ts | 3 +- .../src/operations/pay-merchant.ts | 4 +- .../src/operations/pay-peer-common.ts | 12 +---- .../taler-wallet-core/src/operations/refresh.ts | 12 +---- .../src/operations/transactions.ts | 1 - .../src/operations/withdraw.test.ts | 22 ++++---- .../taler-wallet-core/src/util/coinSelection.ts | 30 +++-------- .../src/util/instructedAmountConversion.ts | 2 +- packages/taler-wallet-core/src/wallet.ts | 22 ++------ 16 files changed, 77 insertions(+), 182 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts') diff --git a/packages/taler-util/src/transactions-types.ts b/packages/taler-util/src/transactions-types.ts index 6331bc731..304183ceb 100644 --- a/packages/taler-util/src/transactions-types.ts +++ b/packages/taler-util/src/transactions-types.ts @@ -527,22 +527,6 @@ export interface OrderShortInfo { */ summary_i18n?: InternationalizedString; - /** - * List of products that are part of the order - */ - products: Product[] | undefined; - - /** - * Time indicating when the order should be delivered. - * May be overwritten by individual products. - */ - delivery_date?: TalerProtocolTimestamp; - - /** - * Delivery location for (all!) products. - */ - delivery_location?: Location; - /** * URL of the fulfillment, given by the merchant */ @@ -724,7 +708,6 @@ export const codecForOrderShortInfo = (): Codec => .property("fulfillmentUrl", codecOptional(codecForString())) .property("merchant", codecForMerchantInfo()) .property("orderId", codecForString()) - .property("products", codecOptional(codecForList(codecForProduct()))) .property("summary", codecForString()) .property("summary_i18n", codecOptional(codecForInternationalizedString())) .build("OrderShortInfo"); diff --git a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts index c1a761fb6..35777e714 100644 --- a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts +++ b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts @@ -959,11 +959,7 @@ export const nativeCryptoR: TalerCryptoInterfaceR = { req: DenominationValidationRequest, ): Promise { const { masterPub, denom } = req; - const value: AmountJson = { - currency: denom.currency, - fraction: denom.amountFrac, - value: denom.amountVal, - }; + const value: AmountJson = Amounts.parseOrThrow(denom.value); const p = buildSigPS(TalerSignaturePurpose.MASTER_DENOMINATION_KEY_VALIDITY) .put(decodeCrock(masterPub)) .put(timestampRoundedToBuffer(denom.stampStart)) diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 3db7ae9b5..3a8109320 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -28,56 +28,53 @@ import { } from "@gnu-taler/idb-bridge"; import { AgeCommitmentProof, - AmountJson, AmountString, + Amounts, + AttentionInfo, + Codec, CoinEnvelope, + CoinPublicKeyString, CoinRefreshRequest, CoinStatus, - MerchantContractTerms, + DenomSelectionState, DenominationInfo, DenominationPubKey, - DenomSelectionState, EddsaPublicKeyString, EddsaSignatureString, ExchangeAuditor, ExchangeGlobalFees, + HashCodeString, InternationalizedString, - Location, + Logger, + MerchantContractTerms, MerchantInfo, PayCoinSelection, PeerContractTerms, - Product, RefreshReason, TalerErrorDetail, + TalerPreciseTimestamp, TalerProtocolDuration, TalerProtocolTimestamp, TransactionIdStr, UnblindedSignature, WireInfo, - HashCodeString, - Amounts, - AttentionInfo, - Logger, - CoinPublicKeyString, - TalerPreciseTimestamp, codecForAny, - Codec, } from "@gnu-taler/taler-util"; +import { RetryInfo, TaskIdentifiers } from "./operations/common.js"; import { DbAccess, DbReadOnlyTransaction, DbReadWriteTransaction, - describeContents, - describeIndex, - describeStore, GetReadWriteAccess, IndexDescriptor, - openDatabase, StoreDescriptor, StoreNames, StoreWithIndexes, + describeContents, + describeIndex, + describeStore, + openDatabase, } from "./util/query.js"; -import { RetryInfo, TaskIdentifiers } from "./operations/common.js"; /** * This file contains the database schema of the Taler wallet together @@ -109,6 +106,9 @@ import { RetryInfo, TaskIdentifiers } from "./operations/common.js"; store. - More object stores should have an "id" primary key, as this makes referencing less expensive. + - Coin selections should probably go into a separate object store. + - Some records should be split up into an extra "details" record + that we don't always need to iterate over. */ /** @@ -323,12 +323,14 @@ export interface DenomFees { * Denomination record as stored in the wallet's database. */ export interface DenominationRecord { + /** + * Currency of the denomination. + * + * Stored separately as we have an index on it. + */ currency: string; - // FIXME: Use binary encoding of amount instead? - amountVal: number; - - amountFrac: number; + value: AmountString; /** * The denomination public key. @@ -407,14 +409,6 @@ export interface DenominationRecord { } export namespace DenominationRecord { - export function getValue(d: DenominationRecord): AmountJson { - return { - currency: d.currency, - fraction: d.amountFrac, - value: d.amountVal, - }; - } - export function toDenomInfo(d: DenominationRecord): DenominationInfo { return { denomPub: d.denomPub, @@ -427,7 +421,7 @@ export namespace DenominationRecord { stampExpireLegal: d.stampExpireLegal, stampExpireWithdraw: d.stampExpireWithdraw, stampStart: d.stampStart, - value: Amounts.stringify(DenominationRecord.getValue(d)), + value: Amounts.stringify(d.value), exchangeBaseUrl: d.exchangeBaseUrl, }; } @@ -1056,9 +1050,6 @@ export interface AllowedExchangeInfo { * processing in the wallet. */ export interface WalletContractData { - products?: Product[]; - summaryI18n: { [lang_tag: string]: string } | undefined; - /** * Fulfillment URL, or the empty string if the order has no fulfillment URL. * @@ -1076,6 +1067,7 @@ export interface WalletContractData { orderId: string; merchantBaseUrl: string; summary: string; + summaryI18n: { [lang_tag: string]: string } | undefined; autoRefund: TalerProtocolDuration | undefined; maxWireFee: AmountString; wireFeeAmortization: number; @@ -1087,8 +1079,6 @@ export interface WalletContractData { wireInfoHash: string; maxDepositFee: AmountString; minimumAge?: number; - deliveryDate: TalerProtocolTimestamp | undefined; - deliveryLocation: Location | undefined; } export enum PurchaseStatus { @@ -2095,8 +2085,7 @@ export interface OperationRetryRecord { */ export interface CoinAvailabilityRecord { currency: string; - amountVal: number; - amountFrac: number; + value: AmountString; denomPubHash: string; exchangeBaseUrl: string; diff --git a/packages/taler-wallet-core/src/dbless.ts b/packages/taler-wallet-core/src/dbless.ts index 0aad477e4..11c6c0f74 100644 --- a/packages/taler-wallet-core/src/dbless.ts +++ b/packages/taler-wallet-core/src/dbless.ts @@ -159,11 +159,7 @@ export async function withdrawCoin(args: { reservePriv: reserveKeyPair.reservePriv, reservePub: reserveKeyPair.reservePub, secretSeed: encodeCrock(getRandomBytes(32)), - value: { - currency: denom.currency, - fraction: denom.amountFrac, - value: denom.amountVal, - }, + value: Amounts.parseOrThrow(denom.value), }); const reqBody: ExchangeWithdrawRequest = { @@ -211,11 +207,7 @@ export function findDenomOrThrow( ): DenominationRecord { const denomselAllowLate = options.denomselAllowLate ?? false; for (const d of exchangeInfo.keys.currentDenominations) { - const value: AmountJson = { - currency: d.currency, - fraction: d.amountFrac, - value: d.amountVal, - }; + const value: AmountJson = Amounts.parseOrThrow(d.value); if ( Amounts.cmp(value, amount) === 0 && isWithdrawableDenom(d, denomselAllowLate) @@ -303,11 +295,7 @@ export async function refreshCoin(req: { denomPub: x.denomPub, denomPubHash: x.denomPubHash, feeWithdraw: x.fees.feeWithdraw, - value: Amounts.stringify({ - currency: x.currency, - fraction: x.amountFrac, - value: x.amountVal, - }), + value: x.value, })), meltCoinMaxAge: oldCoin.maxAge, }); diff --git a/packages/taler-wallet-core/src/operations/balance.ts b/packages/taler-wallet-core/src/operations/balance.ts index 28aa5ac70..a20ded2af 100644 --- a/packages/taler-wallet-core/src/operations/balance.ts +++ b/packages/taler-wallet-core/src/operations/balance.ts @@ -133,11 +133,7 @@ export async function getBalancesInsideTransaction( const b = initBalance(ca.currency); const count = ca.visibleCoinCount ?? 0; for (let i = 0; i < count; i++) { - b.available = Amounts.add(b.available, { - currency: ca.currency, - fraction: ca.amountFrac, - value: ca.amountVal, - }).amount; + b.available = Amounts.add(b.available, ca.value).amount; } }); @@ -408,11 +404,7 @@ export async function getMerchantPaymentBalanceDetails( if (ca.currency != req.currency) { return; } - const singleCoinAmount: AmountJson = { - currency: ca.currency, - fraction: ca.amountFrac, - value: ca.amountVal, - }; + const singleCoinAmount: AmountJson = Amounts.parseOrThrow(ca.value); const coinAmount: AmountJson = Amounts.mult( singleCoinAmount, ca.freshCoinCount, @@ -530,11 +522,7 @@ export async function getPeerPaymentBalanceDetailsInTx( ) { return; } - const singleCoinAmount: AmountJson = { - currency: ca.currency, - fraction: ca.amountFrac, - value: ca.amountVal, - }; + const singleCoinAmount: AmountJson = Amounts.parseOrThrow(ca.value); const coinAmount: AmountJson = Amounts.mult( singleCoinAmount, ca.freshCoinCount, diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts index 680874dfa..50dd3dc5c 100644 --- a/packages/taler-wallet-core/src/operations/common.ts +++ b/packages/taler-wallet-core/src/operations/common.ts @@ -26,7 +26,6 @@ import { CoinRefreshRequest, CoinStatus, Duration, - ErrorInfoSummary, ExchangeEntryStatus, ExchangeListItem, ExchangeTosStatus, @@ -34,9 +33,11 @@ import { getErrorDetailFromException, j2s, Logger, + makeErrorDetail, NotificationType, OperationErrorInfo, RefreshReason, + TalerError, TalerErrorCode, TalerErrorDetail, TombstoneIdStr, @@ -44,32 +45,31 @@ import { TransactionType, WalletNotification, } from "@gnu-taler/taler-util"; +import { CryptoApiStoppedError } from "../crypto/workers/crypto-dispatcher.js"; import { - WalletStoresV1, + BackupProviderRecord, CoinRecord, + DepositGroupRecord, ExchangeDetailsRecord, + ExchangeEntryDbRecordStatus, + ExchangeEntryDbUpdateStatus, ExchangeEntryRecord, - BackupProviderRecord, - DepositGroupRecord, - PeerPullPaymentIncomingRecord, PeerPullCreditRecord, - PeerPushPaymentIncomingRecord, + PeerPullPaymentIncomingRecord, PeerPushDebitRecord, + PeerPushPaymentIncomingRecord, PurchaseRecord, RecoupGroupRecord, RefreshGroupRecord, RewardRecord, + WalletStoresV1, WithdrawalGroupRecord, - ExchangeEntryDbUpdateStatus, - ExchangeEntryDbRecordStatus, } from "../db.js"; -import { makeErrorDetail, TalerError } from "@gnu-taler/taler-util"; import { InternalWalletState } from "../internal-wallet-state.js"; -import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; -import { GetReadOnlyAccess, GetReadWriteAccess } from "../util/query.js"; -import { CryptoApiStoppedError } from "../crypto/workers/crypto-dispatcher.js"; import { PendingTaskType, TaskId } from "../pending-types.js"; import { assertUnreachable } from "../util/assertUnreachable.js"; +import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; +import { GetReadOnlyAccess, GetReadWriteAccess } from "../util/query.js"; import { constructTransactionIdentifier } from "./transactions.js"; const logger = new Logger("operations/common.ts"); @@ -144,8 +144,7 @@ export async function makeCoinAvailable( if (!car) { car = { maxAge: ageRestriction, - amountFrac: denom.amountFrac, - amountVal: denom.amountVal, + value: denom.value, currency: denom.currency, denomPubHash: denom.denomPubHash, exchangeBaseUrl: denom.exchangeBaseUrl, diff --git a/packages/taler-wallet-core/src/operations/deposits.ts b/packages/taler-wallet-core/src/operations/deposits.ts index 3d78e938b..8ea792d91 100644 --- a/packages/taler-wallet-core/src/operations/deposits.ts +++ b/packages/taler-wallet-core/src/operations/deposits.ts @@ -1539,7 +1539,7 @@ async function getTotalFeesForDepositAmount( .iter(coin.exchangeBaseUrl) .filter((x) => Amounts.isSameCurrency( - DenominationRecord.getValue(x), + x.value, pcs.coinContributions[i], ), ); diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 13e89b16c..43a08ed3b 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -443,8 +443,7 @@ async function downloadExchangeKeysInfo( exchangeMasterPub: exchangeKeysJsonUnchecked.master_public_key, isOffered: true, isRevoked: false, - amountFrac: value.fraction, - amountVal: value.value, + value: Amounts.stringify(value), currency: value.currency, stampExpireDeposit: denomIn.stamp_expire_deposit, stampExpireLegal: denomIn.stamp_expire_legal, diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index 1b3248f49..3a7208ab0 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -174,12 +174,12 @@ export async function getTotalPaymentCost( .iter(coin.exchangeBaseUrl) .filter((x) => Amounts.isSameCurrency( - DenominationRecord.getValue(x), + x.value, pcs.coinContributions[i], ), ); const amountLeft = Amounts.sub( - DenominationRecord.getValue(denom), + denom.value, pcs.coinContributions[i], ).amount; const refreshCost = getTotalRefreshCost( diff --git a/packages/taler-wallet-core/src/operations/pay-peer-common.ts b/packages/taler-wallet-core/src/operations/pay-peer-common.ts index 9e05e43d8..6d425289d 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer-common.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer-common.ts @@ -108,16 +108,8 @@ export async function getTotalPeerPaymentCost( } const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl .iter(coin.exchangeBaseUrl) - .filter((x) => - Amounts.isSameCurrency( - DenominationRecord.getValue(x), - pcs[i].contribution, - ), - ); - const amountLeft = Amounts.sub( - DenominationRecord.getValue(denom), - pcs[i].contribution, - ).amount; + .filter((x) => Amounts.isSameCurrency(x.value, pcs[i].contribution)); + const amountLeft = Amounts.sub(denom.value, pcs[i].contribution).amount; const refreshCost = getTotalRefreshCost( allDenoms, DenominationRecord.toDenomInfo(denom), diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 3c4ef207a..75adbc860 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -134,11 +134,7 @@ export function getTotalRefreshCost( const resultingAmount = Amounts.add( Amounts.zeroOfCurrency(withdrawAmount.currency), ...withdrawDenoms.selectedDenoms.map( - (d) => - Amounts.mult( - DenominationRecord.getValue(denomMap[d.denomPubHash]), - d.count, - ).amount, + (d) => Amounts.mult(denomMap[d.denomPubHash].value, d.count).amount, ), ).amount; const totalCost = Amounts.sub(amountLeft, resultingAmount).amount; @@ -1200,11 +1196,7 @@ export async function autoRefresh( if (AbsoluteTime.isExpired(executeThreshold)) { refreshCoins.push({ coinPub: coin.coinPub, - amount: Amounts.stringify({ - value: denom.amountVal, - fraction: denom.amountFrac, - currency: denom.currency, - }), + amount: denom.value, }); } else { const checkThreshold = getAutoRefreshCheckThreshold(denom); diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 9d5ca9f1a..7bdb9af5b 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -884,7 +884,6 @@ async function buildTransactionForPurchase( const info: OrderShortInfo = { merchant: contractData.merchant, orderId: contractData.orderId, - products: contractData.products, summary: contractData.summary, summary_i18n: contractData.summaryI18n, contractTermsHash: contractData.contractTermsHash, diff --git a/packages/taler-wallet-core/src/operations/withdraw.test.ts b/packages/taler-wallet-core/src/operations/withdraw.test.ts index 5a557b5de..2d9286610 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.test.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.test.ts @@ -78,8 +78,7 @@ test("withdrawal selection bug repro", (t) => { }, verificationStatus: DenominationVerificationStatus.Unverified, currency: "KUDOS", - amountFrac: 0, - amountVal: 1000, + value: "KUDOS:1000", listIssueDate: { t_s: 0 }, }, { @@ -133,8 +132,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }, verificationStatus: DenominationVerificationStatus.Unverified, - amountFrac: 0, - amountVal: 10, + value: "KUDOS:10", currency: "KUDOS", listIssueDate: { t_s: 0 }, }, @@ -188,8 +186,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }, verificationStatus: DenominationVerificationStatus.Unverified, - amountFrac: 0, - amountVal: 5, + value: "KUDOS:5", currency: "KUDOS", listIssueDate: { t_s: 0 }, }, @@ -244,8 +241,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }, verificationStatus: DenominationVerificationStatus.Unverified, - amountFrac: 0, - amountVal: 1, + value: "KUDOS:1", currency: "KUDOS", listIssueDate: { t_s: 0 }, }, @@ -299,8 +295,11 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }, verificationStatus: DenominationVerificationStatus.Unverified, - amountFrac: 10000000, - amountVal: 0, + value: Amounts.stringify({ + currency: "KUDOS", + fraction: 10000000, + value: 0, + }), currency: "KUDOS", listIssueDate: { t_s: 0 }, }, @@ -354,8 +353,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }, verificationStatus: DenominationVerificationStatus.Unverified, - amountFrac: 0, - amountVal: 2, + value: "KUDOS:2", currency: "KUDOS", listIssueDate: { t_s: 0 }, }, diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts index ce9fec186..ef2f85789 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.ts @@ -699,25 +699,17 @@ export function selectWithdrawalDenominations( let totalWithdrawCost = Amounts.zeroOfCurrency(amountAvailable.currency); denoms = denoms.filter((d) => isWithdrawableDenom(d, denomselAllowLate)); - denoms.sort((d1, d2) => - Amounts.cmp( - DenominationRecord.getValue(d2), - DenominationRecord.getValue(d1), - ), - ); + denoms.sort((d1, d2) => Amounts.cmp(d2.value, d1.value)); for (const d of denoms) { - const cost = Amounts.add( - DenominationRecord.getValue(d), - d.fees.feeWithdraw, - ).amount; + const cost = Amounts.add(d.value, d.fees.feeWithdraw).amount; const res = Amounts.divmod(remaining, cost); const count = res.quotient; remaining = Amounts.sub(remaining, Amounts.mult(cost, count).amount).amount; if (count > 0) { totalCoinValue = Amounts.add( totalCoinValue, - Amounts.mult(DenominationRecord.getValue(d), count).amount, + Amounts.mult(d.value, count).amount, ).amount; totalWithdrawCost = Amounts.add( totalWithdrawCost, @@ -766,30 +758,22 @@ export function selectForcedWithdrawalDenominations( let totalWithdrawCost = Amounts.zeroOfCurrency(amountAvailable.currency); denoms = denoms.filter((d) => isWithdrawableDenom(d, denomselAllowLate)); - denoms.sort((d1, d2) => - Amounts.cmp( - DenominationRecord.getValue(d2), - DenominationRecord.getValue(d1), - ), - ); + denoms.sort((d1, d2) => Amounts.cmp(d2.value, d1.value)); for (const fds of forcedDenomSel.denoms) { const count = fds.count; const denom = denoms.find((x) => { - return Amounts.cmp(DenominationRecord.getValue(x), fds.value) == 0; + return Amounts.cmp(x.value, fds.value) == 0; }); if (!denom) { throw Error( `unable to find denom for forced selection (value ${fds.value})`, ); } - const cost = Amounts.add( - DenominationRecord.getValue(denom), - denom.fees.feeWithdraw, - ).amount; + const cost = Amounts.add(denom.value, denom.fees.feeWithdraw).amount; totalCoinValue = Amounts.add( totalCoinValue, - Amounts.mult(DenominationRecord.getValue(denom), count).amount, + Amounts.mult(denom.value, count).amount, ).amount; totalWithdrawCost = Amounts.add( totalWithdrawCost, diff --git a/packages/taler-wallet-core/src/util/instructedAmountConversion.ts b/packages/taler-wallet-core/src/util/instructedAmountConversion.ts index bd02e7b22..54c08eee4 100644 --- a/packages/taler-wallet-core/src/util/instructedAmountConversion.ts +++ b/packages/taler-wallet-core/src/util/instructedAmountConversion.ts @@ -321,7 +321,7 @@ function buildCoinInfoFromDenom( AbsoluteTime.fromProtocolTimestamp(denom.stampExpireDeposit), ), totalAvailable: total, - value: DenominationRecord.getValue(denom), + value: Amounts.parseOrThrow(denom.value), maxAge, }; } diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 11fb3f739..1a60b148c 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -915,11 +915,7 @@ async function dumpCoins(ws: InternalWalletState): Promise { coin_pub: c.coinPub, denom_pub: denomInfo.denomPub, denom_pub_hash: c.denomPubHash, - denom_value: Amounts.stringify({ - value: denom.amountVal, - currency: denom.currency, - fraction: denom.amountFrac, - }), + denom_value: denom.value, exchange_base_url: c.exchangeBaseUrl, refresh_parent_coin_pub: refreshParentCoinPub, withdrawal_reserve_pub: withdrawalReservePub, @@ -1876,35 +1872,27 @@ class InternalWalletStateImpl implements InternalWalletState { return computeRefundTransactionState(rec); } case TransactionType.PeerPullCredit: - const rec = await tx.peerPullCredit.get( - parsedTxId.pursePub, - ); + const rec = await tx.peerPullCredit.get(parsedTxId.pursePub); if (!rec) { return undefined; } return computePeerPullCreditTransactionState(rec); case TransactionType.PeerPullDebit: { - const rec = await tx.peerPullDebit.get( - parsedTxId.peerPullDebitId, - ); + const rec = await tx.peerPullDebit.get(parsedTxId.peerPullDebitId); if (!rec) { return undefined; } return computePeerPullDebitTransactionState(rec); } case TransactionType.PeerPushCredit: { - const rec = await tx.peerPushCredit.get( - parsedTxId.peerPushCreditId, - ); + const rec = await tx.peerPushCredit.get(parsedTxId.peerPushCreditId); if (!rec) { return undefined; } return computePeerPushCreditTransactionState(rec); } case TransactionType.PeerPushDebit: { - const rec = await tx.peerPushDebit.get( - parsedTxId.pursePub, - ); + const rec = await tx.peerPushDebit.get(parsedTxId.pursePub); if (!rec) { return undefined; } -- cgit v1.2.3