diff options
Diffstat (limited to 'packages/anastasis-core/src')
-rw-r--r-- | packages/anastasis-core/src/index.ts | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index 5e7397450..88f3bdbe2 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -43,6 +43,7 @@ import { URL, j2s, } from "@gnu-taler/taler-util"; +import { HttpResponse, createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { anastasisData } from "./anastasis-data.js"; import { codecForChallengeInstructionMessage, @@ -96,7 +97,6 @@ import { AggregatedPolicyMetaInfo, AuthenticationProviderStatusMap, } from "./reducer-types.js"; -import fetchPonyfill from "fetch-ponyfill"; import { accountKeypairDerive, asOpaque, @@ -133,12 +133,15 @@ import { ChallengeFeedbackStatus, } from "./challenge-feedback-types.js"; -const { fetch } = fetchPonyfill({}); - export * from "./reducer-types.js"; export * as validators from "./validators.js"; export * from "./challenge-feedback-types.js"; +const httpLib = createPlatformHttpLib({ + allowHttp: true, + enableThrottling: false, +}); + const logger = new Logger("anastasis-core:index.ts"); const ANASTASIS_HTTP_HEADER_POLICY_META_DATA = "Anastasis-Policy-Meta-Data"; @@ -281,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 httpLib.fetch(new URL("config", providerBaseUrl).href); } catch (e) { return { status: "error", @@ -553,7 +556,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 httpLib.fetch(reqUrl.href, { method: "POST", headers: { "content-type": "application/json", @@ -643,7 +646,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 httpLib.fetch(reqUrl.href, { method: "POST", headers: { "Anastasis-Policy-Signature": encodeCrock(sig), @@ -754,14 +757,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 httpLib.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), @@ -978,10 +981,10 @@ async function requestTruth( const hresp = await getResponseHash(truth, solveRequest); - let resp: Response; + let resp: HttpResponse; try { - resp = await fetch(url.href, { + resp = await httpLib.fetch(url.href, { method: "POST", headers: { Accept: "application/json", @@ -1019,7 +1022,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, @@ -1135,10 +1138,10 @@ async function selectChallenge( } } - let resp: Response; + let resp: HttpResponse; try { - resp = await fetch(url.href, { + resp = await httpLib.fetch(url.href, { method: "POST", headers: { Accept: "application/json", @@ -1856,7 +1859,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 httpLib.fetch(reqUrl.href); if (resp.status !== 200) { logger.warn(`Could not fetch policy metadate from ${reqUrl.href}`); continue; |