gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (c5c30866 -> bf1b350d)


From: gnunet
Subject: [taler-wallet-core] branch master updated (c5c30866 -> bf1b350d)
Date: Mon, 09 Mar 2020 09:59:20 +0100

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

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

    from c5c30866 give payload notification to Android
     new 49999203 use newer bank API
     new 7ba1f918 formatting / DCE
     new bf1b350d abort exchange update if version does not match

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/headless/bank.ts        | 31 ++++++++++++++++++++-----------
 src/operations/exchanges.ts | 34 +++++++++++++++++++++++++++-------
 2 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/src/headless/bank.ts b/src/headless/bank.ts
index b82951f4..81b5293b 100644
--- a/src/headless/bank.ts
+++ b/src/headless/bank.ts
@@ -24,13 +24,16 @@
  * Imports.
  */
 import Axios from "axios";
-import querystring = require("querystring");
 
 export interface BankUser {
   username: string;
   password: string;
 }
 
+/**
+ * Generate a random alphanumeric ID.  Does *not* use cryptographically
+ * secure randomness.
+ */
 function makeId(length: number): string {
   let result = "";
   const characters =
@@ -41,18 +44,25 @@ function makeId(length: number): string {
   return result;
 }
 
+/**
+ * Helper function to generate the "Authorization" HTTP header.
+ */
 function makeAuth(username: string, password: string): string {
   const auth = `${username}:${password}`;
   const authEncoded: string = Buffer.from(auth).toString("base64");
   return `Basic ${authEncoded}`;
 }
 
-
-
+/**
+ * Client for the Taler bank access API.
+ */
 export class Bank {
   constructor(private bankBaseUrl: string) {}
 
-  async generateWithdrawUri(bankUser: BankUser, amount: string): 
Promise<string> {
+  async generateWithdrawUri(
+    bankUser: BankUser,
+    amount: string,
+  ): Promise<string> {
     const body = {
       amount,
     };
@@ -65,7 +75,7 @@ export class Bank {
       data: body,
       responseType: "json",
       headers: {
-        "Authorization": makeAuth(bankUser.username, bankUser.password),
+        Authorization: makeAuth(bankUser.username, bankUser.password),
       },
     });
 
@@ -86,14 +96,13 @@ export class Bank {
     reservePub: string,
     exchangePaytoUri: string,
   ) {
-    const reqUrl = new URL("api/withdraw-headless", this.bankBaseUrl).href;
+    const reqUrl = new URL("testing/withdraw", this.bankBaseUrl).href;
 
     const body = {
-      auth: { type: "basic" },
       username: bankUser,
       amount,
       reserve_pub: reservePub,
-      exchange_wire_detail: exchangePaytoUri,
+      exchange_payto_uri: exchangePaytoUri,
     };
 
     const resp = await Axios({
@@ -102,7 +111,7 @@ export class Bank {
       data: body,
       responseType: "json",
       headers: {
-        "Authorization": makeAuth(bankUser.username, bankUser.password),
+        Authorization: makeAuth(bankUser.username, bankUser.password),
       },
     });
 
@@ -112,7 +121,7 @@ export class Bank {
   }
 
   async registerRandomUser(): Promise<BankUser> {
-    const reqUrl = new URL("api/register", this.bankBaseUrl).href;
+    const reqUrl = new URL("testing/register", this.bankBaseUrl).href;
     const randId = makeId(8);
     const bankUser: BankUser = {
       username: `testuser-${randId}`,
@@ -122,7 +131,7 @@ export class Bank {
     const resp = await Axios({
       method: "post",
       url: reqUrl,
-      data: querystring.stringify(bankUser as any),
+      data: bankUser,
       responseType: "json",
     });
 
diff --git a/src/operations/exchanges.ts b/src/operations/exchanges.ts
index 2e0fd090..89f89ec1 100644
--- a/src/operations/exchanges.ts
+++ b/src/operations/exchanges.ts
@@ -15,7 +15,12 @@
  */
 
 import { InternalWalletState } from "./state";
-import { ExchangeKeysJson, Denomination, ExchangeWireJson, 
codecForExchangeKeysJson, codecForExchangeWireJson } from "../types/talerTypes";
+import {
+  ExchangeKeysJson,
+  Denomination,
+  codecForExchangeKeysJson,
+  codecForExchangeWireJson,
+} from "../types/talerTypes";
 import { OperationError } from "../types/walletTypes";
 import {
   ExchangeRecord,
@@ -27,18 +32,19 @@ import {
   ExchangeUpdateReason,
   ExchangeUpdatedEventRecord,
 } from "../types/dbTypes";
-import {
-  canonicalizeBaseUrl,
-} from "../util/helpers";
-import { Database } from "../util/query";
+import { canonicalizeBaseUrl } from "../util/helpers";
 import * as Amounts from "../util/amounts";
 import { parsePaytoUri } from "../util/payto";
 import {
   OperationFailedAndReportedError,
   guardOperationException,
 } from "./errors";
-import { WALLET_CACHE_BREAKER_CLIENT_VERSION } from "./versions";
+import {
+  WALLET_CACHE_BREAKER_CLIENT_VERSION,
+  WALLET_EXCHANGE_PROTOCOL_VERSION,
+} from "./versions";
 import { getTimestampNow } from "../util/time";
+import { compare } from "../util/libtoolVersion";
 
 async function denominationRecordFromKeys(
   ws: InternalWalletState,
@@ -127,7 +133,7 @@ async function updateExchangeWithKeys(
     throw new OperationFailedAndReportedError(m);
   }
 
-  const lastUpdateTimestamp = exchangeKeysJson.list_issue_date
+  const lastUpdateTimestamp = exchangeKeysJson.list_issue_date;
   if (!lastUpdateTimestamp) {
     const m = `Parsing /keys response failed: invalid list_issue_date.`;
     await setExchangeError(ws, baseUrl, {
@@ -159,6 +165,20 @@ async function updateExchangeWithKeys(
     throw new OperationFailedAndReportedError(m);
   }
 
+  const versionRes = compare(WALLET_EXCHANGE_PROTOCOL_VERSION, 
protocolVersion);
+  if (versionRes?.compatible != true) {
+    const m = "exchange protocol version not compatible with wallet";
+    await setExchangeError(ws, baseUrl, {
+      type: "protocol-incompatible",
+      details: {
+        exchangeProtocolVersion: protocolVersion,
+        walletProtocolVersion: WALLET_EXCHANGE_PROTOCOL_VERSION,
+      },
+      message: m,
+    });
+    throw new OperationFailedAndReportedError(m);
+  }
+
   const currency = Amounts.parseOrThrow(exchangeKeysJson.denoms[0].value)
     .currency;
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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