aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2024-05-27 14:10:40 -0600
committerIván Ávalos <avalos@disroot.org>2024-05-27 14:10:40 -0600
commitd9c0332004d01642bc5158d7a81b5357ef4aff6f (patch)
tree041d466ef8103a3d08e7480ab3fc5977ccdc8340 /packages
parentdb45b25fe871de42a68a4303b6eb31aa6da64f9b (diff)
downloadwallet-core-d9c0332004d01642bc5158d7a81b5357ef4aff6f.tar.xz
anastasis: switch to new http fetch function
Diffstat (limited to 'packages')
-rw-r--r--packages/anastasis-core/src/index.ts33
1 files changed, 19 insertions, 14 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts
index 05fa4a49f..c4ead05a7 100644
--- a/packages/anastasis-core/src/index.ts
+++ b/packages/anastasis-core/src/index.ts
@@ -43,7 +43,7 @@ import {
URL,
j2s,
} from "@gnu-taler/taler-util";
-import { HttpResponse } from "@gnu-taler/taler-util/http";
+import { HttpResponse, createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import { anastasisData } from "./anastasis-data.js";
import {
codecForChallengeInstructionMessage,
@@ -139,6 +139,11 @@ export * from "./challenge-feedback-types.js";
const logger = new Logger("anastasis-core:index.ts");
+const http = createPlatformHttpLib({
+ enableThrottling: true,
+ requireTls: false,
+});
+
const ANASTASIS_HTTP_HEADER_POLICY_META_DATA = "Anastasis-Policy-Meta-Data";
function getContinents(): ContinentInfo[] {
@@ -279,9 +284,9 @@ async function getProviderInfo(
providerBaseUrl: string,
): Promise<AuthenticationProviderStatus> {
// FIXME: Use a reasonable timeout here.
- let resp: Response;
+ let resp: HttpResponse;
try {
- resp = await fetch(new URL("config", providerBaseUrl).href);
+ resp = await http.fetch(new URL("config", providerBaseUrl).href);
} catch (e) {
console.warn(
"Encountered an HTTP error whilst trying to get the provider's config: ",
@@ -293,7 +298,7 @@ async function getProviderInfo(
hint: "request to anastasis provider failed",
};
}
- if (!resp.ok) {
+ if (resp.status < 200 && resp.status >= 300) {
console.warn("Got bad response code whilst getting provider config", resp);
return {
status: "error",
@@ -556,7 +561,7 @@ async function uploadSecret(
// FIXME: Get this from the params
reqUrl.searchParams.set("timeout_ms", "500");
}
- const resp = await fetch(reqUrl.href, {
+ const resp = await http.fetch(reqUrl.href, {
method: "POST",
headers: {
"content-type": "application/json",
@@ -646,7 +651,7 @@ async function uploadSecret(
reqUrl.searchParams.set("timeout_ms", "500");
}
logger.info(`uploading policy to ${prov.provider_url}`);
- const resp = await fetch(reqUrl.href, {
+ const resp = await http.fetch(reqUrl.href, {
method: "POST",
headers: {
"Anastasis-Policy-Signature": encodeCrock(sig),
@@ -757,14 +762,14 @@ async function downloadPolicyFromProvider(
const acctKeypair = accountKeypairDerive(userId);
const reqUrl = new URL(`policy/${acctKeypair.pub}`, providerUrl);
reqUrl.searchParams.set("version", `${version}`);
- const resp = await fetch(reqUrl.href);
+ const resp = await http.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.arrayBuffer();
+ const body = await resp.bytes();
const bodyDecrypted = await decryptRecoveryDocument(
userId,
encodeCrock(body),
@@ -981,10 +986,10 @@ async function requestTruth(
const hresp = await getResponseHash(truth, solveRequest);
- let resp: Response;
+ let resp: HttpResponse;
try {
- resp = await fetch(url.href, {
+ resp = await http.fetch(url.href, {
method: "POST",
headers: {
Accept: "application/json",
@@ -1022,7 +1027,7 @@ async function requestTruth(
truth.provider_salt,
);
- const respBody = new Uint8Array(await resp.arrayBuffer());
+ const respBody = new Uint8Array(await resp.bytes());
const keyShare = await decryptKeyShare(
encodeCrock(respBody),
userId,
@@ -1138,10 +1143,10 @@ async function selectChallenge(
}
}
- let resp: Response;
+ let resp: HttpResponse;
try {
- resp = await fetch(url.href, {
+ resp = await http.fetch(url.href, {
method: "POST",
headers: {
Accept: "application/json",
@@ -1859,7 +1864,7 @@ export async function discoverPolicies(
);
const acctKeypair = accountKeypairDerive(userId);
const reqUrl = new URL(`policy/${acctKeypair.pub}/meta`, providerUrl);
- const resp = await fetch(reqUrl.href);
+ const resp = await http.fetch(reqUrl.href);
if (resp.status !== 200) {
logger.warn(`Could not fetch policy metadate from ${reqUrl.href}`);
continue;