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 --- .../taler-wallet-core/src/util/coinSelection.test.ts | 17 +++++++++++++---- packages/taler-wallet-core/src/util/coinSelection.ts | 1 + packages/taler-wallet-core/src/util/query.ts | 15 +++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) (limited to 'packages/taler-wallet-core/src/util') diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts index 3c6ad0d82..fe9672116 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.test.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts @@ -18,7 +18,12 @@ * Imports. */ import test from "ava"; -import { AmountJson, Amounts, DenomKeyType } from "@gnu-taler/taler-util"; +import { + AgeRestriction, + AmountJson, + Amounts, + DenomKeyType, +} from "@gnu-taler/taler-util"; import { AvailableCoinInfo, selectPayCoinsLegacy } from "./coinSelection.js"; function a(x: string): AmountJson { @@ -41,10 +46,14 @@ function fakeAci(current: string, feeDeposit: string): AvailableCoinInfo { }, feeDeposit: a(feeDeposit), exchangeBaseUrl: "https://example.com/", + maxAge: AgeRestriction.AGE_UNRESTRICTED, }; } -function fakeAciWithAgeRestriction(current: string, feeDeposit: string): AvailableCoinInfo { +function fakeAciWithAgeRestriction( + current: string, + feeDeposit: string, +): AvailableCoinInfo { return { value: a(current), availableAmount: a(current), @@ -56,6 +65,7 @@ function fakeAciWithAgeRestriction(current: string, feeDeposit: string): Availab }, feeDeposit: a(feeDeposit), exchangeBaseUrl: "https://example.com/", + maxAge: AgeRestriction.AGE_UNRESTRICTED, }; } @@ -284,7 +294,6 @@ test("coin selection 9", (t) => { t.pass(); }); - test("it should be able to use unrestricted coins for age restricted contract", (t) => { const acis: AvailableCoinInfo[] = [ fakeAciWithAgeRestriction("EUR:1.0", "EUR:0.2"), @@ -299,7 +308,7 @@ test("it should be able to use unrestricted coins for age restricted contract", depositFeeLimit: a("EUR:0.4"), wireFeeLimit: a("EUR:0"), wireFeeAmortization: 1, - requiredMinimumAge: 13 + requiredMinimumAge: 13, }); if (!res) { t.fail(); diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts index 9622b3a76..d2f12baf5 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.ts @@ -72,6 +72,7 @@ export interface AvailableCoinInfo { exchangeBaseUrl: string; + maxAge: number; ageCommitmentProof?: AgeCommitmentProof; } diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index 17b713659..8b8c30f35 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -33,6 +33,7 @@ import { IDBVersionChangeEvent, IDBCursor, IDBKeyPath, + IDBKeyRange, } from "@gnu-taler/idb-bridge"; import { Logger } from "@gnu-taler/taler-util"; import { performanceNow } from "./timer.js"; @@ -309,9 +310,12 @@ export function describeIndex( } interface IndexReadOnlyAccessor { - iter(query?: IDBValidKey): ResultStream; + iter(query?: IDBKeyRange | IDBValidKey): ResultStream; get(query: IDBValidKey): Promise; - getAll(query: IDBValidKey, count?: number): Promise; + getAll( + query: IDBKeyRange | IDBValidKey, + count?: number, + ): Promise; } type GetIndexReadOnlyAccess = { @@ -319,9 +323,12 @@ type GetIndexReadOnlyAccess = { }; interface IndexReadWriteAccessor { - iter(query: IDBValidKey): ResultStream; + iter(query: IDBKeyRange | IDBValidKey): ResultStream; get(query: IDBValidKey): Promise; - getAll(query: IDBValidKey, count?: number): Promise; + getAll( + query: IDBKeyRange | IDBValidKey, + count?: number, + ): Promise; } type GetIndexReadWriteAccess = { -- cgit v1.2.3