diff options
author | Florian Dold <florian@dold.me> | 2022-04-29 21:05:17 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-04-29 21:05:28 +0200 |
commit | 9996c274886cd80d5255765f7e3db8dfcadcfc94 (patch) | |
tree | ecf305bac9f332f7b6a160e4b8b747906b514591 /packages/taler-wallet-core/src/util/coinSelection.ts | |
parent | 5e7be5865888393fbf3e00ed76a556bb4f0ace66 (diff) | |
download | wallet-core-9996c274886cd80d5255765f7e3db8dfcadcfc94.tar.gz wallet-core-9996c274886cd80d5255765f7e3db8dfcadcfc94.tar.bz2 wallet-core-9996c274886cd80d5255765f7e3db8dfcadcfc94.zip |
wallet-core: make coin selection aware of age restriction
Diffstat (limited to 'packages/taler-wallet-core/src/util/coinSelection.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/coinSelection.ts | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts index e19b58774..080a5049d 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.ts @@ -24,12 +24,12 @@ * Imports. */ import { + AgeCommitmentProof, + AgeRestriction, AmountJson, Amounts, DenominationPubKey, - DenomKeyType, Logger, - strcmp, } from "@gnu-taler/taler-util"; const logger = new Logger("coinSelection.ts"); @@ -77,7 +77,7 @@ export interface AvailableCoinInfo { /** * Coin's denomination public key. - * + * * FIXME: We should only need the denomPubHash here, if at all. */ denomPub: DenominationPubKey; @@ -94,6 +94,8 @@ export interface AvailableCoinInfo { feeDeposit: AmountJson; exchangeBaseUrl: string; + + ageCommitmentProof?: AgeCommitmentProof; } export type PreviousPayCoins = { @@ -115,6 +117,7 @@ export interface SelectPayCoinRequest { wireFeeLimit: AmountJson; wireFeeAmortization: number; prevPayCoins?: PreviousPayCoins; + requiredMinimumAge?: number; } interface CoinSelectionTally { @@ -306,6 +309,21 @@ export function selectPayCoins( continue; } + if (req.requiredMinimumAge != null) { + const index = AgeRestriction.getAgeGroupIndex( + aci.denomPub.age_mask, + req.requiredMinimumAge, + ); + if (!aci.ageCommitmentProof) { + // No age restriction, can't use for this payment + continue; + } + if (aci.ageCommitmentProof.proof.privateKeys.length < index) { + // Available age proofs to low, can't use for this payment + continue; + } + } + tally = tallyFees( tally, candidates.wireFeesPerExchange, |