get rid of deprecated bank API client, change allowHttp to requireTls

This commit is contained in:
Florian Dold 2023-09-06 12:32:31 +02:00
parent 07d71eb297
commit 7450bede5b
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
30 changed files with 188 additions and 372 deletions

View File

@ -138,7 +138,6 @@ export * as validators from "./validators.js";
export * from "./challenge-feedback-types.js";
const httpLib = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});

View File

@ -57,7 +57,6 @@ export async function runBench2(configJson: any): Promise<void> {
const http = createPlatformHttpLib({
enableThrottling: false,
allowHttp: true,
});
const numIter = benchConf.iterations ?? 1;

View File

@ -52,7 +52,6 @@ export async function runBench3(configJson: any): Promise<void> {
const myHttpLib = createPlatformHttpLib({
enableThrottling: false,
allowHttp: true,
});
const numIter = b3conf.iterations ?? 1;

View File

@ -25,62 +25,46 @@
* Imports
*/
import {
AccountAddDetails,
AmountJson,
Amounts,
AmountString,
codecForMerchantOrderPrivateStatusResponse,
codecForMerchantPostOrderResponse,
codecForMerchantReserveCreateConfirmation,
Configuration,
CoreApiResponse,
createEddsaKeyPair,
Duration,
eddsaGetPublic,
EddsaKeyPair,
Logger,
MerchantInstanceConfig,
PartialMerchantInstanceConfig,
TalerError,
WalletNotification,
createEddsaKeyPair,
eddsaGetPublic,
encodeCrock,
hash,
j2s,
Logger,
MerchantInstancesResponse,
MerchantOrderPrivateStatusResponse,
MerchantPostOrderRequest,
MerchantPostOrderResponse,
MerchantReserveCreateConfirmation,
MerchantTemplateAddDetails,
parsePaytoUri,
stringToBytes,
TalerError,
TalerProtocolDuration,
RewardCreateConfirmation,
RewardCreateRequest,
TippingReserveStatus,
WalletNotification,
codecForAny,
AccountAddDetails,
MerchantInstanceConfig,
PartialMerchantInstanceConfig,
} from "@gnu-taler/taler-util";
import {
createPlatformHttpLib,
expectSuccessResponseOrThrow,
readSuccessResponseJsonOrThrow,
} from "@gnu-taler/taler-util/http";
import {
BankApi,
BankAccessApiClient,
BankServiceHandle,
HarnessExchangeBankAccount,
openPromise,
WalletCoreApiClient,
WalletCoreRequestType,
WalletCoreResponseType,
WalletOperations,
openPromise,
} from "@gnu-taler/taler-wallet-core";
import {
RemoteWallet,
WalletNotificationWaiter,
createRemoteWallet,
getClientFromRemoteWallet,
makeNotificationWaiter,
RemoteWallet,
WalletNotificationWaiter,
} from "@gnu-taler/taler-wallet-core/remote";
import { deepStrictEqual } from "assert";
import { ChildProcess, spawn } from "child_process";
@ -594,7 +578,7 @@ export class FakebankService
{
proc: ProcessWrapper | undefined;
http = createPlatformHttpLib({ allowHttp: true, enableThrottling: false });
http = createPlatformHttpLib({ enableThrottling: false });
// We store "created" accounts during setup and
// register them after startup.
@ -702,13 +686,9 @@ export class FakebankService
"bank",
);
await this.pingUntilAvailable();
const bankClient = new BankAccessApiClient(this.bankAccessApiBaseUrl);
for (const acc of this.accounts) {
await BankApi.registerAccount(
this,
acc.accountName,
acc.accountPassword,
{},
);
await bankClient.registerAccount(acc.accountName, acc.accountPassword);
}
}
@ -1351,7 +1331,6 @@ export interface MerchantServiceInterface {
* Default HTTP client handle for the integration test harness.
*/
export const harnessHttpLib = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});

View File

