gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: wallet-core: make coin select


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core: make coin selection aware of age restriction
Date: Fri, 29 Apr 2022 21:05:36 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 9996c274 wallet-core: make coin selection aware of age restriction
9996c274 is described below

commit 9996c274886cd80d5255765f7e3db8dfcadcfc94
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Apr 29 21:05:17 2022 +0200

    wallet-core: make coin selection aware of age restriction
---
 packages/taler-wallet-core/src/operations/pay.ts   |  4 ++++
 .../taler-wallet-core/src/util/coinSelection.ts    | 24 +++++++++++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/pay.ts 
b/packages/taler-wallet-core/src/operations/pay.ts
index a1773547..db157257 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -315,6 +315,7 @@ export async function getCandidatePayCoins(
             denomPub: denom.denomPub,
             feeDeposit: denom.feeDeposit,
             exchangeBaseUrl: denom.exchangeBaseUrl,
+            ageCommitmentProof: coin.ageCommitmentProof,
           });
         }
 
@@ -1120,6 +1121,7 @@ async function handleInsufficientFunds(
     wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
     wireFeeLimit: contractData.maxWireFee,
     prevPayCoins,
+    requiredMinimumAge: contractData.minimumAge,
   });
 
   if (!res) {
@@ -1236,6 +1238,7 @@ export async function checkPaymentByProposalId(
       wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
       wireFeeLimit: contractData.maxWireFee,
       prevPayCoins: [],
+      requiredMinimumAge: contractData.minimumAge,
     });
 
     if (!res) {
@@ -1488,6 +1491,7 @@ export async function confirmPay(
     wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
     wireFeeLimit: contractData.maxWireFee,
     prevPayCoins: [],
+    requiredMinimumAge: contractData.minimumAge,
   });
 
   logger.trace("coin selection result", res);
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts 
b/packages/taler-wallet-core/src/util/coinSelection.ts
index e19b5877..080a5049 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,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]