gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/03: core should use builtin fetch, not this weird


From: gnunet
Subject: [taler-wallet-core] 02/03: core should use builtin fetch, not this weird httplib impl that only really works on node
Date: Sun, 21 Apr 2024 11:27:06 +0200

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

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

commit 9d681226b432c989e7ede05fbaab82d3b2476f2f
Author: Nullptrderef <nullptrderef@proton.me>
AuthorDate: Sun Apr 21 11:26:47 2024 +0200

    core should use builtin fetch, not this weird httplib impl that only really 
works on node
---
 packages/anastasis-core/src/index.ts  | 39 +++++++++++++++--------------------
 packages/anastasis-core/tsconfig.json |  2 +-
 2 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/packages/anastasis-core/src/index.ts 
b/packages/anastasis-core/src/index.ts
index cbb94a5d4..15e06cb85 100644
--- a/packages/anastasis-core/src/index.ts
+++ b/packages/anastasis-core/src/index.ts
@@ -43,10 +43,7 @@ import {
   URL,
   j2s,
 } from "@gnu-taler/taler-util";
-import {
-  HttpResponse,
-  createPlatformHttpLib,
-} from "@gnu-taler/taler-util/http";
+import { HttpResponse } from "@gnu-taler/taler-util/http";
 import { anastasisData } from "./anastasis-data.js";
 import {
   codecForChallengeInstructionMessage,
@@ -140,10 +137,6 @@ export * from "./reducer-types.js";
 export * as validators from "./validators.js";
 export * from "./challenge-feedback-types.js";
 
-const httpLib = createPlatformHttpLib({
-  enableThrottling: false,
-});
-
 const logger = new Logger("anastasis-core:index.ts");
 
 const ANASTASIS_HTTP_HEADER_POLICY_META_DATA = "Anastasis-Policy-Meta-Data";
@@ -286,17 +279,19 @@ async function getProviderInfo(
   providerBaseUrl: string,
 ): Promise<AuthenticationProviderStatus> {
   // FIXME: Use a reasonable timeout here.
-  let resp: HttpResponse;
+  console.log("hi");
+
+  let resp: Response;
   try {
-    resp = await httpLib.fetch(new URL("config", providerBaseUrl).href);
+    resp = await fetch(new URL("config", providerBaseUrl).href);
   } catch (e) {
     return {
       status: "error",
       code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
-      hint: "request to provider failed",
+      hint: "request to anastasis provider failed",
     };
   }
-  if (resp.status !== 200) {
+  if (resp.status >= 400) {
     return {
       status: "error",
       code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
@@ -558,7 +553,7 @@ async function uploadSecret(
       // FIXME: Get this from the params
       reqUrl.searchParams.set("timeout_ms", "500");
     }
-    const resp = await httpLib.fetch(reqUrl.href, {
+    const resp = await fetch(reqUrl.href, {
       method: "POST",
       headers: {
         "content-type": "application/json",
@@ -648,7 +643,7 @@ async function uploadSecret(
       reqUrl.searchParams.set("timeout_ms", "500");
     }
     logger.info(`uploading policy to ${prov.provider_url}`);
-    const resp = await httpLib.fetch(reqUrl.href, {
+    const resp = await fetch(reqUrl.href, {
       method: "POST",
       headers: {
         "Anastasis-Policy-Signature": encodeCrock(sig),
@@ -759,14 +754,14 @@ async function downloadPolicyFromProvider(
   const acctKeypair = accountKeypairDerive(userId);
   const reqUrl = new URL(`policy/${acctKeypair.pub}`, providerUrl);
   reqUrl.searchParams.set("version", `${version}`);
-  const resp = await httpLib.fetch(reqUrl.href);
+  const resp = await fetch(reqUrl.href);
   if (resp.status !== 200) {
     logger.info(
       `Could not download policy from provider ${providerUrl}, status 
${resp.status}`,
     );
     return undefined;
   }
-  const body = await resp.bytes();
+  const body = await resp.arrayBuffer();
   const bodyDecrypted = await decryptRecoveryDocument(
     userId,
     encodeCrock(body),
@@ -983,10 +978,10 @@ async function requestTruth(
 
   const hresp = await getResponseHash(truth, solveRequest);
 
-  let resp: HttpResponse;
+  let resp: Response;
 
   try {
-    resp = await httpLib.fetch(url.href, {
+    resp = await fetch(url.href, {
       method: "POST",
       headers: {
         Accept: "application/json",
@@ -1024,7 +1019,7 @@ async function requestTruth(
       truth.provider_salt,
     );
 
-    const respBody = new Uint8Array(await resp.bytes());
+    const respBody = new Uint8Array(await resp.arrayBuffer());
     const keyShare = await decryptKeyShare(
       encodeCrock(respBody),
       userId,
@@ -1140,10 +1135,10 @@ async function selectChallenge(
     }
   }
 
-  let resp: HttpResponse;
+  let resp: Response;
 
   try {
-    resp = await httpLib.fetch(url.href, {
+    resp = await fetch(url.href, {
       method: "POST",
       headers: {
         Accept: "application/json",
@@ -1861,7 +1856,7 @@ export async function discoverPolicies(
     );
     const acctKeypair = accountKeypairDerive(userId);
     const reqUrl = new URL(`policy/${acctKeypair.pub}/meta`, providerUrl);
-    const resp = await httpLib.fetch(reqUrl.href);
+    const resp = await fetch(reqUrl.href);
     if (resp.status !== 200) {
       logger.warn(`Could not fetch policy metadate from ${reqUrl.href}`);
       continue;
diff --git a/packages/anastasis-core/tsconfig.json 
b/packages/anastasis-core/tsconfig.json
index a12f2e641..e463201e7 100644
--- a/packages/anastasis-core/tsconfig.json
+++ b/packages/anastasis-core/tsconfig.json
@@ -6,7 +6,7 @@
     "module": "Node16",
     "moduleResolution": "Node16",
     "sourceMap": true,
-    "lib": ["ES2020"],
+    "lib": ["ES2020", "DOM"],
     "noImplicitReturns": true,
     "noFallthroughCasesInSwitch": true,
     "strict": true,

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