@ -36,8 +36,7 @@ import {
MerchantApiClient,
} from "@gnu-taler/taler-util";
import {
BankAccessApi,
BankApi,
BankAccessApiClient,
HarnessExchangeBankAccount,
WalletApiOperation,
} from "@gnu-taler/taler-wallet-core";
@ -563,8 +562,10 @@ export async function withdrawViaBankV2(
): Promise<WithdrawViaBankResult> {
const { walletClient: wallet, bank, exchange, amount } = p;
const user = await BankApi.createRandomBankUser(bank);
const wop = await BankAccessApi.createWithdrawalOperation(bank, user, amount);
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
const user = await bankClient.createRandomBankUser();
const wop = await bankClient.createWithdrawalOperation(user.username, amount);
// Hand it to the wallet
@ -593,7 +594,7 @@ export async function withdrawViaBankV2(
// Confirm it
await BankApi.confirmWithdrawalOperation(bank, user, wop);
await bankClient.confirmWithdrawalOperation(user.username, wop);
return {
withdrawalFinishedCond,

View File

@ -176,10 +176,7 @@ export interface LibeufinSandboxAddIncomingRequest {
direction: string;
}
const libeufinHarnessHttpLib = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});
const libeufinHarnessHttpLib = createPlatformHttpLib();
/**
* APIs spread across Legacy and Access, it is therefore

View File

@ -236,14 +236,15 @@ deploymentCli
console.log(tipReserveResp);
const bankAccessApiClient = new BankAccessApiClient({
baseUrl: args.tipTopup.bankAccessUrl,
const bankAccessApiClient = new BankAccessApiClient(
args.tipTopup.bankAccessUrl,
{
auth: {
username: args.tipTopup.bankAccount,
password: args.tipTopup.bankPassword,
},
allowHttp: true,
});
},
);
const paytoUri = addPaytoQueryParams(tipReserveResp.accounts[0].payto_uri, {
message: `tip-reserve ${tipReserveResp.reserve_pub}`,

View File

@ -18,7 +18,7 @@
* Imports.
*/
import {
BankApi,
BankAccessApiClient,
WalletApiOperation,
WireGatewayApiClient,
} from "@gnu-taler/taler-wallet-core";
@ -179,7 +179,8 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
// Pay with coin from tipping
{
const mbu = await BankApi.createRandomBankUser(bank);
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
const mbu = await bankClient.createRandomBankUser();
const tipReserveResp = await merchantClient.createTippingReserve({
exchange_url: exchange.baseUrl,
initial_balance: "TESTKUDOS:10",
@ -191,12 +192,15 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
exchangeBankAccount.accountPaytoUri,
);
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
allowHttp: true,
});
const wireGatewayApiClient = new WireGatewayApiClient(
exchangeBankAccount.wireGatewayApiBaseUrl,
{
auth: {
username: exchangeBankAccount.accountName,
password: exchangeBankAccount.accountPassword,
},
},
);
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:10",

View File

@ -19,8 +19,7 @@
*/
import { createEddsaKeyPair, encodeCrock } from "@gnu-taler/taler-util";
import {
BankAccessApi,
BankApi,
BankAccessApiClient,
CreditDebitIndicator,
WireGatewayApiClient,
} from "@gnu-taler/taler-wallet-core";
@ -99,17 +98,19 @@ export async function runBankApiTest(t: GlobalTestState) {
console.log("setup done!");
const bankUser = await BankApi.registerAccount(bank, "user1", "pw1", {});
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
const bankUser = await bankClient.registerAccount("user1", "pw1");
// Make sure that registering twice results in a 409 Conflict
{
const e = await t.assertThrowsTalerErrorAsync(async () => {
await BankApi.registerAccount(bank, "user1", "pw2", {});
await bankClient.registerAccount("user1", "pw1");
});
t.assertTrue(e.errorDetail.httpStatusCode === 409);
}
let balResp = await BankAccessApi.getAccountBalance(bank, bankUser);
let balResp = await bankClient.getAccountBalance(bankUser.username);
console.log(balResp);
@ -121,12 +122,15 @@ export async function runBankApiTest(t: GlobalTestState) {
const res = createEddsaKeyPair();
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
allowHttp: true,
});
const wireGatewayApiClient = new WireGatewayApiClient(
exchangeBankAccount.wireGatewayApiBaseUrl,
{
auth: {
username: exchangeBankAccount.accountName,
password: exchangeBankAccount.accountPassword,
},
},
);
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:115",
@ -134,7 +138,7 @@ export async function runBankApiTest(t: GlobalTestState) {
reservePub: encodeCrock(res.eddsaPub),
});
balResp = await BankAccessApi.getAccountBalance(bank, bankUser);
balResp = await bankClient.getAccountBalance(bankUser.username);
t.assertAmountEquals(balResp.balance.amount, "TESTKUDOS:15");
t.assertTrue(
balResp.balance.credit_debit_indicator === CreditDebitIndicator.Debit,

View File

@ -49,7 +49,6 @@ export async function runExchangeDepositTest(t: GlobalTestState) {
const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t);
const http = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});
const cryptiDisp = new CryptoDispatcher(

View File

@ -28,8 +28,7 @@ import {
} from "../harness/harness.js";
import {
WalletApiOperation,
BankApi,
BankAccessApi,
BankAccessApiClient,
} from "@gnu-taler/taler-wallet-core";
import {
ExchangesListResponse,
@ -266,10 +265,11 @@ export async function runExchangeManagementTest(
// Create withdrawal operation
const user = await BankApi.createRandomBankUser(bank);
const wop = await BankAccessApi.createWithdrawalOperation(
bank,
user,
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
const user = await bankClient.createRandomBankUser();
const wop = await bankClient.createWithdrawalOperation(
user.username,
"TESTKUDOS:10",
);

View File

@ -94,7 +94,6 @@ function getDenomInfoFromKeys(ek: ExchangeKeysJson): DenomInfo[] {
}
const http = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});

View File

@ -28,8 +28,7 @@ import {
} from "@gnu-taler/taler-util";
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import {
BankAccessApi,
BankApi,
BankAccessApiClient,
WalletApiOperation,
} from "@gnu-taler/taler-wallet-core";
import * as http from "node:http";
@ -305,9 +304,11 @@ export async function runKycTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
const amount = "TESTKUDOS:20";
const user = await BankApi.createRandomBankUser(bank);
const wop = await BankAccessApi.createWithdrawalOperation(bank, user, amount);
const user = await bankClient.createRandomBankUser();
const wop = await bankClient.createWithdrawalOperation(user.username, amount);
// Hand it to the wallet
@ -332,7 +333,7 @@ export async function runKycTest(t: GlobalTestState) {
// Confirm it
await BankApi.confirmWithdrawalOperation(bank, user, wop);
await bankClient.confirmWithdrawalOperation(user.username, wop);
const kycNotificationCond = walletClient.waitForNotificationCond((x) => {
if (
@ -376,7 +377,6 @@ export async function runKycTest(t: GlobalTestState) {
// which would usually done in the browser.
const httpLib = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});
const kycServerResp = await httpLib.fetch(kycUrl);

View File

@ -23,8 +23,7 @@
*/
import { CoreApiResponse, MerchantApiClient } from "@gnu-taler/taler-util";
import {
BankAccessApi,
BankApi,
BankAccessApiClient,
WalletApiOperation,
} from "@gnu-taler/taler-wallet-core";
import { defaultCoinConfig } from "../harness/denomStructures.js";
@ -127,10 +126,11 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Create withdrawal operation
const user = await BankApi.createRandomBankUser(bank);
const wop = await BankAccessApi.createWithdrawalOperation(
bank,
user,
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
const user = await bankClient.createRandomBankUser();
const wop = await bankClient.createWithdrawalOperation(
user.username,
"TESTKUDOS:20",
);
@ -152,7 +152,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Confirm it
await BankApi.confirmWithdrawalOperation(bank, user, wop);
await bankClient.confirmWithdrawalOperation(user.username, wop);
await wallet.runUntilDone();

View File

@ -38,10 +38,9 @@ export async function runTippingTest(t: GlobalTestState) {
const { walletClient, bank, exchange, merchant, exchangeBankAccount } =
await createSimpleTestkudosEnvironmentV2(t);
const bankAccessApiClient = new BankAccessApiClient({
allowHttp: true,
baseUrl: bank.bankAccessApiBaseUrl,
});
const bankAccessApiClient = new BankAccessApiClient(
bank.bankAccessApiBaseUrl,
);
const mbu = await bankAccessApiClient.createRandomBankUser();
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
@ -59,12 +58,15 @@ export async function runTippingTest(t: GlobalTestState) {
exchangeBankAccount.accountPaytoUri,
);
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
allowHttp: true,
});
const wireGatewayApiClient = new WireGatewayApiClient(
exchangeBankAccount.wireGatewayApiBaseUrl,
{
auth: {
username: exchangeBankAccount.accountName,
password: exchangeBankAccount.accountPassword,
},
},
);
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:10",

View File

@ -123,10 +123,9 @@ export async function runWalletNotificationsTest(t: GlobalTestState) {
skipDefaults: true,
});
const bankAccessApiClient = new BankAccessApiClient({
allowHttp: true,
baseUrl: bank.bankAccessApiBaseUrl,
});
const bankAccessApiClient = new BankAccessApiClient(
bank.bankAccessApiBaseUrl,
);
const user = await bankAccessApiClient.createRandomBankUser();
bankAccessApiClient.setAuth(user);
const wop = await bankAccessApiClient.createWithdrawalOperation(

View File

@ -36,10 +36,9 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) {
// Create a withdrawal operation
const bankAccessApiClient = new BankAccessApiClient({
allowHttp: true,
baseUrl: bank.bankAccessApiBaseUrl,
});
const bankAccessApiClient = new BankAccessApiClient(
bank.bankAccessApiBaseUrl,
);
const user = await bankAccessApiClient.createRandomBankUser();
bankAccessApiClient.setAuth(user);
const wop = await bankAccessApiClient.createWithdrawalOperation(

View File

@ -19,7 +19,10 @@
*/
import { GlobalTestState } from "../harness/harness.js";
import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js";
import { BankAccessApiClient, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import {
BankAccessApiClient,
WalletApiOperation,
} from "@gnu-taler/taler-wallet-core";
import {
j2s,
NotificationType,
@ -40,10 +43,9 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
// Create a withdrawal operation
const bankAccessApiClient = new BankAccessApiClient({
allowHttp: true,
baseUrl: bank.bankAccessApiBaseUrl,
});
const bankAccessApiClient = new BankAccessApiClient(
bank.bankAccessApiBaseUrl,
);
const user = await bankAccessApiClient.createRandomBankUser();
bankAccessApiClient.setAuth(user);
const wop = await bankAccessApiClient.createWithdrawalOperation(

View File

@ -110,10 +110,9 @@ export async function runWithdrawalFeesTest(t: GlobalTestState) {
const amount = "TESTKUDOS:7.5";
const bankAccessApiClient = new BankAccessApiClient({
allowHttp: true,
baseUrl: bank.bankAccessApiBaseUrl,
});
const bankAccessApiClient = new BankAccessApiClient(
bank.bankAccessApiBaseUrl,
);
const user = await bankAccessApiClient.createRandomBankUser();
bankAccessApiClient.setAuth(user);
const wop = await bankAccessApiClient.createWithdrawalOperation(

View File

@ -39,10 +39,9 @@ export async function runWithdrawalManualTest(t: GlobalTestState) {
// Create a withdrawal operation
const bankAccessApiClient = new BankAccessApiClient({
baseUrl: bank.bankAccessApiBaseUrl,
allowHttp: true,
});
const bankAccessApiClient = new BankAccessApiClient(
bank.bankAccessApiBaseUrl,
);
const user = await bankAccessApiClient.createRandomBankUser();
@ -74,12 +73,15 @@ export async function runWithdrawalManualTest(t: GlobalTestState) {
const reservePub: string = wres.reservePub;
const wireGatewayApiClient = new WireGatewayApiClient({
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
accountName: exchangeBankAccount.accountName,
accountPassword: exchangeBankAccount.accountPassword,
allowHttp: true,
});
const wireGatewayApiClient = new WireGatewayApiClient(
exchangeBankAccount.wireGatewayApiBaseUrl,
{
auth: {
username: exchangeBankAccount.accountName,
password: exchangeBankAccount.accountPassword,
},
},
);
await wireGatewayApiClient.adminAddIncoming({
amount: "TESTKUDOS:10",

View File

@ -55,7 +55,6 @@ interface PubkeyConf {
const httpLib = createPlatformHttpLib({
enableThrottling: false,
allowHttp: true,
});
interface ShellResult {

View File

@ -138,10 +138,7 @@ export class MerchantApiClient {
};
}
httpClient = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});
httpClient = createPlatformHttpLib();
async changeAuth(auth: MerchantAuthConfiguration): Promise<void> {
const url = new URL("private/auth", this.baseUrl);

View File

@ -436,7 +436,10 @@ export function getExpiry(
export interface HttpLibArgs {
enableThrottling?: boolean;
allowHttp?: boolean;
/**
* Only allow HTTPS connections, not plain http.
*/
requireTls?: boolean;
}
export function encodeBody(body: any): ArrayBuffer {

View File

@ -63,11 +63,11 @@ const textDecoder = new TextDecoder();
export class HttpLibImpl implements HttpRequestLibrary {
private throttle = new RequestThrottler();
private throttlingEnabled = true;
private allowHttp = false;
private requireTls = false;
constructor(args?: HttpLibArgs) {
this.throttlingEnabled = args?.enableThrottling ?? false;
this.allowHttp = args?.allowHttp ?? false;
this.requireTls = args?.requireTls ?? false;
}
/**
@ -94,7 +94,7 @@ export class HttpLibImpl implements HttpRequestLibrary {
`request to origin ${parsedUrl.origin} was throttled`,
);
}
if (!this.allowHttp && parsedUrl.protocol !== "https:") {
if (this.requireTls && parsedUrl.protocol !== "https:") {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_NETWORK_ERROR,
{

View File

@ -41,11 +41,11 @@ const textDecoder = new TextDecoder();
export class HttpLibImpl implements HttpRequestLibrary {
private throttle = new RequestThrottler();
private throttlingEnabled = true;
private allowHttp = false;
private requireTls = false;
constructor(args?: HttpLibArgs) {
this.throttlingEnabled = args?.enableThrottling ?? false;
this.allowHttp = args?.allowHttp ?? false;
this.requireTls = args?.requireTls ?? false;
}
/**
@ -72,7 +72,7 @@ export class HttpLibImpl implements HttpRequestLibrary {
`request to origin ${parsedUrl.origin} was throttled`,
);
}
if (!this.allowHttp && parsedUrl.protocol !== "https:") {
if (this.requireTls && parsedUrl.protocol !== "https:") {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_NETWORK_ERROR,
{

View File

@ -244,7 +244,7 @@ async function createLocalWallet(
const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
const myHttpLib = createPlatformHttpLib({
enableThrottling: walletCliArgs.wallet.noThrottle ? false : true,
allowHttp: walletCliArgs.wallet.noHttp ? false : true,
requireTls: walletCliArgs.wallet.noHttp,
});
const wallet = await createNativeWalletHost({
persistentStoragePath: dbPath !== ":memory:" ? dbPath : undefined,
@ -1259,10 +1259,7 @@ advancedCli
help: "Run the 'bench-internal' benchmark",
})
.action(async (args) => {
const myHttpLib = createPlatformHttpLib({
enableThrottling: false,
allowHttp: true,
});
const myHttpLib = createPlatformHttpLib();
const res = await createNativeWalletHost2({
// No persistent DB storage.
persistentStoragePath: undefined,

View File

@ -99,177 +99,9 @@ const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
.property("taler_withdraw_uri", codecForString())
.build("WithdrawalOperationInfo");
/**
* @deprecated Use BankAccessApiClient or WireGatewayApi
*/
export namespace BankApi {
// FIXME: Move to BankAccessApi?!
export async function registerAccount(
bank: BankServiceHandle,
username: string,
password: string,
options: {
iban?: string;
},
): Promise<BankUser> {
const url = new URL("testing/register", bank.bankAccessApiBaseUrl);
const resp = await bank.http.postJson(url.href, {
username,
password,
iban: options?.iban,
});
let paytoUri = `payto://x-taler-bank/localhost/${username}`;
if (resp.status !== 200 && resp.status !== 202 && resp.status !== 204) {
logger.error(`${j2s(await resp.json())}`);
throw TalerError.fromDetail(
TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
{
httpStatusCode: resp.status,
},
);
}
try {
// Pybank has no body, thus this might throw.
const respJson = await resp.json();
// LibEuFin demobank returns payto URI in response
if (respJson.paytoUri) {
paytoUri = respJson.paytoUri;
}
} catch (e) {
// Do nothing
}
return {
password,
username,
accountPaytoUri: paytoUri,
};
}
// FIXME: Move to BankAccessApi?!
export async function createRandomBankUser(
bank: BankServiceHandle,
): Promise<BankUser> {
const username = "user-" + encodeCrock(getRandomBytes(10)).toLowerCase();
const password = "pw-" + encodeCrock(getRandomBytes(10)).toLowerCase();
// FIXME: This is just a temporary workaround, because demobank is running out of short IBANs
const iban = generateIban("DE", 15);
return await registerAccount(bank, username, password, {
iban,
});
}
export async function confirmWithdrawalOperation(
bank: BankServiceHandle,
bankUser: BankUser,
wopi: WithdrawalOperationInfo,
): Promise<void> {
const url = new URL(
`accounts/${bankUser.username}/withdrawals/${wopi.withdrawal_id}/confirm`,
bank.bankAccessApiBaseUrl,
);
logger.info(`confirming withdrawal operation via ${url.href}`);
const resp = await bank.http.postJson(
url.href,
{},
{
headers: {
Authorization: makeBasicAuthHeader(
bankUser.username,
bankUser.password,
),
},
},
);
logger.info(`response status ${resp.status}`);
const respJson = await readSuccessResponseJsonOrThrow(resp, codecForAny());
// FIXME: We don't check the status here!
}
export async function abortWithdrawalOperation(
bank: BankServiceHandle,
bankUser: BankUser,
wopi: WithdrawalOperationInfo,
): Promise<void> {
const url = new URL(
`accounts/${bankUser.username}/withdrawals/${wopi.withdrawal_id}/abort`,
bank.bankAccessApiBaseUrl,
);
const resp = await bank.http.postJson(
url.href,
{},
{
headers: {
Authorization: makeBasicAuthHeader(
bankUser.username,
bankUser.password,
),
},
},
);
await readSuccessResponseJsonOrThrow(resp, codecForAny());
}
}
/**
* @deprecated use BankAccessApiClient
*/
export namespace BankAccessApi {
export async function getAccountBalance(
bank: BankServiceHandle,
bankUser: BankUser,
): Promise<BankAccountBalanceResponse> {
const url = new URL(
`accounts/${bankUser.username}`,
bank.bankAccessApiBaseUrl,
);
const resp = await bank.http.fetch(url.href, {
headers: {
Authorization: makeBasicAuthHeader(
bankUser.username,
bankUser.password,
),
},
});
return await resp.json();
}
export async function createWithdrawalOperation(
bank: BankServiceHandle,
bankUser: BankUser,
amount: string,
): Promise<WithdrawalOperationInfo> {
const url = new URL(
`accounts/${bankUser.username}/withdrawals`,
bank.bankAccessApiBaseUrl,
);
const resp = await bank.http.postJson(
url.href,
{
amount,
},
{
headers: {
Authorization: makeBasicAuthHeader(
bankUser.username,
bankUser.password,
),
},
},
);
return readSuccessResponseJsonOrThrow(
resp,
codecForWithdrawalOperationInfo(),
);
}
}
export interface BankAccessApiClientArgs {
baseUrl: string;
auth?: { username: string; password: string };
enableThrottling?: boolean;
allowHttp?: boolean;
httpClient?: HttpRequestLibrary;
}
export interface BankAccessApiCreateTransactionRequest {
@ -278,11 +110,11 @@ export interface BankAccessApiCreateTransactionRequest {
}
export class WireGatewayApiClientArgs {
accountName: string;
accountPassword: string;
wireGatewayApiBaseUrl: string;
enableThrottling?: boolean;
allowHttp?: boolean;
auth?: {
username: string;
password: string;
};
httpClient?: HttpRequestLibrary;
}
/**
@ -292,11 +124,21 @@ export class WireGatewayApiClientArgs {
export class WireGatewayApiClient {
httpLib;
constructor(private args: WireGatewayApiClientArgs) {
this.httpLib = createPlatformHttpLib({
enableThrottling: !!args.enableThrottling,
allowHttp: !!args.allowHttp,
});
constructor(
private baseUrl: string,
private args: WireGatewayApiClientArgs = {},
) {
this.httpLib = args.httpClient ?? createPlatformHttpLib();
}
private makeAuthHeader(): Record<string, string> {
const auth = this.args.auth;
if (auth) {
return {
Authorization: makeBasicAuthHeader(auth.username, auth.password),
};
}
return {};
}
async adminAddIncoming(params: {
@ -304,7 +146,7 @@ export class WireGatewayApiClient {
reservePub: string;
debitAccountPayto: string;
}): Promise<void> {
let url = new URL(`admin/add-incoming`, this.args.wireGatewayApiBaseUrl);
let url = new URL(`admin/add-incoming`, this.baseUrl);
const resp = await this.httpLib.fetch(url.href, {
method: "POST",
body: {
@ -312,12 +154,7 @@ export class WireGatewayApiClient {
reserve_pub: params.reservePub,
debit_account: params.debitAccountPayto,
},
headers: {
Authorization: makeBasicAuthHeader(
this.args.accountName,
this.args.accountPassword,
),
},
headers: this.makeAuthHeader(),
});
logger.info(`add-incoming response status: ${resp.status}`);
await checkSuccessResponseOrThrow(resp);
@ -331,11 +168,11 @@ export class WireGatewayApiClient {
export class BankAccessApiClient {
httpLib: HttpRequestLibrary;
constructor(private args: BankAccessApiClientArgs) {
this.httpLib = createPlatformHttpLib({
enableThrottling: !!args.enableThrottling,
allowHttp: !!args.allowHttp,
});
constructor(
private baseUrl: string,
private args: BankAccessApiClientArgs = {},
) {
this.httpLib = args.httpClient ?? createPlatformHttpLib();
}
setAuth(auth: { username: string; password: string }) {
@ -355,12 +192,18 @@ export class BankAccessApiClient {
};
}
async getAccountBalance(
username: string,
): Promise<BankAccountBalanceResponse> {
const url = new URL(`accounts/${username}`, this.baseUrl);
const resp = await this.httpLib.fetch(url.href, {
headers: this.makeAuthHeader(),
});
return await resp.json();
}
async getTransactions(username: string): Promise<void> {
const auth = this.args.auth;
const reqUrl = new URL(
`accounts/${username}/transactions`,
this.args.baseUrl,
);
const reqUrl = new URL(`accounts/${username}/transactions`, this.baseUrl);
const resp = await this.httpLib.fetch(reqUrl.href, {
method: "GET",
headers: {
@ -376,10 +219,7 @@ export class BankAccessApiClient {
username: string,
req: BankAccessApiCreateTransactionRequest,
): Promise<any> {
const reqUrl = new URL(
`accounts/${username}/transactions`,
this.args.baseUrl,
);
const reqUrl = new URL(`accounts/${username}/transactions`, this.baseUrl);
const resp = await this.httpLib.fetch(reqUrl.href, {
method: "POST",
@ -395,9 +235,9 @@ export class BankAccessApiClient {
password: string,
options: {
iban?: string;
},
} = {},
): Promise<BankUser> {
const url = new URL("testing/register", this.args.baseUrl);
const url = new URL("testing/register", this.baseUrl);
const resp = await this.httpLib.fetch(url.href, {
method: "POST",
body: {
@ -447,7 +287,7 @@ export class BankAccessApiClient {
user: string,
amount: string,
): Promise<WithdrawalOperationInfo> {
const url = new URL(`accounts/${user}/withdrawals`, this.args.baseUrl);
const url = new URL(`accounts/${user}/withdrawals`, this.baseUrl);
const resp = await this.httpLib.fetch(url.href, {
method: "POST",
body: {
@ -467,7 +307,7 @@ export class BankAccessApiClient {
): Promise<void> {
const url = new URL(
`accounts/${username}/withdrawals/${wopi.withdrawal_id}/confirm`,
this.args.baseUrl,
this.baseUrl,
);
logger.info(`confirming withdrawal operation via ${url.href}`);
const resp = await this.httpLib.fetch(url.href, {
@ -488,7 +328,7 @@ export class BankAccessApiClient {
): Promise<void> {
const url = new URL(
`accounts/${accountName}/withdrawals/${wopi.withdrawal_id}/abort`,
this.args.baseUrl,
this.baseUrl,
);
const resp = await this.httpLib.fetch(url.href, {
method: "POST",

View File

@ -48,24 +48,20 @@ import {
parsePaytoUri,
UnblindedSignature,
} from "@gnu-taler/taler-util";
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
import { DenominationRecord } from "./db.js";
import {
BankAccessApi,
BankApi,
BankServiceHandle,
} from "./bank-api-client.js";
import {
HttpRequestLibrary,
readSuccessResponseJsonOrThrow,
} from "@gnu-taler/taler-util/http";
import { BankAccessApiClient, BankServiceHandle } from "./bank-api-client.js";
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
import { DenominationRecord } from "./db.js";
import { isWithdrawableDenom } from "./index.js";
import { ExchangeInfo } from "./operations/exchanges.js";
import { assembleRefreshRevealRequest } from "./operations/refresh.js";
import {
getBankStatusUrl,
getBankWithdrawalInfo,
} from "./operations/withdraw.js";
import { ExchangeInfo } from "./operations/exchanges.js";
import { assembleRefreshRevealRequest } from "./operations/refresh.js";
import { isWithdrawableDenom, WalletConfig } from "./index.js";
const logger = new Logger("dbless.ts");
@ -125,10 +121,10 @@ export async function topupReserveWithDemobank(
bankAccessApiBaseUrl: bankAccessApiBaseUrl,
http,
};
const bankUser = await BankApi.createRandomBankUser(bankHandle);
const wopi = await BankAccessApi.createWithdrawalOperation(
bankHandle,
bankUser,
const bankClient = new BankAccessApiClient(bankAccessApiBaseUrl);
const bankUser = await bankClient.createRandomBankUser();
const wopi = await bankClient.createWithdrawalOperation(
bankUser.username,
amount,
);
const bankInfo = await getBankWithdrawalInfo(http, wopi.taler_withdraw_uri);
@ -149,7 +145,7 @@ export async function topupReserveWithDemobank(
httpResp,
codecForBankWithdrawalOperationPostResponse(),
);
await BankApi.confirmWithdrawalOperation(bankHandle, bankUser, wopi);
await bankClient.confirmWithdrawalOperation(bankUser.username, wopi);
}
export async function withdrawCoin(args: {

View File

@ -134,7 +134,7 @@ export async function createNativeWalletHost2(
} else {
myHttpLib = createPlatformHttpLib({
enableThrottling: true,
allowHttp: args.config?.features?.allowHttp,
requireTls: !args.config?.features?.allowHttp,
});
}

View File

@ -188,7 +188,7 @@ export async function createNativeWalletHost2(
} else {
myHttpLib = createPlatformHttpLib({
enableThrottling: true,
allowHttp: args.config?.features?.allowHttp,
requireTls: !args.config?.features?.allowHttp,
});
}