diff options
author | Florian Dold <florian@dold.me> | 2023-09-06 12:32:31 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-09-06 12:32:31 +0200 |
commit | 7450bede5b5809f6a496b7e68852a454386850e5 (patch) | |
tree | ce4aedaad43ad095e643d96f5897883b70616c03 | |
parent | 07d71eb29704a148f7e7bb0c064cbbad056d5a50 (diff) |
get rid of deprecated bank API client, change allowHttp to requireTls
30 files changed, 188 insertions, 372 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index 88f3bdbe2..89cf186dd 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -138,7 +138,6 @@ export * as validators from "./validators.js"; export * from "./challenge-feedback-types.js"; const httpLib = createPlatformHttpLib({ - allowHttp: true, enableThrottling: false, }); diff --git a/packages/taler-harness/src/bench2.ts b/packages/taler-harness/src/bench2.ts index 48ac76b9f..53db6f6c1 100644 --- a/packages/taler-harness/src/bench2.ts +++ b/packages/taler-harness/src/bench2.ts @@ -57,7 +57,6 @@ export async function runBench2(configJson: any): Promise<void> { const http = createPlatformHttpLib({ enableThrottling: false, - allowHttp: true, }); const numIter = benchConf.iterations ?? 1; diff --git a/packages/taler-harness/src/bench3.ts b/packages/taler-harness/src/bench3.ts index c7eca90a8..0b5371af5 100644 --- a/packages/taler-harness/src/bench3.ts +++ b/packages/taler-harness/src/bench3.ts @@ -52,7 +52,6 @@ export async function runBench3(configJson: any): Promise<void> { const myHttpLib = createPlatformHttpLib({ enableThrottling: false, - allowHttp: true, }); const numIter = b3conf.iterations ?? 1; diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index df3c9b215..d0719b4f7 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -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, }); diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts index 7b2f7d8f1..f92fd4dd9 100644 --- a/packages/taler-harness/src/harness/helpers.ts +++ b/packages/taler-harness/src/harness/helpers.ts @@ -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, diff --git a/packages/taler-harness/src/harness/libeufin-apis.ts b/packages/taler-harness/src/harness/libeufin-apis.ts index 0553223cb..0193f9252 100644 --- a/packages/taler-harness/src/harness/libeufin-apis.ts +++ b/packages/taler-harness/src/harness/libeufin-apis.ts @@ -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 diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index ed2e545f7..185f6226d 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -236,14 +236,15 @@ deploymentCli console.log(tipReserveResp); - const bankAccessApiClient = new BankAccessApiClient({ - baseUrl: args.tipTopup.bankAccessUrl, - auth: { - username: args.tipTopup.bankAccount, - password: args.tipTopup.bankPassword, + 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}`, diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts index 4e096e0ea..bff13ae40 100644 --- a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts +++ b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts @@ -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", diff --git a/packages/taler-harness/src/integrationtests/test-bank-api.ts b/packages/taler-harness/src/integrationtests/test-bank-api.ts index e645d60f1..afb06b61a 100644 --- a/packages/taler-harness/src/integrationtests/test-bank-api.ts +++ b/packages/taler-harness/src/integrationtests/test-bank-api.ts @@ -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, diff --git a/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts b/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts index 05bbbfaa1..96255f5b5 100644 --- a/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts +++ b/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts @@ -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( diff --git a/packages/taler-harness/src/integrationtests/test-exchange-management.ts b/packages/taler-harness/src/integrationtests/test-exchange-management.ts index 718cee0d7..19be7c962 100644 --- a/packages/taler-harness/src/integrationtests/test-exchange-management.ts +++ b/packages/taler-harness/src/integrationtests/test-exchange-management.ts @@ -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", ); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts b/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts index 401cc4ff2..2ef7683b3 100644 --- a/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts +++ b/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts @@ -94,7 +94,6 @@ function getDenomInfoFromKeys(ek: ExchangeKeysJson): DenomInfo[] { } const http = createPlatformHttpLib({ - allowHttp: true, enableThrottling: false, }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc.ts b/packages/taler-harness/src/integrationtests/test-kyc.ts index 22c8ce03c..88875d4fc 100644 --- a/packages/taler-harness/src/integrationtests/test-kyc.ts +++ b/packages/taler-harness/src/integrationtests/test-kyc.ts @@ -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); diff --git a/packages/taler-harness/src/integrationtests/test-payment-fault.ts b/packages/taler-harness/src/integrationtests/test-payment-fault.ts index 70fa587e7..3ad11d82d 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-fault.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-fault.ts @@ -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(); diff --git a/packages/taler-harness/src/integrationtests/test-tipping.ts b/packages/taler-harness/src/integrationtests/test-tipping.ts index f4a7c020e..9b980acad 100644 --- a/packages/taler-harness/src/integrationtests/test-tipping.ts +++ b/packages/taler-harness/src/integrationtests/test-tipping.ts @@ -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", diff --git a/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts b/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts index 3315a71d4..9b35884f0 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts @@ -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( diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-abort-bank.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-abort-bank.ts index 1ba180fc1..c62b98623 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-abort-bank.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-abort-bank.ts @@ -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( diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts index 61687ec02..76c973a12 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts @@ -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( diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts index 34dfb8fc9..9f4631c7e 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts @@ -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( diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts index d49235f89..324b8abc5 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts @@ -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", diff --git a/packages/taler-harness/src/lint.ts b/packages/taler-harness/src/lint.ts index 6d8e679db..a45e6db9d 100644 --- a/packages/taler-harness/src/lint.ts +++ b/packages/taler-harness/src/lint.ts @@ -55,7 +55,6 @@ interface PubkeyConf { const httpLib = createPlatformHttpLib({ enableThrottling: false, - allowHttp: true, }); interface ShellResult { diff --git a/packages/taler-util/src/MerchantApiClient.ts b/packages/taler-util/src/MerchantApiClient.ts index cf4788d9e..cbdcb9fdf 100644 --- a/packages/taler-util/src/MerchantApiClient.ts +++ b/packages/taler-util/src/MerchantApiClient.ts @@ -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); diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts index 93cf9bba0..02ec8ce72 100644 --- a/packages/taler-util/src/http-common.ts +++ b/packages/taler-util/src/http-common.ts @@ -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 { diff --git a/packages/taler-util/src/http-impl.node.ts b/packages/taler-util/src/http-impl.node.ts index 07648a28d..528d303be 100644 --- a/packages/taler-util/src/http-impl.node.ts +++ b/packages/taler-util/src/http-impl.node.ts @@ -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, { diff --git a/packages/taler-util/src/http-impl.qtart.ts b/packages/taler-util/src/http-impl.qtart.ts index 3e076e96d..fb642ac89 100644 --- a/packages/taler-util/src/http-impl.qtart.ts +++ b/packages/taler-util/src/http-impl.qtart.ts @@ -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, { diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index a0f44fb41..943283a36 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -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, diff --git a/packages/taler-wallet-core/src/bank-api-client.ts b/packages/taler-wallet-core/src/bank-api-client.ts index 3174667f1..f1289525d 100644 --- a/packages/taler-wallet-core/src/bank-api-client.ts +++ b/packages/taler-wallet-core/src/bank-api-client.ts @@ -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", diff --git a/packages/taler-wallet-core/src/dbless.ts b/packages/taler-wallet-core/src/dbless.ts index 5532345ae..357b7d289 100644 --- a/packages/taler-wallet-core/src/dbless.ts +++ b/packages/taler-wallet-core/src/dbless.ts @@ -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: { diff --git a/packages/taler-wallet-core/src/host-impl.node.ts b/packages/taler-wallet-core/src/host-impl.node.ts index 0626b9254..a6dae58a1 100644 --- a/packages/taler-wallet-core/src/host-impl.node.ts +++ b/packages/taler-wallet-core/src/host-impl.node.ts @@ -134,7 +134,7 @@ export async function createNativeWalletHost2( } else { myHttpLib = createPlatformHttpLib({ enableThrottling: true, - allowHttp: args.config?.features?.allowHttp, + requireTls: !args.config?.features?.allowHttp, }); } diff --git a/packages/taler-wallet-core/src/host-impl.qtart.ts b/packages/taler-wallet-core/src/host-impl.qtart.ts index 81dbe0acd..85f8df6e5 100644 --- a/packages/taler-wallet-core/src/host-impl.qtart.ts +++ b/packages/taler-wallet-core/src/host-impl.qtart.ts @@ -188,7 +188,7 @@ export async function createNativeWalletHost2( } else { myHttpLib = createPlatformHttpLib({ enableThrottling: true, - allowHttp: args.config?.features?.allowHttp, + requireTls: !args.config?.features?.allowHttp, }); } |