From b91caf977fad8da11e523ca3a39064dd86e04c64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 16 Sep 2022 16:20:47 +0200 Subject: wallet-core: support age restrictions in new coin selection --- packages/taler-wallet-core/src/db.ts | 55 ++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'packages/taler-wallet-core/src/db.ts') diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 760234941..6466edf5a 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -319,11 +319,6 @@ export interface DenominationRecord { * that includes this denomination. */ listIssueDate: TalerProtocolTimestamp; - - /** - * Number of fresh coins of this denomination that are available. - */ - freshCoinCount?: number; } export namespace DenominationRecord { @@ -546,6 +541,8 @@ export interface PlanchetRecord { coinEvHash: string; + maxAge: number; + ageCommitmentProof?: AgeCommitmentProof; } @@ -674,6 +671,8 @@ export interface CoinRecord { */ allocation?: CoinAllocation; + maxAge: number; + ageCommitmentProof?: AgeCommitmentProof; } @@ -1770,7 +1769,45 @@ export interface OperationAttemptLongpollResult { type: OperationAttemptResultType.Longpoll; } +/** + * Availability of coins of a given denomination (and age restriction!). + * + * We can't store this information with the denomination record, as one denomination + * can be withdrawn with multiple age restrictions. + */ +export interface CoinAvailabilityRecord { + currency: string; + amountVal: number; + amountFrac: number; + denomPubHash: string; + exchangeBaseUrl: string; + + /** + * Age restriction on the coin, or 0 for no age restriction (or + * denomination without age restriction support). + */ + maxAge: number; + + /** + * Number of fresh coins of this denomination that are available. + */ + freshCoinCount: number; +} + export const WalletStoresV1 = { + coinAvailability: describeStore( + "coinAvailability", + describeContents({ + keyPath: ["exchangeBaseUrl", "denomPubHash", "maxAge"], + }), + { + byExchangeAgeAvailability: describeIndex("byExchangeAgeAvailability", [ + "exchangeBaseUrl", + "maxAge", + "freshCoinCount", + ]), + }, + ), coins: describeStore( "coins", describeContents({ @@ -1779,10 +1816,10 @@ export const WalletStoresV1 = { { byBaseUrl: describeIndex("byBaseUrl", "exchangeBaseUrl"), byDenomPubHash: describeIndex("byDenomPubHash", "denomPubHash"), - byDenomPubHashAndStatus: describeIndex("byDenomPubHashAndStatus", [ - "denomPubHash", - "status", - ]), + byExchangeDenomPubHashAndAgeAndStatus: describeIndex( + "byExchangeDenomPubHashAndAgeAndStatus", + ["exchangeBaseUrl", "denomPubHash", "maxAge", "status"], + ), byCoinEvHash: describeIndex("byCoinEvHash", "coinEvHash"), }, ), -- cgit v1.2.3