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: support restrict


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core: support restricting scope for peer push payments
Date: Wed, 11 Sep 2024 16:29:56 +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 f401ab076 wallet-core: support restricting scope for peer push payments
f401ab076 is described below

commit f401ab076bb037e46c4b12e371dfe13a777bf582
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Sep 11 16:29:50 2024 +0200

    wallet-core: support restricting scope for peer push payments
---
 packages/taler-util/src/types-taler-wallet.ts      | 13 +++++++++++++
 packages/taler-wallet-core/src/coinSelection.ts    | 22 ++++++++++++++++++++++
 packages/taler-wallet-core/src/db.ts               |  7 +++++++
 packages/taler-wallet-core/src/exchanges.ts        | 11 +++++++++++
 .../taler-wallet-core/src/pay-peer-push-debit.ts   |  7 ++++++-
 5 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/packages/taler-util/src/types-taler-wallet.ts 
b/packages/taler-util/src/types-taler-wallet.ts
index 0461b74f9..879749784 100644
--- a/packages/taler-util/src/types-taler-wallet.ts
+++ b/packages/taler-util/src/types-taler-wallet.ts
@@ -2749,6 +2749,12 @@ export interface CheckPeerPushDebitRequest {
    */
   amount: AmountString;
 
+  /**
+   * Restrict the scope of funds that can be spent via the given
+   * scope info.
+   */
+  restrictScope?: ScopeInfo;
+
   /**
    * ID provided by the client to cancel the request.
    *
@@ -2789,6 +2795,13 @@ export interface CheckPeerPushDebitResponse {
 
 export interface InitiatePeerPushDebitRequest {
   exchangeBaseUrl?: string;
+
+  /**
+   * Restrict the scope of funds that can be spent via the given
+   * scope info.
+   */
+  restrictScope?: ScopeInfo;
+
   partialContractTerms: PeerContractTerms;
 }
 
diff --git a/packages/taler-wallet-core/src/coinSelection.ts 
b/packages/taler-wallet-core/src/coinSelection.ts
index 87d2c9c36..164a7858d 100644
--- a/packages/taler-wallet-core/src/coinSelection.ts
+++ b/packages/taler-wallet-core/src/coinSelection.ts
@@ -46,6 +46,8 @@ import {
   PayCoinSelection,
   PaymentInsufficientBalanceDetails,
   ProspectivePayCoinSelection,
+  ScopeInfo,
+  ScopeType,
   SelectedCoin,
   SelectedProspectiveCoin,
   strcmp,
@@ -55,6 +57,7 @@ import { getPaymentBalanceDetailsInTx } from "./balance.js";
 import { getAutoRefreshExecuteThreshold } from "./common.js";
 import { DenominationRecord, WalletDbReadOnlyTransaction } from "./db.js";
 import {
+  checkExchangeInScope,
   ExchangeWireDetails,
   getExchangeWireDetailsInTx,
 } from "./exchanges.js";
@@ -992,6 +995,12 @@ export type SelectPeerCoinsResult =
 export interface PeerCoinSelectionRequest {
   instructedAmount: AmountJson;
 
+  /**
+   * Restrict the scope of funds that can be spent via the given
+   * scope info.
+   */
+  restrictScope?: ScopeInfo;
+
   /**
    * Instruct the coin selection to repair this coin
    * selection instead of selecting completely new coins.
@@ -1165,6 +1174,19 @@ export async function selectPeerCoinsInTx(
     if (!exchWire) {
       continue;
     }
+    const isInScope = req.restrictScope
+      ? await checkExchangeInScope(wex, exch.baseUrl, req.restrictScope)
+      : true;
+    if (!isInScope) {
+      continue;
+    }
+    if (
+      req.restrictScope &&
+      req.restrictScope.type === ScopeType.Exchange &&
+      req.restrictScope.url !== exch.baseUrl
+    ) {
+      continue;
+    }
     const globalFees = getGlobalFees(exchWire);
     if (!globalFees) {
       continue;
diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index 7f3b24250..c1f2df26c 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -1897,6 +1897,13 @@ export interface PeerPushDebitRecord {
    */
   exchangeBaseUrl: string;
 
+  /**
+   * Restricted scope for this transaction.
+   * 
+   * Relevant for coin reselection.
+   */
+  restrictScope?: ScopeInfo;
+
   /**
    * Instructed amount.
    */
diff --git a/packages/taler-wallet-core/src/exchanges.ts 
b/packages/taler-wallet-core/src/exchanges.ts
index 4c2677482..773ad0d59 100644
--- a/packages/taler-wallet-core/src/exchanges.ts
+++ b/packages/taler-wallet-core/src/exchanges.ts
@@ -3571,3 +3571,14 @@ export async function processExchangeKyc(
       );
   }
 }
+
+export async function checkExchangeInScope(
+  wex: WalletExecutionContext,
+  exchangeBaseUrl: string,
+  scope: ScopeInfo,
+): Promise<boolean> {
+  if (scope.type === ScopeType.Exchange && scope.url !== exchangeBaseUrl) {
+    return false;
+  }
+  return true;
+}
diff --git a/packages/taler-wallet-core/src/pay-peer-push-debit.ts 
b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
index 4485976b9..97b337bdb 100644
--- a/packages/taler-wallet-core/src/pay-peer-push-debit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
@@ -80,6 +80,7 @@ import {
   timestampProtocolFromDb,
   timestampProtocolToDb,
 } from "./db.js";
+import { getScopeForAllExchanges } from "./exchanges.js";
 import {
   codecForExchangePurseStatus,
   getTotalPeerPaymentCost,
@@ -93,7 +94,6 @@ import {
   notifyTransition,
 } from "./transactions.js";
 import { WalletExecutionContext } from "./wallet.js";
-import { getScopeForAllExchanges } from "./exchanges.js";
 
 const logger = new Logger("pay-peer-push-debit.ts");
 
@@ -455,6 +455,7 @@ async function internalCheckPeerPushDebit(
   );
   const coinSelRes = await selectPeerCoins(wex, {
     instructedAmount,
+    restrictScope: req.restrictScope,
   });
   let coins: SelectedProspectiveCoin[] | undefined = undefined;
   switch (coinSelRes.type) {
@@ -528,6 +529,7 @@ async function handlePurseCreationConflict(
 
   const coinSelRes = await selectPeerCoins(wex, {
     instructedAmount,
+    restrictScope: peerPushInitiation.restrictScope,
     repair,
   });
 
@@ -599,6 +601,7 @@ async function processPeerPushDebitCreateReserve(
   if (!peerPushInitiation.coinSel) {
     const coinSelRes = await selectPeerCoins(wex, {
       instructedAmount: Amounts.parseOrThrow(peerPushInitiation.amount),
+      restrictScope: peerPushInitiation.restrictScope,
     });
 
     switch (coinSelRes.type) {
@@ -1228,6 +1231,7 @@ export async function initiatePeerPushDebit(
     async (tx) => {
       const coinSelRes = await selectPeerCoinsInTx(wex, tx, {
         instructedAmount,
+        restrictScope: req.restrictScope,
       });
 
       let coins: SelectedProspectiveCoin[] | undefined = undefined;
@@ -1255,6 +1259,7 @@ export async function initiatePeerPushDebit(
       const totalAmount = await getTotalPeerPaymentCostInTx(wex, tx, coins);
       const ppi: PeerPushDebitRecord = {
         amount: Amounts.stringify(instructedAmount),
+        restrictScope: req.restrictScope,
         contractPriv: contractKeyPair.priv,
         contractPub: contractKeyPair.pub,
         contractTermsHash: hContractTerms,

-- 
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]