commit e64c5ed603c02ef3b5afb42daaca89c0c9f674eb parent 513bf5480ebe99f3a12fefa8d43ba54a7f6489f3 Author: Florian Dold <florian@dold.me> Date: Tue, 15 Apr 2025 16:56:35 +0200 harness,util: get rid of duplicate wire gateway API client Diffstat:
43 files changed, 521 insertions(+), 514 deletions(-)
diff --git a/packages/merchant-backoffice-ui/src/hooks/testing.tsx b/packages/merchant-backoffice-ui/src/hooks/testing.tsx @@ -19,26 +19,35 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { + TalerBankIntegrationHttpClient, + TalerCoreBankHttpClient, + TalerRevenueHttpClient, + TalerWireGatewayHttpClient, +} from "@gnu-taler/taler-util"; +import { + HttpRequestLibrary, + HttpRequestOptions, + HttpResponse, +} from "@gnu-taler/taler-util/http"; +import { ApiContextProvider } from "@gnu-taler/web-util/browser"; import { MockEnvironment } from "@gnu-taler/web-util/testing"; import { ComponentChildren, FunctionalComponent, h, VNode } from "preact"; -import { HttpRequestLibrary, HttpRequestOptions, HttpResponse } from "@gnu-taler/taler-util/http"; import { SWRConfig } from "swr"; -import { ApiContextProvider } from "@gnu-taler/web-util/browser"; -import { TalerBankIntegrationHttpClient, TalerCoreBankHttpClient, TalerRevenueHttpClient, TalerWireGatewayHttpClient } from "@gnu-taler/taler-util"; interface RequestOptions { - method?: "GET" | "POST" | "HEAD", - params?: any, - token?: string | undefined, - data?: any, + method?: "GET" | "POST" | "HEAD"; + params?: any; + token?: string | undefined; + data?: any; } interface HttpResponseOk<T> { - ok: true, - data: T, - loading: boolean, - clientError: boolean, - serverError: boolean, - info: any, + ok: true; + data: T; + loading: boolean; + clientError: boolean; + serverError: boolean; + info: any; } export class ApiMockEnvironment extends MockEnvironment { @@ -61,7 +70,6 @@ export class ApiMockEnvironment extends MockEnvironment { }: { children: ComponentChildren; }): VNode { - async function request<T>( base: string, path: string, @@ -104,8 +112,11 @@ export class ApiMockEnvironment extends MockEnvironment { } const SC: any = SWRConfig; - const mockHttpClient = new class implements HttpRequestLibrary { - async fetch(url: string, options?: HttpRequestOptions | undefined): Promise<HttpResponse> { + const mockHttpClient = new (class implements HttpRequestLibrary { + async fetch( + url: string, + options?: HttpRequestOptions | undefined, + ): Promise<HttpResponse> { const _url = new URL(url); const mocked = __SAVE_REQUEST_AND_GET_MOCKED_RESPONSE( { @@ -132,7 +143,7 @@ export class ApiMockEnvironment extends MockEnvironment { text: async () => responsePayload as any as string, bytes: async () => responsePayload as ArrayBuffer, }; - return resp + return resp; } get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> { return this.fetch(url, { @@ -153,12 +164,25 @@ export class ApiMockEnvironment extends MockEnvironment { ...opt, }); } - - } - const bankCore = new TalerCoreBankHttpClient("http://localhost", mockHttpClient) - const bankIntegration = new TalerBankIntegrationHttpClient(bankCore.getIntegrationAPI().href, mockHttpClient) - const bankRevenue = new TalerRevenueHttpClient(bankCore.getRevenueAPI("a").href, mockHttpClient) - const bankWire = new TalerWireGatewayHttpClient(bankCore.getWireGatewayAPI("b").href, "b", mockHttpClient) + })(); + const bankCore = new TalerCoreBankHttpClient( + "http://localhost", + mockHttpClient, + ); + const bankIntegration = new TalerBankIntegrationHttpClient( + bankCore.getIntegrationAPI().href, + mockHttpClient, + ); + const bankRevenue = new TalerRevenueHttpClient( + bankCore.getRevenueAPI("a").href, + mockHttpClient, + ); + const bankWire = new TalerWireGatewayHttpClient( + bankCore.getWireGatewayAPI("b").href, + { + httpClient: mockHttpClient, + }, + ); return ( // <BackendContextProvider defaultUrl="http://backend"> @@ -170,20 +194,28 @@ export class ApiMockEnvironment extends MockEnvironment { // changeToken: () => null, // }} // > - <ApiContextProvider value={{ request : undefined as any, bankCore, bankIntegration, bankRevenue, bankWire }}> - <SC - value={{ - loadingTimeout: 0, - dedupingInterval: 0, - shouldRetryOnError: false, - errorRetryInterval: 0, - errorRetryCount: 0, - provider: () => new Map(), - }} - > - {children} - </SC> - </ApiContextProvider> + <ApiContextProvider + value={{ + request: undefined as any, + bankCore, + bankIntegration, + bankRevenue, + bankWire, + }} + > + <SC + value={{ + loadingTimeout: 0, + dedupingInterval: 0, + shouldRetryOnError: false, + errorRetryInterval: 0, + errorRetryCount: 0, + provider: () => new Map(), + }} + > + {children} + </SC> + </ApiContextProvider> // </InstanceContextProvider> // </BackendContextProvider> ); diff --git a/packages/taler-harness/src/env1.ts b/packages/taler-harness/src/env1.ts @@ -50,8 +50,10 @@ export async function runEnv1(t: GlobalTestState): Promise<void> { }); exchange.addBankAccount("1", { - accountName: "exchange", - accountPassword: "password", + wireGatewayAuth: { + username: "exchange", + password: "password", + }, wireGatewayApiBaseUrl: new URL("/exchange/", bank.baseUrl).href, accountPaytoUri: "payto://x-taler-bank/localhost/exchange", }); diff --git a/packages/taler-harness/src/harness/environments.ts b/packages/taler-harness/src/harness/environments.ts @@ -46,7 +46,6 @@ import { succeedOrThrow, TalerCorebankApiClient, TalerCoreBankHttpClient, - TalerExchangeApi, TalerExchangeHttpClient, TalerMerchantApi, TalerMerchantInstanceHttpClient, @@ -56,7 +55,6 @@ import { TransactionMajorState, TransactionMinorState, WalletNotification, - WireGatewayApiClient, } from "@gnu-taler/taler-util"; import { createSyncCryptoApi, @@ -92,7 +90,6 @@ import { } from "./harness.js"; import * as fs from "node:fs"; -import { deprecate } from "node:util"; const logger = new Logger("helpers.ts"); @@ -506,8 +503,10 @@ export async function createSimpleTestkudosEnvironmentV3( const exchangeBankAccount: HarnessExchangeBankAccount = { wireGatewayApiBaseUrl, - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, accountPaytoUri: exchangePaytoUri, skipWireFeeCreation: opts.skipWireFeeCreation === true, accountRestrictions: opts.accountRestrictions, @@ -1097,10 +1096,6 @@ export interface KycTestEnv { walletService: WalletService; amlKeypair: EddsaKeyPairStrings; merchant: MerchantService; - /** - * @deprecated - */ - wireGatewayApiClient: WireGatewayApiClient; bankApi: TalerCoreBankHttpClient; exchangeApi: TalerExchangeHttpClient; wireGatewayApi: TalerWireGatewayHttpClient; @@ -1145,8 +1140,10 @@ export async function createKycTestkudosEnvironment( ).href; await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl, accountPaytoUri: exchangePaytoUri, }); @@ -1238,22 +1235,14 @@ export async function createKycTestkudosEnvironment( }); const exchangeBankAccount: HarnessExchangeBankAccount = { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, accountPaytoUri: exchangePaytoUri, wireGatewayApiBaseUrl, }; - const wireGatewayApiClient = new WireGatewayApiClient( - exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: exchangeBankAccount.accountName, - password: exchangeBankAccount.accountPassword, - }, - }, - ); - t.logStep("env-setup-done"); const bankApi = new TalerCoreBankHttpClient( @@ -1262,9 +1251,12 @@ export async function createKycTestkudosEnvironment( ); const wireGatewayApi = new TalerWireGatewayHttpClient( - bankApi.getWireGatewayAPI(exchangeBankAccount.accountName).href, - exchangeBankAccount.accountName, - harnessHttpLib, + bankApi.getWireGatewayAPI( + exchangeBankAccount.wireGatewayAuth.username, + ).href, + { + httpClient: harnessHttpLib, + }, ); const merchantApi = new TalerMerchantInstanceHttpClient( @@ -1286,7 +1278,6 @@ export async function createKycTestkudosEnvironment( bankClient, exchangeBankAccount, merchant, - wireGatewayApiClient, bankApi, wireGatewayApi, merchantApi, diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts @@ -45,10 +45,11 @@ import { TalerMerchantApi, TalerMerchantManagementHttpClient, TalerProtocolDuration, + TalerWireGatewayAuth, + TalerWireGatewayHttpClient, Transaction, TransactionIdStr, WalletNotification, - WireGatewayApiClient, codecForAccountKycRedirects, codecForQueryInstancesResponse, createEddsaKeyPair, @@ -655,18 +656,14 @@ export type HarnessAccountRestriction = | [RestrictionFlag, "regex", string, string, string]; export interface HarnessExchangeBankAccount { - accountName: string; - accountPassword: string; accountPaytoUri: string; wireGatewayApiBaseUrl: string; - + wireGatewayAuth: TalerWireGatewayAuth; conversionUrl?: string; - /** * If set, the harness will not automatically configure the wire fee for this account. */ skipWireFeeCreation?: boolean; - accountRestrictions?: HarnessAccountRestriction[]; } @@ -767,8 +764,10 @@ export class FakebankService accountPassword: password, }); return { - accountName: accountName, - accountPassword: password, + wireGatewayAuth: { + username: accountName, + password, + }, accountPaytoUri: getTestHarnessPaytoForLabel(accountName), wireGatewayApiBaseUrl: `http://localhost:${this.bankConfig.httpPort}/accounts/${accountName}/taler-wire-gateway/`, }; @@ -1347,12 +1346,12 @@ export class ExchangeService implements ExchangeServiceInterface { config.setString( `exchange-accountcredentials-${localName}`, "username", - exchangeBankAccount.accountName, + exchangeBankAccount.wireGatewayAuth.username, ); config.setString( `exchange-accountcredentials-${localName}`, "password", - exchangeBankAccount.accountPassword, + exchangeBankAccount.wireGatewayAuth.password, ); config.writeTo(this.configFilename, { excludeDefaults: true }); } @@ -2564,6 +2563,7 @@ export async function doMerchantKycAuth( t: GlobalTestState, req: { exchangeBankAccount: HarnessExchangeBankAccount; + wireGatewayAuth: TalerWireGatewayAuth; merchant: MerchantServiceInterface; bankClient: TalerCorebankApiClient; }, @@ -2582,14 +2582,8 @@ export async function doMerchantKycAuth( accountPub = parsedResp.merchant_pub; } - const wireGatewayApiClient = new WireGatewayApiClient( + const wireGatewayApiClient = new TalerWireGatewayHttpClient( req.exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: req.exchangeBankAccount.accountName, - password: req.exchangeBankAccount.accountPassword, - }, - }, ); let kycRespOne: MerchantAccountKycRedirectsResponse | undefined = undefined; @@ -2624,10 +2618,13 @@ export async function doMerchantKycAuth( username: "merchant-default", payto_uri: kycRespOne.kyc_data[0].payto_uri, //this bank user needs to have the same payto that the exchange is asking from }); - await wireGatewayApiClient.adminAddKycauth({ - amount: "TESTKUDOS:0.1", - debitAccountPayto: kycRespOne.kyc_data[0].payto_uri, - accountPub, + await wireGatewayApiClient.addKycAuth({ + auth: req.wireGatewayAuth, + body: { + amount: "TESTKUDOS:0.1", + debit_account: kycRespOne.kyc_data[0].payto_uri, + account_pub: accountPub, + }, }); let kycRespTwo: MerchantAccountKycRedirectsResponse | undefined = undefined; diff --git a/packages/taler-harness/src/integrationtests/test-bank-api.ts b/packages/taler-harness/src/integrationtests/test-bank-api.ts @@ -18,9 +18,9 @@ * Imports. */ import { - TalerCorebankApiClient, CreditDebitIndicator, - WireGatewayApiClient, + TalerCorebankApiClient, + TalerWireGatewayHttpClient, createEddsaKeyPair, encodeCrock, } from "@gnu-taler/taler-util"; @@ -66,14 +66,17 @@ export async function runBankApiTest(t: GlobalTestState) { let exchangeBankUsername = "exchange"; let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); + let wireGatewayAuth = { + username: exchangeBankUsername, + password: exchangeBankPassword, + }; let wireGatewayApiBaseUrl = new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, ).href; await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth, wireGatewayApiBaseUrl, accountPaytoUri: exchangePaytoUri, }); @@ -128,7 +131,7 @@ export async function runBankApiTest(t: GlobalTestState) { // Make sure that registering twice results in a 409 Conflict { const e = await t.assertThrowsTalerErrorAsync( - bankClient.registerAccount("user1", "password2") + bankClient.registerAccount("user1", "password2"), ); t.assertTrue(e.errorDetail.httpStatusCode === 409); } @@ -145,17 +148,17 @@ export async function runBankApiTest(t: GlobalTestState) { const res = createEddsaKeyPair(); - const wireGatewayApiClient = new WireGatewayApiClient(wireGatewayApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const wireGatewayApiClient = new TalerWireGatewayHttpClient( + wireGatewayApiBaseUrl, + ); - await wireGatewayApiClient.adminAddIncoming({ - amount: "TESTKUDOS:115", - debitAccountPayto: bankUser.accountPaytoUri, - reservePub: encodeCrock(res.eddsaPub), + await wireGatewayApiClient.addIncoming({ + auth: wireGatewayAuth, + body: { + amount: "TESTKUDOS:115", + debit_account: bankUser.accountPaytoUri, + reserve_pub: encodeCrock(res.eddsaPub), + }, }); balResp = await bankClient.getAccountBalance(bankUser.username); diff --git a/packages/taler-harness/src/integrationtests/test-currency-scope.ts b/packages/taler-harness/src/integrationtests/test-currency-scope.ts @@ -83,8 +83,10 @@ export async function runCurrencyScopeTest(t: GlobalTestState) { "accounts/myexchange/taler-wire-gateway/", bank.corebankApiBaseUrl, ).href, - accountName: "myexchange", - accountPassword: "password", + wireGatewayAuth: { + username: "myexchange", + password: "password", + }, accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), }; @@ -93,8 +95,10 @@ export async function runCurrencyScopeTest(t: GlobalTestState) { "accounts/myexchange2/taler-wire-gateway/", bank.corebankApiBaseUrl, ).href, - accountName: "myexchange2", - accountPassword: "password", + wireGatewayAuth: { + username: "myexchange2", + password: "password", + }, accountPaytoUri: getTestHarnessPaytoForLabel("myexchange2"), }; @@ -115,18 +119,18 @@ export async function runCurrencyScopeTest(t: GlobalTestState) { }); await bankClient.registerAccountExtended({ - name: exchangeOneBankAccount.accountName, - username: exchangeOneBankAccount.accountName, - password: exchangeOneBankAccount.accountPassword, + name: exchangeOneBankAccount.wireGatewayAuth.username, + username: exchangeOneBankAccount.wireGatewayAuth.username, + password: exchangeOneBankAccount.wireGatewayAuth.password, is_taler_exchange: true, payto_uri: exchangeOneBankAccount.accountPaytoUri, }); await exchangeOne.addBankAccount("1", exchangeOneBankAccount); await bankClient.registerAccountExtended({ - name: exchangeTwoBankAccount.accountName, - username: exchangeTwoBankAccount.accountName, - password: exchangeTwoBankAccount.accountPassword, + name: exchangeTwoBankAccount.wireGatewayAuth.username, + username: exchangeTwoBankAccount.wireGatewayAuth.username, + password: exchangeTwoBankAccount.wireGatewayAuth.password, is_taler_exchange: true, payto_uri: exchangeTwoBankAccount.accountPaytoUri, }); diff --git a/packages/taler-harness/src/integrationtests/test-deposit-fault.ts b/packages/taler-harness/src/integrationtests/test-deposit-fault.ts @@ -74,8 +74,10 @@ export async function runDepositFaultTest(t: GlobalTestState) { let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-exchange-management-fault.ts b/packages/taler-harness/src/integrationtests/test-exchange-management-fault.ts @@ -76,8 +76,10 @@ export async function runExchangeManagementFaultTest( let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, @@ -192,7 +194,7 @@ export async function runExchangeManagementFaultTest( const err1 = await t.assertThrowsTalerErrorAsync( wallet.client.call(WalletApiOperation.AddExchange, { exchangeBaseUrl: faultyExchange.baseUrl, - }) + }), ); console.log("got error", err1); @@ -240,7 +242,7 @@ export async function runExchangeManagementFaultTest( const err2 = await t.assertThrowsTalerErrorAsync( wallet.client.call(WalletApiOperation.AddExchange, { exchangeBaseUrl: faultyExchange.baseUrl, - }) + }), ); t.assertTrue(err2.hasErrorCode(TalerErrorCode.WALLET_EXCHANGE_UNAVAILABLE)); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts b/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts @@ -130,8 +130,10 @@ export async function runExchangeTimetravelTest(t: GlobalTestState) { let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-fee-regression.ts b/packages/taler-harness/src/integrationtests/test-fee-regression.ts @@ -23,19 +23,20 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { + SimpleTestEnvironmentNg3, + createWalletDaemonWithClient, + makeTestPaymentV2, + withdrawViaBankV3, +} from "../harness/environments.js"; +import { BankService, ExchangeService, GlobalTestState, + HarnessExchangeBankAccount, MerchantService, getTestHarnessPaytoForLabel, setupDb, } from "../harness/harness.js"; -import { - SimpleTestEnvironmentNg3, - createWalletDaemonWithClient, - makeTestPaymentV2, - withdrawViaBankV3, -} from "../harness/environments.js"; /** * Run a test case with a simple TESTKUDOS Taler environment, consisting @@ -71,15 +72,19 @@ export async function createMyTestkudosEnvironment( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + const exchangeBankAccount: HarnessExchangeBankAccount = { + wireGatewayAuth: { + password: exchangeBankPassword, + username: exchangeBankUsername, + }, + accountPaytoUri: exchangePaytoUri, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, ).href, - accountPaytoUri: exchangePaytoUri, - }); + }; + + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); @@ -189,12 +194,7 @@ export async function createMyTestkudosEnvironment( walletService, bankClient, bank, - exchangeBankAccount: { - accountName: "", - accountPassword: "", - accountPaytoUri: "", - wireGatewayApiBaseUrl: "", - }, + exchangeBankAccount, }; } diff --git a/packages/taler-harness/src/integrationtests/test-kyc-balance-withdrawal.ts b/packages/taler-harness/src/integrationtests/test-kyc-balance-withdrawal.ts @@ -87,15 +87,19 @@ async function createKycTestkudosEnvironment( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + const exchangeBankAccount: HarnessExchangeBankAccount = { + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, ).href, accountPaytoUri: exchangePaytoUri, - }); + } + + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); @@ -179,12 +183,7 @@ async function createKycTestkudosEnvironment( walletClient, walletService, bankClient, - exchangeBankAccount: { - accountName: "", - accountPassword: "", - accountPaytoUri: "", - wireGatewayApiBaseUrl: "", - }, + exchangeBankAccount, }; } diff --git a/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts b/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts @@ -28,9 +28,9 @@ import { j2s, LimitOperationType, TalerProtocolTimestamp, + TalerWireGatewayHttpClient, TransactionMajorState, TransactionMinorState, - WireGatewayApiClient, } from "@gnu-taler/taler-util"; import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; import { @@ -83,14 +83,8 @@ export async function runKycDecisionsTest(t: GlobalTestState) { const cryptoApi = createSyncCryptoApi(); - const wireGatewayApiClient = new WireGatewayApiClient( + const wireGatewayApiClient = new TalerWireGatewayHttpClient( exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: exchangeBankAccount.accountName, - password: exchangeBankAccount.accountPassword, - }, - }, ); const merchantPair = await cryptoApi.createEddsaKeypair({}); @@ -165,10 +159,13 @@ export async function runKycDecisionsTest(t: GlobalTestState) { }, }); - await wireGatewayApiClient.adminAddKycauth({ - amount: "TESTKUDOS:0.1", - debitAccountPayto: merchantPayto, - accountPub: merchantPair.pub, + await wireGatewayApiClient.addKycAuth({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:0.1", + debit_account: merchantPayto, + account_pub: merchantPair.pub, + }, }); let checkResp: AccountKycStatus | undefined; diff --git a/packages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate.ts b/packages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate.ts @@ -45,7 +45,7 @@ function adjustExchangeConfig(config: Configuration): void { config.setString("KYC-MEASURE-M1", "check_name", "C1"); config.setString("KYC-MEASURE-M1", "context", "{}"); - config.setString("KYC-MEASURE-M1", "program", "NONE");; + config.setString("KYC-MEASURE-M1", "program", "NONE"); config.setString("KYC-CHECK-C1", "type", "INFO"); config.setString("KYC-CHECK-C1", "description", "my check!"); @@ -59,8 +59,9 @@ export async function runKycDepositAggregateTest(t: GlobalTestState) { walletClient, bankClient, exchange, + exchangeBankAccount, + wireGatewayApi, amlKeypair, - wireGatewayApiClient, } = await createKycTestkudosEnvironment(t, { adjustExchangeConfig, }); @@ -101,10 +102,13 @@ export async function runKycDepositAggregateTest(t: GlobalTestState) { t.assertDeepEqual(depositTx.type, TransactionType.Deposit); - await wireGatewayApiClient.adminAddKycauth({ - amount: "TESTKUDOS:0.1", - debitAccountPayto: wres.accountPaytoUri, - accountPub: depositTx.accountPub, + await wireGatewayApi.addKycAuth({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:0.1", + debit_account: wres.accountPaytoUri, + account_pub: depositTx.accountPub, + }, }); await exchange.runWirewatchOnce(); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-deposit-deposit-kyctransfer.ts b/packages/taler-harness/src/integrationtests/test-kyc-deposit-deposit-kyctransfer.ts @@ -24,7 +24,6 @@ import { TransactionMajorState, TransactionMinorState, TransactionType, - WireGatewayApiClient, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { @@ -69,6 +68,7 @@ export async function runKycDepositDepositKyctransferTest(t: GlobalTestState) { exchange, amlKeypair, exchangeBankAccount, + wireGatewayApi, } = await createKycTestkudosEnvironment(t, { adjustExchangeConfig, }); @@ -114,16 +114,6 @@ export async function runKycDepositDepositKyctransferTest(t: GlobalTestState) { t.logStep("kyc-auth-requested"); - const wireGatewayApiClient = new WireGatewayApiClient( - exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: "admin", - password: "admin-password", - }, - }, - ); - { const txDetails = await walletClient.call( WalletApiOperation.GetTransactionById, @@ -146,10 +136,13 @@ export async function runKycDepositDepositKyctransferTest(t: GlobalTestState) { logger.info(`account pub: ${kycTx.accountPub}`); - await wireGatewayApiClient.adminAddKycauth({ - amount: "TESTKUDOS:0.1", - debitAccountPayto: depositPaytoUri, - accountPub: kycTx.accountPub, + await wireGatewayApi.addKycAuth({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:0.1", + debit_account: depositPaytoUri, + account_pub: kycTx.accountPub, + }, }); } diff --git a/packages/taler-harness/src/integrationtests/test-kyc-merchant-activate-bank-account.ts b/packages/taler-harness/src/integrationtests/test-kyc-merchant-activate-bank-account.ts @@ -20,12 +20,10 @@ import { codecForAccountKycRedirects, codecForQueryInstancesResponse, - Configuration, j2s, Logger, MerchantAccountKycRedirectsResponse, parsePaytoUri, - WireGatewayApiClient, } from "@gnu-taler/taler-util"; import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; import { createKycTestkudosEnvironment } from "../harness/environments.js"; @@ -41,7 +39,7 @@ export async function runKycMerchantActivateBankAccountTest( t: GlobalTestState, ) { // Set up test environment - const { merchant, bankClient, exchangeBankAccount } = + const { merchant, bankClient, exchangeBankAccount, wireGatewayApi } = await createKycTestkudosEnvironment(t, { adjustExchangeConfig(config) { config.setString("exchange", "enable_kyc", "yes"); @@ -105,16 +103,6 @@ export async function runKycMerchantActivateBankAccountTest( payto_uri: kycRespOne.kyc_data[0].payto_uri, //this bank user needs to have the same payto that the exchange is asking from }); - const wireGatewayApiClient = new WireGatewayApiClient( - exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: "admin", - password: "admin-password", - }, - }, - ); - const kycauthPayto = kycRespOne.kyc_data[0].payto_kycauths![0]; logger.info(`kycauth payto: ${kycauthPayto}`); const p = parsePaytoUri(kycauthPayto); @@ -126,10 +114,13 @@ export async function runKycMerchantActivateBankAccountTest( // what looks like a public key from the message. t.assertDeepEqual(`KYC:${accountPub}`, msgAccountPub); - await wireGatewayApiClient.adminAddKycauth({ - amount: "TESTKUDOS:0.1", - debitAccountPayto: kycRespOne.kyc_data[0].payto_uri, - accountPub, + await wireGatewayApi.addKycAuth({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:0.1", + debit_account: kycRespOne.kyc_data[0].payto_uri, + account_pub: accountPub, + }, }); let kycRespTwo: MerchantAccountKycRedirectsResponse | undefined = undefined; diff --git a/packages/taler-harness/src/integrationtests/test-kyc-merchant-aggregate.ts b/packages/taler-harness/src/integrationtests/test-kyc-merchant-aggregate.ts @@ -77,6 +77,7 @@ export async function runKycMerchantAggregateTest(t: GlobalTestState) { bankClient, exchangeBankAccount, merchant, + wireGatewayAuth: exchangeBankAccount.wireGatewayAuth, }); await makeTestPaymentV2(t, { diff --git a/packages/taler-harness/src/integrationtests/test-kyc-merchant-deposit-rewrite.ts b/packages/taler-harness/src/integrationtests/test-kyc-merchant-deposit-rewrite.ts @@ -175,10 +175,13 @@ export async function runKycMerchantDepositRewriteTest(t: GlobalTestState) { ); succeedOrThrow( - await wireGatewayApi.addKycAuth(exchangeBankAccount.accountPassword, { - account_pub: info.merchant_pub, - amount: "TESTKUDOS:0.1", - debit_account: merchantBankAccount, + await wireGatewayApi.addKycAuth({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + account_pub: info.merchant_pub, + amount: "TESTKUDOS:0.1", + debit_account: merchantBankAccount, + }, }), ); logger.info("Money wired"); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-merchant-deposit.ts b/packages/taler-harness/src/integrationtests/test-kyc-merchant-deposit.ts @@ -29,7 +29,6 @@ import { MerchantAccountKycRedirectsResponse, MerchantAccountKycStatus, TalerMerchantApi, - WireGatewayApiClient, } from "@gnu-taler/taler-util"; import { readResponseJsonOrThrow, @@ -39,7 +38,6 @@ import { configureCommonKyc, createKycTestkudosEnvironment, postAmlDecisionNoRules, - withdrawViaBankV3, } from "../harness/environments.js"; import { delayMs, @@ -87,6 +85,7 @@ export async function runKycMerchantDepositTest(t: GlobalTestState) { exchange, exchangeBankAccount, amlKeypair, + wireGatewayApi, } = await createKycTestkudosEnvironment(t, { adjustExchangeConfig, }); @@ -103,16 +102,6 @@ export async function runKycMerchantDepositTest(t: GlobalTestState) { accountPub = parsedResp.merchant_pub; } - const wireGatewayApiClient = new WireGatewayApiClient( - exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: "admin", - password: "admin-password", - }, - }, - ); - // Withdraw digital cash into the wallet. let kycRespOne: MerchantAccountKycRedirectsResponse | undefined = undefined; @@ -174,10 +163,13 @@ export async function runKycMerchantDepositTest(t: GlobalTestState) { username: "merchant-default", payto_uri: kycRespOne.kyc_data[0].payto_uri, //this bank user needs to have the same payto that the exchange is asking from }); - await wireGatewayApiClient.adminAddKycauth({ - amount: "TESTKUDOS:0.1", - debitAccountPayto: kycRespOne.kyc_data[0].payto_uri, - accountPub, + await wireGatewayApi.addKycAuth({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:0.1", + account_pub: kycRespOne.kyc_data[0].payto_uri, + debit_account: accountPub, + }, }); let kycRespTwo: MerchantAccountKycRedirectsResponse | undefined = undefined; diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-bank.ts b/packages/taler-harness/src/integrationtests/test-libeufin-bank.ts @@ -21,25 +21,24 @@ import { CreditDebitIndicator, Logger, TalerCorebankApiClient, + TalerWireGatewayHttpClient, TransactionMajorState, TransactionMinorState, - WireGatewayApiClient, createEddsaKeyPair, encodeCrock, j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; +import { createWalletDaemonWithClient } from "../harness/environments.js"; import { ExchangeService, GlobalTestState, LibeufinBankService, MerchantService, getTestHarnessPaytoForLabel, - generateRandomTestIban, setupDb, } from "../harness/harness.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; const logger = new Logger("test-libeufin-bank.ts"); @@ -83,8 +82,10 @@ export async function runLibeufinBankTest(t: GlobalTestState) { exchange.addBankAccount("1", { wireGatewayApiBaseUrl, - accountName: exchangeBankUsername, - accountPassword: exchangeBankPw, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPw, + }, accountPaytoUri: exchangePayto, }); @@ -122,10 +123,13 @@ export async function runLibeufinBankTest(t: GlobalTestState) { console.log("setup done!"); + const adminUser = "admin"; + const adminPassword = "admin-password"; + const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { auth: { - username: "admin", - password: "admin-password", + username: adminUser, + password: adminPassword, }, }); @@ -166,20 +170,20 @@ export async function runLibeufinBankTest(t: GlobalTestState) { // Not a normal client, but one with admin credentials, // as /add-incoming is testing functionality only allowed by the admin. - const wireGatewayApiAdminClient = new WireGatewayApiClient( + const wireGatewayApiAdminClient = new TalerWireGatewayHttpClient( wireGatewayApiBaseUrl, - { - auth: { - username: "admin", - password: "admin-password", - }, - }, ); - await wireGatewayApiAdminClient.adminAddIncoming({ - amount: "TESTKUDOS:115", - debitAccountPayto: bankUser.accountPaytoUri, - reservePub: encodeCrock(res.eddsaPub), + await wireGatewayApiAdminClient.addIncoming({ + auth: { + username: adminUser, + password: adminPassword, + }, + body: { + amount: "TESTKUDOS:115", + debit_account: bankUser.accountPaytoUri, + reserve_pub: encodeCrock(res.eddsaPub), + }, }); balResp = await bankClient.getAccountBalance(bankUser.username); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts @@ -93,8 +93,10 @@ export async function createConfusedMerchantTestkudosEnvironment( let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-multiexchange.ts b/packages/taler-harness/src/integrationtests/test-multiexchange.ts @@ -25,6 +25,11 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { + createWalletDaemonWithClient, + makeTestPaymentV2, + withdrawViaBankV3, +} from "../harness/environments.js"; +import { BankService, ExchangeService, GlobalTestState, @@ -33,11 +38,6 @@ import { getTestHarnessPaytoForLabel, setupDb, } from "../harness/harness.js"; -import { - createWalletDaemonWithClient, - makeTestPaymentV2, - withdrawViaBankV3, -} from "../harness/environments.js"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -82,18 +82,22 @@ export async function runMultiExchangeTest(t: GlobalTestState) { "accounts/myexchange/taler-wire-gateway/", bank.corebankApiBaseUrl, ).href, - accountName: "myexchange", - accountPassword: "password", + wireGatewayAuth: { + username: "myexchange", + password: "password", + }, accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), }; let exchangeTwoBankAccount: HarnessExchangeBankAccount = { + wireGatewayAuth: { + username: "myexchange2", + password: "password", + }, wireGatewayApiBaseUrl: new URL( "accounts/myexchange2/taler-wire-gateway/", bank.corebankApiBaseUrl, ).href, - accountName: "myexchange2", - accountPassword: "password", accountPaytoUri: getTestHarnessPaytoForLabel("myexchange2"), }; @@ -114,18 +118,18 @@ export async function runMultiExchangeTest(t: GlobalTestState) { }); await bankClient.registerAccountExtended({ - name: exchangeOneBankAccount.accountName, - username: exchangeOneBankAccount.accountName, - password: exchangeOneBankAccount.accountPassword, + name: exchangeOneBankAccount.wireGatewayAuth.username, + username: exchangeOneBankAccount.wireGatewayAuth.username, + password: exchangeOneBankAccount.wireGatewayAuth.password, is_taler_exchange: true, payto_uri: exchangeOneBankAccount.accountPaytoUri, }); await exchangeOne.addBankAccount("1", exchangeOneBankAccount); await bankClient.registerAccountExtended({ - name: exchangeTwoBankAccount.accountName, - username: exchangeTwoBankAccount.accountName, - password: exchangeTwoBankAccount.accountPassword, + name: exchangeTwoBankAccount.wireGatewayAuth.username, + username: exchangeTwoBankAccount.wireGatewayAuth.username, + password: exchangeTwoBankAccount.wireGatewayAuth.password, is_taler_exchange: true, payto_uri: exchangeTwoBankAccount.accountPaytoUri, }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-fault.ts b/packages/taler-harness/src/integrationtests/test-payment-fault.ts @@ -75,8 +75,10 @@ export async function runPaymentFaultTest(t: GlobalTestState) { let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-payment-multiple.ts b/packages/taler-harness/src/integrationtests/test-payment-multiple.ts @@ -66,8 +66,10 @@ async function setupTest(t: GlobalTestState): Promise<{ let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-revocation.ts b/packages/taler-harness/src/integrationtests/test-revocation.ts @@ -24,9 +24,16 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig } from "../harness/denomStructures.js"; import { + SimpleTestEnvironmentNg3, + createWalletDaemonWithClient, + makeTestPaymentV2, + withdrawViaBankV3, +} from "../harness/environments.js"; +import { BankService, ExchangeService, GlobalTestState, + HarnessExchangeBankAccount, MerchantService, WalletCli, WalletClient, @@ -34,12 +41,6 @@ import { getTestHarnessPaytoForLabel, setupDb, } from "../harness/harness.js"; -import { - SimpleTestEnvironmentNg3, - createWalletDaemonWithClient, - makeTestPaymentV2, - withdrawViaBankV3, -} from "../harness/environments.js"; async function revokeAllWalletCoins(req: { walletClient: WalletClient; @@ -94,15 +95,17 @@ async function createTestEnvironment( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + const exchangeBankAccount: HarnessExchangeBankAccount = { + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, ).href, accountPaytoUri: exchangePaytoUri, - }); + }; bank.setSuggestedExchange(exchange, exchangePaytoUri); @@ -180,12 +183,7 @@ async function createTestEnvironment( walletService, bank, bankClient, - exchangeBankAccount: { - accountName: "", - accountPassword: "", - accountPaytoUri: "", - wireGatewayApiBaseUrl: "", - }, + exchangeBankAccount, }; } diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts @@ -77,8 +77,10 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts @@ -26,6 +26,7 @@ import { TalerCorebankApiClient, TalerMerchantApi, TalerMerchantInstanceHttpClient, + TalerWireGatewayAuth, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; @@ -97,11 +98,14 @@ async function createMyEnvironment( `accounts/${exchangeBankUsername}/taler-wire-gateway/`, bank.corebankApiBaseUrl, ).href; + const wireGatewayAuth: TalerWireGatewayAuth = { + username: exchangeBankUsername, + password: exchangeBankPassword, + }; const exchangeBankAccount: HarnessExchangeBankAccount = { wireGatewayApiBaseUrl, - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth, accountPaytoUri: exchangePaytoUri, }; diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dd48.ts b/packages/taler-harness/src/integrationtests/test-wallet-dd48.ts @@ -23,6 +23,7 @@ import { TalerCorebankApiClient, TalerError, TalerErrorCode, + TalerWireGatewayAuth, WalletNotification, j2s, } from "@gnu-taler/taler-util"; @@ -65,10 +66,13 @@ export async function runWalletDd48Test(t: GlobalTestState) { let exchangeBankUsername = "exchange"; let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); + const wireGatewayAuth: TalerWireGatewayAuth = { + username: exchangeBankUsername, + password: exchangeBankPassword, + }; await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts b/packages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts @@ -22,6 +22,7 @@ import { ExchangeUpdateStatus, NotificationType, TalerCorebankApiClient, + TalerWireGatewayAuth, j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -84,18 +85,17 @@ export async function runWalletExchangeUpdateTest( }, }); - // const exchangeBankAccount = await bank.createExchangeAccount( - // "myexchange", - // "password", - // ); + const wireGatewayAuth: TalerWireGatewayAuth = { + username: "myexchange", + password: "password", + }; - let exchangeBankAccount: HarnessExchangeBankAccount = { + const exchangeBankAccount: HarnessExchangeBankAccount = { wireGatewayApiBaseUrl: new URL( "accounts/myexchange/taler-wire-gateway/", bank.corebankApiBaseUrl, ).href, - accountName: "myexchange", - accountPassword: "password", + wireGatewayAuth, accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), }; @@ -108,9 +108,9 @@ export async function runWalletExchangeUpdateTest( await bank.start(); bankClient.registerAccountExtended({ - name: exchangeBankAccount.accountName, - username: exchangeBankAccount.accountName, - password: exchangeBankAccount.accountPassword, + name: exchangeBankAccount.wireGatewayAuth.username, + username: exchangeBankAccount.wireGatewayAuth.username, + password: exchangeBankAccount.wireGatewayAuth.password, is_taler_exchange: true, payto_uri: exchangeBankAccount.accountPaytoUri, }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts @@ -23,20 +23,21 @@ import { j2s, PaymentInsufficientBalanceDetails, TalerErrorCode, + TalerWireGatewayAuth, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { + createSimpleTestkudosEnvironmentV3, + withdrawViaBankV3, +} from "../harness/environments.js"; +import { ExchangeService, getTestHarnessPaytoForLabel, GlobalTestState, HarnessExchangeBankAccount, setupDb, } from "../harness/harness.js"; -import { - createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, -} from "../harness/environments.js"; export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { // Set up test environment @@ -69,10 +70,14 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { bank.corebankApiBaseUrl, ).href; + const wireGatewayAuth: TalerWireGatewayAuth = { + username: exchangeBankUsername, + password: exchangeBankPassword, + }; + const exchangeBankAccount: HarnessExchangeBankAccount = { wireGatewayApiBaseUrl, - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth, accountPaytoUri: exchangePaytoUri, skipWireFeeCreation: true, }; @@ -133,7 +138,7 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { walletClient.call(WalletApiOperation.CheckDeposit, { amount: "TESTKUDOS:5" as AmountString, depositPaytoUri: "payto://x-taler-bank/localhost/foobar", - }) + }), ); t.assertDeepEqual( @@ -170,7 +175,7 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { const exc = await t.assertThrowsTalerErrorAsync( walletClient.call(WalletApiOperation.CheckPeerPushDebit, { amount: "TESTKUDOS:20" as AmountString, - }) + }), ); const insufficientBalanceDetails: PaymentInsufficientBalanceDetails = diff --git a/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts b/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts @@ -21,6 +21,7 @@ import { Duration, NotificationType, TalerCorebankApiClient, + TalerWireGatewayAuth, TransactionMajorState, TransactionMinorState, } from "@gnu-taler/taler-util"; @@ -65,6 +66,11 @@ export async function runWalletNotificationsTest(t: GlobalTestState) { let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); + const wireGatewayAuth: TalerWireGatewayAuth = { + username: exchangeBankUsername, + password: exchangeBankPassword, + }; + const merchant = await MerchantService.create(t, { name: "testmerchant-1", httpPort: 8083, @@ -72,8 +78,7 @@ export async function runWalletNotificationsTest(t: GlobalTestState) { }); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-observability.ts b/packages/taler-harness/src/integrationtests/test-wallet-observability.ts @@ -20,10 +20,12 @@ import { NotificationType, TalerCorebankApiClient, + TalerWireGatewayAuth, WalletNotification, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; +import { withdrawViaBankV3 } from "../harness/environments.js"; import { BankService, ExchangeService, @@ -33,7 +35,6 @@ import { getTestHarnessPaytoForLabel, setupDb, } from "../harness/harness.js"; -import { withdrawViaBankV3 } from "../harness/environments.js"; export async function runWalletObservabilityTest(t: GlobalTestState) { // Set up test environment @@ -59,9 +60,13 @@ export async function runWalletObservabilityTest(t: GlobalTestState) { let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); + const wireGatewayAuth: TalerWireGatewayAuth = { + username: exchangeBankUsername, + password: exchangeBankPassword, + }; + await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-wirefees.ts b/packages/taler-harness/src/integrationtests/test-wallet-wirefees.ts @@ -24,6 +24,7 @@ import { TalerCorebankApiClient, TalerMerchantApi, TalerMerchantInstanceHttpClient, + TalerWireGatewayAuth, TransactionMajorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -75,10 +76,13 @@ export async function runWalletWirefeesTest(t: GlobalTestState) { let exchangeBankUsername = "exchange"; let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); + const wireGatewayAuth: TalerWireGatewayAuth = { + username: exchangeBankUsername, + password: exchangeBankPassword, + }; await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-amount.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-amount.ts @@ -20,12 +20,12 @@ import { AmountString, Logger, - WireGatewayApiClient, + TalerWireGatewayHttpClient, j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; const logger = new Logger("test-withdrawal-manual.ts"); @@ -38,14 +38,8 @@ export async function runWithdrawalAmountTest(t: GlobalTestState) { const { walletClient, bankClient, exchange, exchangeBankAccount } = await createSimpleTestkudosEnvironmentV3(t); - const wireGatewayApiClient = new WireGatewayApiClient( + const wireGatewayApiClient = new TalerWireGatewayHttpClient( exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: "admin", - password: "admin-password", - }, - }, ); // Create a withdrawal operation @@ -71,10 +65,13 @@ export async function runWithdrawalAmountTest(t: GlobalTestState) { const reservePub: string = wres.reservePub; - await wireGatewayApiClient.adminAddIncoming({ - amount: "TESTKUDOS:5", - debitAccountPayto: user.accountPaytoUri, - reservePub: reservePub, + await wireGatewayApiClient.addIncoming({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:5", + debit_account: user.accountPaytoUri, + reserve_pub: reservePub, + }, }); await exchange.runWirewatchOnce(); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts @@ -24,14 +24,15 @@ import { Logger, TalerBankConversionApi, TalerCorebankApiClient, + TalerWireGatewayHttpClient, TransactionType, - WireGatewayApiClient, WithdrawalType, j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import * as http from "node:http"; import { defaultCoinConfig } from "../harness/denomStructures.js"; +import { createWalletDaemonWithClient } from "../harness/environments.js"; import { BankService, ExchangeService, @@ -41,7 +42,6 @@ import { getTestHarnessPaytoForLabel, setupDb, } from "../harness/harness.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; const logger = new Logger("test-withdrawal-conversion.ts"); @@ -161,8 +161,10 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { "accounts/myexchange/taler-wire-gateway/", bank.corebankApiBaseUrl, ).href, - accountName: "myexchange", - accountPassword: "password", + wireGatewayAuth: { + username: "myexchange", + password: "password", + }, accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), conversionUrl: "http://localhost:8071/", }; @@ -183,9 +185,9 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { }); await bankClient.registerAccountExtended({ - name: exchangeBankAccount.accountName, - username: exchangeBankAccount.accountName, - password: exchangeBankAccount.accountPassword, + name: exchangeBankAccount.wireGatewayAuth.username, + username: exchangeBankAccount.wireGatewayAuth.username, + password: exchangeBankAccount.wireGatewayAuth.password, is_taler_exchange: true, payto_uri: exchangeBankAccount.accountPaytoUri, }); @@ -292,17 +294,17 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { const reservePub: string = wres.reservePub; - const wireGatewayApiClient = new WireGatewayApiClient( + const wireGatewayApiClient = new TalerWireGatewayHttpClient( exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: bankClientAuth, - }, ); - await wireGatewayApiClient.adminAddIncoming({ - amount: "TESTKUDOS:10", - debitAccountPayto: user.accountPaytoUri, - reservePub: reservePub, + await wireGatewayApiClient.addIncoming({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:10", + debit_account: user.accountPaytoUri, + reserve_pub: reservePub, + }, }); await exchange.runWirewatchOnce(); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts @@ -52,8 +52,10 @@ export async function runWithdrawalFakebankTest(t: GlobalTestState) { }); exchange.addBankAccount("1", { - accountName: "exchange", - accountPassword: "password", + wireGatewayAuth: { + username: "exchange", + password: "password", + }, wireGatewayApiBaseUrl: new URL( "/accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts @@ -93,8 +93,10 @@ export async function runWithdrawalFeesTest(t: GlobalTestState) { let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); await exchange.addBankAccount("1", { - accountName: exchangeBankUsername, - accountPassword: exchangeBankPassword, + wireGatewayAuth: { + username: exchangeBankUsername, + password: exchangeBankPassword, + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts @@ -18,22 +18,22 @@ * Imports. */ import { - GlobalTestState, - setupDb, - ExchangeService, - WalletService, - WalletClient, - BankService, -} from "../harness/harness.js"; -import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; -import { AmountString, NotificationType, TalerCorebankApiClient, TransactionMajorState, URL, } from "@gnu-taler/taler-util"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; +import { + BankService, + ExchangeService, + GlobalTestState, + setupDb, + WalletClient, + WalletService, +} from "../harness/harness.js"; /** * Withdraw a high amount. Mostly intended as a perf test. @@ -64,8 +64,10 @@ export async function runWithdrawalHugeTest(t: GlobalTestState) { let paytoUri = "payto://x-taler-bank/localhost/exchange"; await exchange.addBankAccount("1", { - accountName: "exchange", - accountPassword: "password", + wireGatewayAuth: { + username: "exchange", + password: "password", + }, wireGatewayApiBaseUrl: new URL( "accounts/exchange/taler-wire-gateway/", bank.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts @@ -22,7 +22,7 @@ import { AmountString, Logger, ScopeType, - WireGatewayApiClient, + TalerWireGatewayHttpClient, j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -101,20 +101,17 @@ export async function runWithdrawalManualTest(t: GlobalTestState) { const reservePub: string = wres.reservePub; - const wireGatewayApiClient = new WireGatewayApiClient( + const wireGatewayApiClient = new TalerWireGatewayHttpClient( exchangeBankAccount.wireGatewayApiBaseUrl, - { - auth: { - username: "admin", - password: "admin-password", - }, - }, ); - await wireGatewayApiClient.adminAddIncoming({ - amount: "TESTKUDOS:10", - debitAccountPayto: user.accountPaytoUri, - reservePub: reservePub, + await wireGatewayApiClient.addIncoming({ + auth: exchangeBankAccount.wireGatewayAuth, + body: { + amount: "TESTKUDOS:10", + debit_account: user.accountPaytoUri, + reserve_pub: reservePub, + }, }); await exchange.runWirewatchOnce(); diff --git a/packages/taler-util/src/bank-api-client.ts b/packages/taler-util/src/bank-api-client.ts @@ -43,7 +43,6 @@ import { TalerErrorCode, } from "@gnu-taler/taler-util"; import { - checkSuccessResponseOrThrow, createPlatformHttpLib, expectSuccessResponseOrThrow, HttpRequestLibrary, @@ -96,82 +95,6 @@ export interface BankAccessApiClientArgs { httpClient?: HttpRequestLibrary; } -export interface BankAccessApiCreateTransactionRequest { - amount: AmountString; - paytoUri: string; -} - -export class WireGatewayApiClientArgs { - auth?: { - username: string; - password: string; - }; - httpClient?: HttpRequestLibrary; -} - -/** - * This API look like it belongs to harness - * but it will be nice to have in utils to be used by others - */ -export class WireGatewayApiClient { - httpLib; - - 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: { - amount: string; - reservePub: string; - debitAccountPayto: string; - }): Promise<void> { - let url = new URL(`admin/add-incoming`, this.baseUrl); - const resp = await this.httpLib.fetch(url.href, { - method: "POST", - body: { - amount: params.amount, - reserve_pub: params.reservePub, - debit_account: params.debitAccountPayto, - }, - headers: this.makeAuthHeader(), - }); - logger.info(`add-incoming response status: ${resp.status}`); - await checkSuccessResponseOrThrow(resp); - } - - async adminAddKycauth(params: { - amount: string; - accountPub: string; - debitAccountPayto: string; - }): Promise<void> { - let url = new URL(`admin/add-kycauth`, this.baseUrl); - const resp = await this.httpLib.fetch(url.href, { - method: "POST", - body: { - amount: params.amount, - account_pub: params.accountPub, - debit_account: params.debitAccountPayto, - }, - headers: this.makeAuthHeader(), - }); - logger.info(`add-kycauth response status: ${resp.status}`); - await checkSuccessResponseOrThrow(resp); - } -} - export interface AccountBalance { amount: AmountString; credit_debit_indicator: "credit" | "debit"; @@ -183,6 +106,8 @@ export interface ConfirmWithdrawalArgs { /** * Client for the Taler corebank API. + * + * @deprecated use TalerCoreBankHttpClient instead */ export class TalerCorebankApiClient { httpLib: HttpRequestLibrary; diff --git a/packages/taler-util/src/http-client/bank-wire.ts b/packages/taler-util/src/http-client/bank-wire.ts @@ -31,10 +31,10 @@ import { } from "../operation.js"; import { codecForAddIncomingResponse, + codecForBankWireTransferList, codecForIncomingHistory, codecForOutgoingHistory, codecForTransferResponse, - codecForBankWireTransferList, } from "../types-taler-wire-gateway.js"; import { addLongPollingParam, addPaginationParams } from "./utils.js"; @@ -48,6 +48,11 @@ export type TalerWireGatewayErrorsByMethod< prop extends keyof TalerWireGatewayHttpClient, > = FailCasesByMethod<TalerWireGatewayHttpClient, prop>; +export interface TalerWireGatewayAuth { + username: string; + password: string; +} + /** * The API is used by the exchange to trigger transactions and query * incoming transactions, as well as by the auditor to query incoming @@ -60,47 +65,31 @@ export class TalerWireGatewayHttpClient { constructor( readonly baseUrl: string, - readonly username: string, - httpClient?: HttpRequestLibrary, + options: { + httpClient?: HttpRequestLibrary; + } = {}, ) { - this.httpLib = httpClient ?? createPlatformHttpLib(); + this.httpLib = options.httpClient ?? createPlatformHttpLib(); } - // public readonly PROTOCOL_VERSION = "4:0:0"; - // isCompatible(version: string): boolean { - // const compare = LibtoolVersion.compare(this.PROTOCOL_VERSION, version) - // return compare?.compatible ?? false - // } - - // /** - // * https://docs.taler.net/core/api-corebank.html#config - // * - // */ - // async getConfig() { - // const url = new URL(`config`, this.baseUrl); - // const resp = await this.httpLib.fetch(url.href, { - // method: "GET" - // }); - // switch (resp.status) { - // case HttpStatusCode.Ok: return opSuccess(resp, codecForCoreBankConfig()) - // default: return opUnknownFailure(resp, await readTalerErrorResponse(resp)) - // } - // } /** * https://docs.taler.net/core/api-bank-wire.html#post--transfer * */ - async makeWireTransfer( - auth: string, - body: TalerWireGatewayApi.TransferRequest, - ) { + async makeWireTransfer(req: { + body: TalerWireGatewayApi.TransferRequest; + auth: { username: string; password: string }; + }) { const url = new URL(`transfer`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { - Authorization: makeBasicAuthHeader(this.username, auth), + Authorization: makeBasicAuthHeader( + req.auth.username, + req.auth.password, + ), }, - body, + body: req.body, }); switch (resp.status) { case HttpStatusCode.Ok: @@ -124,40 +113,43 @@ export class TalerWireGatewayHttpClient { * https://docs.taler.net/core/api-bank-wire.html#get--transfers * */ - async getTransfers( - auth: string, + async getTransfers(req: { params?: { status?: TalerWireGatewayApi.WireTransferStatus; - } & PaginationParams, - ) { + } & PaginationParams; + auth: TalerWireGatewayAuth; + }) { const url = new URL(`transfers`, this.baseUrl); - if (params) { - if (params.status) { - url.searchParams.set("status", params.status); + if (req.params) { + if (req.params.status) { + url.searchParams.set("status", req.params.status); } } - addPaginationParams(url, params); + addPaginationParams(url, req.params); const resp = await this.httpLib.fetch(url.href, { method: "GET", headers: { - Authorization: makeBasicAuthHeader(this.username, auth), + Authorization: makeBasicAuthHeader( + req.auth.username, + req.auth.password, + ), }, }); switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForBankWireTransferList()); - //FIXME: account should not be returned or make it optional + // FIXME: account should not be returned or make it optional case HttpStatusCode.NoContent: return opFixedSuccess({ transfers: [], debit_account: undefined, }); - //FIXME: show more details in docs + // FIXME: show more details in docs case HttpStatusCode.BadRequest: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Unauthorized: return opKnownHttpFailure(resp.status, resp); - //FIXME: show more details in docs + // FIXME: show more details in docs case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -169,12 +161,15 @@ export class TalerWireGatewayHttpClient { * https://docs.taler.net/core/api-bank-wire.html#get--transfers-$ROW_ID * */ - async getTransferStatus(auth: string, rowId?: number) { - const url = new URL(`transfers/${String(rowId)}`, this.baseUrl); + async getTransferStatus(req: { auth: TalerWireGatewayAuth; rowId?: number }) { + const url = new URL(`transfers/${req.rowId}`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "GET", headers: { - Authorization: makeBasicAuthHeader(this.username, auth), + Authorization: makeBasicAuthHeader( + req.auth.username, + req.auth.password, + ), }, }); switch (resp.status) { @@ -197,17 +192,20 @@ export class TalerWireGatewayHttpClient { * https://docs.taler.net/core/api-bank-wire.html#get--history-incoming * */ - async getHistoryIncoming( - auth: string, - params?: PaginationParams & LongPollParams, - ) { + async getHistoryIncoming(req: { + params?: PaginationParams & LongPollParams; + auth: TalerWireGatewayAuth; + }) { const url = new URL(`history/incoming`, this.baseUrl); - addPaginationParams(url, params); - addLongPollingParam(url, params); + addPaginationParams(url, req.params); + addLongPollingParam(url, req.params); const resp = await this.httpLib.fetch(url.href, { method: "GET", headers: { - Authorization: makeBasicAuthHeader(this.username, auth), + Authorization: makeBasicAuthHeader( + req.auth.username, + req.auth.password, + ), }, }); switch (resp.status) { @@ -236,17 +234,20 @@ export class TalerWireGatewayHttpClient { * https://docs.taler.net/core/api-bank-wire.html#get--history-outgoing * */ - async getHistoryOutgoing( - auth: string, - params?: PaginationParams & LongPollParams, - ) { + async getHistoryOutgoing(req: { + auth: TalerWireGatewayAuth; + params?: PaginationParams & LongPollParams; + }) { const url = new URL(`history/outgoing`, this.baseUrl); - addPaginationParams(url, params); - addLongPollingParam(url, params); + addPaginationParams(url, req.params); + addLongPollingParam(url, req.params); const resp = await this.httpLib.fetch(url.href, { method: "GET", headers: { - Authorization: makeBasicAuthHeader(this.username, auth), + Authorization: makeBasicAuthHeader( + req.auth.username, + req.auth.password, + ), }, }); switch (resp.status) { @@ -275,17 +276,20 @@ export class TalerWireGatewayHttpClient { * https://docs.taler.net/core/api-bank-wire.html#post--admin-add-incoming * */ - async addIncoming( - auth: string, - body: TalerWireGatewayApi.AddIncomingRequest, - ) { + async addIncoming(req: { + body: TalerWireGatewayApi.AddIncomingRequest; + auth: { username: string; password: string }; + }) { const url = new URL(`admin/add-incoming`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { - Authorization: makeBasicAuthHeader(this.username, auth), + Authorization: makeBasicAuthHeader( + req.auth.username, + req.auth.password, + ), }, - body, + body: req.body, }); switch (resp.status) { case HttpStatusCode.Ok: @@ -309,14 +313,20 @@ export class TalerWireGatewayHttpClient { * https://docs.taler.net/core/api-bank-wire.html#post--admin-add-kycauth * */ - async addKycAuth(auth: string, body: TalerWireGatewayApi.AddKycauthRequest) { + async addKycAuth(req: { + body: TalerWireGatewayApi.AddKycauthRequest; + auth: { username: string; password: string }; + }) { const url = new URL(`admin/add-kycauth`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { - Authorization: makeBasicAuthHeader(this.username, auth), + Authorization: makeBasicAuthHeader( + req.auth.username, + req.auth.password, + ), }, - body, + body: req.body, }); switch (resp.status) { case HttpStatusCode.Ok: diff --git a/packages/taler-util/src/index.ts b/packages/taler-util/src/index.ts @@ -1,4 +1,3 @@ -export { TalerErrorCode } from "./taler-error-codes.js"; export * from "./amounts.js"; export * from "./bank-api-client.js"; export * from "./base64.js"; @@ -9,6 +8,8 @@ export * from "./contract-terms.js"; export * from "./errors.js"; export { fnutil } from "./fnutils.js"; export * from "./helpers.js"; +export { TalerErrorCode } from "./taler-error-codes.js"; + export * from "./http-client/bank-conversion.js"; export * from "./http-client/bank-core.js"; export * from "./http-client/bank-integration.js"; @@ -18,6 +19,7 @@ export * from "./http-client/challenger.js"; export * from "./http-client/exchange.js"; export * from "./http-client/merchant.js"; export * from "./http-client/officer-account.js"; + export { BasicAuth, BasicOrTokenAuth, @@ -86,6 +88,6 @@ export * from "./aml/aml-events.js"; export * from "./aml/aml-properties.js"; export * from "./taler-form-attributes.js"; -export * from "./iso-4217.js"; export * from "./iso-3166.js"; +export * from "./iso-4217.js"; export * from "./iso-639.js"; diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts @@ -2031,6 +2031,9 @@ async function processQueryReserve( logger.trace(`got reserve status ${j2s(result.response)}`); + // We only allow changing the amount *down*, so that user error + // in the wire transfer won't result in a giant withdrawal. + // See https://bugs.taler.net/n/9732 let amountChanged = false; if ( Amounts.cmp( diff --git a/packages/taler-wallet-webextension/src/test-utils.ts b/packages/taler-wallet-webextension/src/test-utils.ts @@ -14,14 +14,25 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { NotificationType, TalerBankIntegrationHttpClient, TalerCoreBankHttpClient, TalerRevenueHttpClient, TalerWireGatewayHttpClient, WalletNotification } from "@gnu-taler/taler-util"; +import { + NotificationType, + TalerBankIntegrationHttpClient, + TalerCoreBankHttpClient, + TalerRevenueHttpClient, + TalerWireGatewayHttpClient, + WalletNotification, +} from "@gnu-taler/taler-util"; import { WalletCoreApiClient, WalletCoreOpKeys, WalletCoreRequestType, WalletCoreResponseType, } from "@gnu-taler/taler-wallet-core"; -import { ApiContextProvider, TranslationProvider, defaultRequestHandler } from "@gnu-taler/web-util/browser"; +import { + ApiContextProvider, + TranslationProvider, + defaultRequestHandler, +} from "@gnu-taler/web-util/browser"; import { ComponentChildren, FunctionalComponent, @@ -115,9 +126,7 @@ export function createWalletApiMock(): { }, }), listener: { - trigger: () => { - - }, + trigger: () => {}, onUpdateNotification( mTypes: NotificationType[], callback: ((d: WalletNotification) => void) | undefined, @@ -189,9 +198,9 @@ export function createWalletApiMock(): { request: defaultRequestHandler, bankCore: new TalerCoreBankHttpClient("/"), bankIntegration: new TalerBankIntegrationHttpClient("/"), - bankWire: new TalerWireGatewayHttpClient("/",""), - bankRevenue: new TalerRevenueHttpClient("/"), - } + bankWire: new TalerWireGatewayHttpClient("/"), + bankRevenue: new TalerRevenueHttpClient("/"), + }; children = create(ApiContextProvider, { value, children }, children); children = create( TranslationProvider,