anastasis-core: use http client from taler-util
This commit is contained in:
parent
4853f79677
commit
585fe6b996
@ -22,10 +22,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@gnu-taler/taler-util": "workspace:*",
|
||||
"fetch-ponyfill": "^7.1.0",
|
||||
"fflate": "^0.7.4",
|
||||
"hash-wasm": "^4.9.0",
|
||||
"node-fetch": "^3.2.0",
|
||||
"tslib": "^2.5.3"
|
||||
},
|
||||
"ava": {
|
||||
|
@ -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;
|
||||
|
@ -6,7 +6,7 @@
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node16",
|
||||
"sourceMap": true,
|
||||
"lib": ["es6", "DOM"],
|
||||
"lib": ["es6"],
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"strict": true,
|
||||
|
@ -117,18 +117,12 @@ importers:
|
||||
'@gnu-taler/taler-util':
|
||||
specifier: workspace:*
|
||||
version: link:../taler-util
|
||||
fetch-ponyfill:
|
||||
specifier: ^7.1.0
|
||||
version: 7.1.0
|
||||
fflate:
|
||||
specifier: ^0.7.4
|
||||
version: 0.7.4
|
||||
hash-wasm:
|
||||
specifier: ^4.9.0
|
||||
version: 4.9.0
|
||||
node-fetch:
|
||||
specifier: ^3.2.0
|
||||
version: 3.2.10
|
||||
tslib:
|
||||
specifier: ^2.5.3
|
||||
version: 2.5.3
|
||||
@ -6757,6 +6751,7 @@ packages:
|
||||
/autoprefixer@10.4.14(postcss@8.4.23):
|
||||
resolution: {integrity: sha512-FQzyfOsTlwVzjHxKEqRIAdJx9niO6VCBCoEwax/VLSoQF29ggECcPuBqUMZ+u8jCZOPSy8b8/8KnuFbp0SaFZQ==}
|
||||
engines: {node: ^10 || ^12 || >=14}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
postcss: ^8.1.0
|
||||
dependencies:
|
||||
@ -6772,6 +6767,7 @@ packages:
|
||||
/ava@4.3.3(@ava/typescript@4.0.0):
|
||||
resolution: {integrity: sha512-9Egq/d9R74ExrWohHeqUlexjDbgZJX5jA1Wq4KCTqc3wIfpGEK79zVy4rBtofJ9YKIxs4PzhJ8BgbW5PlAYe6w==}
|
||||
engines: {node: '>=12.22 <13 || >=14.17 <15 || >=16.4 <17 || >=18'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@ava/typescript': '*'
|
||||
peerDependenciesMeta:
|
||||
@ -8571,11 +8567,6 @@ packages:
|
||||
assert-plus: 1.0.0
|
||||
dev: true
|
||||
|
||||
/data-uri-to-buffer@4.0.0:
|
||||
resolution: {integrity: sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==}
|
||||
engines: {node: '>= 12'}
|
||||
dev: false
|
||||
|
||||
/data-urls@1.1.0:
|
||||
resolution: {integrity: sha512-YTWYI9se1P55u58gL5GkQHW4P6VJBJ5iBT+B5a7i2Tjadhv52paJG0qHX4A0OR6/t52odI64KP2YvFpkDOi3eQ==}
|
||||
dependencies:
|
||||
@ -9338,6 +9329,7 @@ packages:
|
||||
|
||||
/eslint-config-prettier@8.5.0(eslint@8.29.0):
|
||||
resolution: {integrity: sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
eslint: '>=7.0.0'
|
||||
dependencies:
|
||||
@ -10175,22 +10167,6 @@ packages:
|
||||
websocket-driver: 0.7.4
|
||||
dev: true
|
||||
|
||||
/fetch-blob@3.2.0:
|
||||
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
|
||||
engines: {node: ^12.20 || >= 14.13}
|
||||
dependencies:
|
||||
node-domexception: 1.0.0
|
||||
web-streams-polyfill: 3.2.1
|
||||
dev: false
|
||||
|
||||
/fetch-ponyfill@7.1.0:
|
||||
resolution: {integrity: sha512-FhbbL55dj/qdVO3YNK7ZEkshvj3eQ7EuIGV2I6ic/2YiocvyWv+7jg2s4AyS0wdRU75s3tA8ZxI/xPigb0v5Aw==}
|
||||
dependencies:
|
||||
node-fetch: 2.6.7
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
dev: false
|
||||
|
||||
/fflate@0.7.4:
|
||||
resolution: {integrity: sha512-5u2V/CDW15QM1XbbgS+0DfPxVB+jUKhWEKuuFuHncbk3tEEqzmoXL+2KyOFuKGqOnmdIy0/davWF1CkuwtibCw==}
|
||||
dev: false
|
||||
@ -10435,13 +10411,6 @@ packages:
|
||||
combined-stream: 1.0.8
|
||||
mime-types: 2.1.35
|
||||
|
||||
/formdata-polyfill@4.0.10:
|
||||
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
|
||||
engines: {node: '>=12.20.0'}
|
||||
dependencies:
|
||||
fetch-blob: 3.2.0
|
||||
dev: false
|
||||
|
||||
/forwarded@0.2.0:
|
||||
resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==}
|
||||
engines: {node: '>= 0.6'}
|
||||
@ -12793,11 +12762,6 @@ packages:
|
||||
resolution: {integrity: sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==}
|
||||
dev: true
|
||||
|
||||
/node-domexception@1.0.0:
|
||||
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||
engines: {node: '>=10.5.0'}
|
||||
dev: false
|
||||
|
||||
/node-fetch@2.6.7:
|
||||
resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
|
||||
engines: {node: 4.x || >=6.0.0}
|
||||
@ -12808,15 +12772,7 @@ packages:
|
||||
optional: true
|
||||
dependencies:
|
||||
whatwg-url: 5.0.0
|
||||
|
||||
/node-fetch@3.2.10:
|
||||
resolution: {integrity: sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
dependencies:
|
||||
data-uri-to-buffer: 4.0.0
|
||||
fetch-blob: 3.2.0
|
||||
formdata-polyfill: 4.0.10
|
||||
dev: false
|
||||
dev: true
|
||||
|
||||
/node-forge@1.3.1:
|
||||
resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==}
|
||||
@ -12941,6 +12897,7 @@ packages:
|
||||
|
||||
/nx@15.0.1:
|
||||
resolution: {integrity: sha512-4pGy6f0SMQpg5kr38I95OkzufgkeMf4n/ui9o2Xk65mFdqXcCzRgRXbKdDhABhdZmhbzV33M+BUPJmMrTw3XDg==}
|
||||
hasBin: true
|
||||
requiresBuild: true
|
||||
peerDependencies:
|
||||
'@swc-node/register': ^1.4.2
|
||||
@ -13623,6 +13580,7 @@ packages:
|
||||
/postcss-cli@10.1.0(postcss@8.4.23):
|
||||
resolution: {integrity: sha512-Zu7PLORkE9YwNdvOeOVKPmWghprOtjFQU3srMUGbdz3pHJiFh7yZ4geiZFMkjMfB0mtTFR3h8RemR62rPkbOPA==}
|
||||
engines: {node: '>=14'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
postcss: ^8.0.0
|
||||
dependencies:
|
||||
@ -14332,6 +14290,7 @@ packages:
|
||||
/preact-cli@3.4.1(eslint@8.29.0)(preact-render-to-string@5.2.6)(preact@10.11.3):
|
||||
resolution: {integrity: sha512-/4be0PuBmAIAox9u8GLJublFpEymq7Lk4JW4PEPz9ErFH/ncZf/oBPhECtXGq9IPqNOEe4r2l8sA+3uqKVwBfw==}
|
||||
engines: {node: '>=12'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
less-loader: ^7.3.0
|
||||
preact: '*'
|
||||
@ -16407,6 +16366,7 @@ packages:
|
||||
|
||||
/tr46@0.0.3:
|
||||
resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
|
||||
dev: true
|
||||
|
||||
/tr46@1.0.1:
|
||||
resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==}
|
||||
@ -16426,6 +16386,7 @@ packages:
|
||||
|
||||
/ts-node@10.9.1(@types/node@18.11.17)(typescript@5.1.3):
|
||||
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@swc/core': '>=1.2.50'
|
||||
'@swc/wasm': '>=1.2.50'
|
||||
@ -16574,6 +16535,7 @@ packages:
|
||||
/typedoc@0.24.8(typescript@5.1.3):
|
||||
resolution: {integrity: sha512-ahJ6Cpcvxwaxfu4KtjA8qZNqS43wYt6JL27wYiIgl1vd38WW/KWX11YuAeZhuz9v+ttrutSsgK+XO1CjL1kA3w==}
|
||||
engines: {node: '>= 14.14'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x
|
||||
dependencies:
|
||||
@ -16713,6 +16675,7 @@ packages:
|
||||
|
||||
/update-browserslist-db@1.0.10(browserslist@4.21.4):
|
||||
resolution: {integrity: sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
browserslist: '>= 4.21.0'
|
||||
dependencies:
|
||||
@ -16723,6 +16686,7 @@ packages:
|
||||
|
||||
/update-browserslist-db@1.0.10(browserslist@4.21.5):
|
||||
resolution: {integrity: sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
browserslist: '>= 4.21.0'
|
||||
dependencies:
|
||||
@ -16963,13 +16927,9 @@ packages:
|
||||
defaults: 1.0.4
|
||||
dev: true
|
||||
|
||||
/web-streams-polyfill@3.2.1:
|
||||
resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==}
|
||||
engines: {node: '>= 8'}
|
||||
dev: false
|
||||
|
||||
/webidl-conversions@3.0.1:
|
||||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||
dev: true
|
||||
|
||||
/webidl-conversions@4.0.2:
|
||||
resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==}
|
||||
@ -17010,6 +16970,7 @@ packages:
|
||||
/webpack-dev-server@4.11.1(webpack@4.46.0):
|
||||
resolution: {integrity: sha512-lILVz9tAUy1zGFwieuaQtYiadImb5M3d+H+L1zDYalYoDl0cksAB1UNyuE5MMWJrG6zR1tXkCP2fitl7yoUJiw==}
|
||||
engines: {node: '>= 12.13.0'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
webpack: ^4.37.0 || ^5.0.0
|
||||
webpack-cli: '*'
|
||||
@ -17108,6 +17069,7 @@ packages:
|
||||
/webpack@4.46.0:
|
||||
resolution: {integrity: sha512-6jJuJjg8znb/xRItk7bkT0+Q7AHCYjjFnvKIWQPkNIOyRqoCGvkOs0ipeQzrqz4l5FtN5ZI/ukEHroeX/o1/5Q==}
|
||||
engines: {node: '>=6.11.5'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
webpack-cli: '*'
|
||||
webpack-command: '*'
|
||||
@ -17178,6 +17140,7 @@ packages:
|
||||
dependencies:
|
||||
tr46: 0.0.3
|
||||
webidl-conversions: 3.0.1
|
||||
dev: true
|
||||
|
||||
/whatwg-url@7.1.0:
|
||||
resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==}
|
||||
|
Loading…
Reference in New Issue
Block a user