get rid of deprecated bank API client, change allowHttp to requireTls
This commit is contained in:
parent
07d71eb297
commit
7450bede5b
@ -138,7 +138,6 @@ export * as validators from "./validators.js";
|
|||||||
export * from "./challenge-feedback-types.js";
|
export * from "./challenge-feedback-types.js";
|
||||||
|
|
||||||
const httpLib = createPlatformHttpLib({
|
const httpLib = createPlatformHttpLib({
|
||||||
allowHttp: true,
|
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ export async function runBench2(configJson: any): Promise<void> {
|
|||||||
|
|
||||||
const http = createPlatformHttpLib({
|
const http = createPlatformHttpLib({
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
allowHttp: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const numIter = benchConf.iterations ?? 1;
|
const numIter = benchConf.iterations ?? 1;
|
||||||
|
@ -52,7 +52,6 @@ export async function runBench3(configJson: any): Promise<void> {
|
|||||||
|
|
||||||
const myHttpLib = createPlatformHttpLib({
|
const myHttpLib = createPlatformHttpLib({
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
allowHttp: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const numIter = b3conf.iterations ?? 1;
|
const numIter = b3conf.iterations ?? 1;
|
||||||
|
@ -25,62 +25,46 @@
|
|||||||
* Imports
|
* Imports
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
AccountAddDetails,
|
||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
AmountString,
|
|
||||||
codecForMerchantOrderPrivateStatusResponse,
|
|
||||||
codecForMerchantPostOrderResponse,
|
|
||||||
codecForMerchantReserveCreateConfirmation,
|
|
||||||
Configuration,
|
Configuration,
|
||||||
CoreApiResponse,
|
CoreApiResponse,
|
||||||
createEddsaKeyPair,
|
|
||||||
Duration,
|
Duration,
|
||||||
eddsaGetPublic,
|
|
||||||
EddsaKeyPair,
|
EddsaKeyPair,
|
||||||
|
Logger,
|
||||||
|
MerchantInstanceConfig,
|
||||||
|
PartialMerchantInstanceConfig,
|
||||||
|
TalerError,
|
||||||
|
WalletNotification,
|
||||||
|
createEddsaKeyPair,
|
||||||
|
eddsaGetPublic,
|
||||||
encodeCrock,
|
encodeCrock,
|
||||||
hash,
|
hash,
|
||||||
j2s,
|
j2s,
|
||||||
Logger,
|
|
||||||
MerchantInstancesResponse,
|
|
||||||
MerchantOrderPrivateStatusResponse,
|
|
||||||
MerchantPostOrderRequest,
|
|
||||||
MerchantPostOrderResponse,
|
|
||||||
MerchantReserveCreateConfirmation,
|
|
||||||
MerchantTemplateAddDetails,
|
|
||||||
parsePaytoUri,
|
parsePaytoUri,
|
||||||
stringToBytes,
|
stringToBytes,
|
||||||
TalerError,
|
|
||||||
TalerProtocolDuration,
|
|
||||||
RewardCreateConfirmation,
|
|
||||||
RewardCreateRequest,
|
|
||||||
TippingReserveStatus,
|
|
||||||
WalletNotification,
|
|
||||||
codecForAny,
|
|
||||||
AccountAddDetails,
|
|
||||||
MerchantInstanceConfig,
|
|
||||||
PartialMerchantInstanceConfig,
|
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
createPlatformHttpLib,
|
createPlatformHttpLib,
|
||||||
expectSuccessResponseOrThrow,
|
expectSuccessResponseOrThrow,
|
||||||
readSuccessResponseJsonOrThrow,
|
|
||||||
} from "@gnu-taler/taler-util/http";
|
} from "@gnu-taler/taler-util/http";
|
||||||
import {
|
import {
|
||||||
BankApi,
|
BankAccessApiClient,
|
||||||
BankServiceHandle,
|
BankServiceHandle,
|
||||||
HarnessExchangeBankAccount,
|
HarnessExchangeBankAccount,
|
||||||
openPromise,
|
|
||||||
WalletCoreApiClient,
|
WalletCoreApiClient,
|
||||||
WalletCoreRequestType,
|
WalletCoreRequestType,
|
||||||
WalletCoreResponseType,
|
WalletCoreResponseType,
|
||||||
WalletOperations,
|
WalletOperations,
|
||||||
|
openPromise,
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
import {
|
import {
|
||||||
|
RemoteWallet,
|
||||||
|
WalletNotificationWaiter,
|
||||||
createRemoteWallet,
|
createRemoteWallet,
|
||||||
getClientFromRemoteWallet,
|
getClientFromRemoteWallet,
|
||||||
makeNotificationWaiter,
|
makeNotificationWaiter,
|
||||||
RemoteWallet,
|
|
||||||
WalletNotificationWaiter,
|
|
||||||
} from "@gnu-taler/taler-wallet-core/remote";
|
} from "@gnu-taler/taler-wallet-core/remote";
|
||||||
import { deepStrictEqual } from "assert";
|
import { deepStrictEqual } from "assert";
|
||||||
import { ChildProcess, spawn } from "child_process";
|
import { ChildProcess, spawn } from "child_process";
|
||||||
@ -594,7 +578,7 @@ export class FakebankService
|
|||||||
{
|
{
|
||||||
proc: ProcessWrapper | undefined;
|
proc: ProcessWrapper | undefined;
|
||||||
|
|
||||||
http = createPlatformHttpLib({ allowHttp: true, enableThrottling: false });
|
http = createPlatformHttpLib({ enableThrottling: false });
|
||||||
|
|
||||||
// We store "created" accounts during setup and
|
// We store "created" accounts during setup and
|
||||||
// register them after startup.
|
// register them after startup.
|
||||||
@ -702,13 +686,9 @@ export class FakebankService
|
|||||||
"bank",
|
"bank",
|
||||||
);
|
);
|
||||||
await this.pingUntilAvailable();
|
await this.pingUntilAvailable();
|
||||||
|
const bankClient = new BankAccessApiClient(this.bankAccessApiBaseUrl);
|
||||||
for (const acc of this.accounts) {
|
for (const acc of this.accounts) {
|
||||||
await BankApi.registerAccount(
|
await bankClient.registerAccount(acc.accountName, acc.accountPassword);
|
||||||
this,
|
|
||||||
acc.accountName,
|
|
||||||
acc.accountPassword,
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1351,7 +1331,6 @@ export interface MerchantServiceInterface {
|
|||||||
* Default HTTP client handle for the integration test harness.
|
* Default HTTP client handle for the integration test harness.
|
||||||
*/
|
*/
|
||||||
export const harnessHttpLib = createPlatformHttpLib({
|
export const harnessHttpLib = createPlatformHttpLib({
|
||||||
allowHttp: true,
|
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -36,8 +36,7 @@ import {
|
|||||||
MerchantApiClient,
|
MerchantApiClient,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
BankAccessApi,
|
BankAccessApiClient,
|
||||||
BankApi,
|
|
||||||
HarnessExchangeBankAccount,
|
HarnessExchangeBankAccount,
|
||||||
WalletApiOperation,
|
WalletApiOperation,
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
@ -563,8 +562,10 @@ export async function withdrawViaBankV2(
|
|||||||
): Promise<WithdrawViaBankResult> {
|
): Promise<WithdrawViaBankResult> {
|
||||||
const { walletClient: wallet, bank, exchange, amount } = p;
|
const { walletClient: wallet, bank, exchange, amount } = p;
|
||||||
|
|
||||||
const user = await BankApi.createRandomBankUser(bank);
|
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
|
||||||
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
|
// Hand it to the wallet
|
||||||
|
|
||||||
@ -593,7 +594,7 @@ export async function withdrawViaBankV2(
|
|||||||
|
|
||||||
// Confirm it
|
// Confirm it
|
||||||
|
|
||||||
await BankApi.confirmWithdrawalOperation(bank, user, wop);
|
await bankClient.confirmWithdrawalOperation(user.username, wop);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
withdrawalFinishedCond,
|
withdrawalFinishedCond,
|
||||||
|
@ -176,10 +176,7 @@ export interface LibeufinSandboxAddIncomingRequest {
|
|||||||
direction: string;
|
direction: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const libeufinHarnessHttpLib = createPlatformHttpLib({
|
const libeufinHarnessHttpLib = createPlatformHttpLib();
|
||||||
allowHttp: true,
|
|
||||||
enableThrottling: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIs spread across Legacy and Access, it is therefore
|
* APIs spread across Legacy and Access, it is therefore
|
||||||
|
@ -236,14 +236,15 @@ deploymentCli
|
|||||||
|
|
||||||
console.log(tipReserveResp);
|
console.log(tipReserveResp);
|
||||||
|
|
||||||
const bankAccessApiClient = new BankAccessApiClient({
|
const bankAccessApiClient = new BankAccessApiClient(
|
||||||
baseUrl: args.tipTopup.bankAccessUrl,
|
args.tipTopup.bankAccessUrl,
|
||||||
auth: {
|
{
|
||||||
username: args.tipTopup.bankAccount,
|
auth: {
|
||||||
password: args.tipTopup.bankPassword,
|
username: args.tipTopup.bankAccount,
|
||||||
|
password: args.tipTopup.bankPassword,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
allowHttp: true,
|
);
|
||||||
});
|
|
||||||
|
|
||||||
const paytoUri = addPaytoQueryParams(tipReserveResp.accounts[0].payto_uri, {
|
const paytoUri = addPaytoQueryParams(tipReserveResp.accounts[0].payto_uri, {
|
||||||
message: `tip-reserve ${tipReserveResp.reserve_pub}`,
|
message: `tip-reserve ${tipReserveResp.reserve_pub}`,
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
BankApi,
|
BankAccessApiClient,
|
||||||
WalletApiOperation,
|
WalletApiOperation,
|
||||||
WireGatewayApiClient,
|
WireGatewayApiClient,
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
@ -179,7 +179,8 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Pay with coin from tipping
|
// 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({
|
const tipReserveResp = await merchantClient.createTippingReserve({
|
||||||
exchange_url: exchange.baseUrl,
|
exchange_url: exchange.baseUrl,
|
||||||
initial_balance: "TESTKUDOS:10",
|
initial_balance: "TESTKUDOS:10",
|
||||||
@ -191,12 +192,15 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
|
|||||||
exchangeBankAccount.accountPaytoUri,
|
exchangeBankAccount.accountPaytoUri,
|
||||||
);
|
);
|
||||||
|
|
||||||
const wireGatewayApiClient = new WireGatewayApiClient({
|
const wireGatewayApiClient = new WireGatewayApiClient(
|
||||||
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
|
exchangeBankAccount.wireGatewayApiBaseUrl,
|
||||||
accountName: exchangeBankAccount.accountName,
|
{
|
||||||
accountPassword: exchangeBankAccount.accountPassword,
|
auth: {
|
||||||
allowHttp: true,
|
username: exchangeBankAccount.accountName,
|
||||||
});
|
password: exchangeBankAccount.accountPassword,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await wireGatewayApiClient.adminAddIncoming({
|
await wireGatewayApiClient.adminAddIncoming({
|
||||||
amount: "TESTKUDOS:10",
|
amount: "TESTKUDOS:10",
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
import { createEddsaKeyPair, encodeCrock } from "@gnu-taler/taler-util";
|
import { createEddsaKeyPair, encodeCrock } from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
BankAccessApi,
|
BankAccessApiClient,
|
||||||
BankApi,
|
|
||||||
CreditDebitIndicator,
|
CreditDebitIndicator,
|
||||||
WireGatewayApiClient,
|
WireGatewayApiClient,
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
@ -99,17 +98,19 @@ export async function runBankApiTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
console.log("setup done!");
|
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
|
// Make sure that registering twice results in a 409 Conflict
|
||||||
{
|
{
|
||||||
const e = await t.assertThrowsTalerErrorAsync(async () => {
|
const e = await t.assertThrowsTalerErrorAsync(async () => {
|
||||||
await BankApi.registerAccount(bank, "user1", "pw2", {});
|
await bankClient.registerAccount("user1", "pw1");
|
||||||
});
|
});
|
||||||
t.assertTrue(e.errorDetail.httpStatusCode === 409);
|
t.assertTrue(e.errorDetail.httpStatusCode === 409);
|
||||||
}
|
}
|
||||||
|
|
||||||
let balResp = await BankAccessApi.getAccountBalance(bank, bankUser);
|
let balResp = await bankClient.getAccountBalance(bankUser.username);
|
||||||
|
|
||||||
console.log(balResp);
|
console.log(balResp);
|
||||||
|
|
||||||
@ -121,12 +122,15 @@ export async function runBankApiTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
const res = createEddsaKeyPair();
|
const res = createEddsaKeyPair();
|
||||||
|
|
||||||
const wireGatewayApiClient = new WireGatewayApiClient({
|
const wireGatewayApiClient = new WireGatewayApiClient(
|
||||||
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
|
exchangeBankAccount.wireGatewayApiBaseUrl,
|
||||||
accountName: exchangeBankAccount.accountName,
|
{
|
||||||
accountPassword: exchangeBankAccount.accountPassword,
|
auth: {
|
||||||
allowHttp: true,
|
username: exchangeBankAccount.accountName,
|
||||||
});
|
password: exchangeBankAccount.accountPassword,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await wireGatewayApiClient.adminAddIncoming({
|
await wireGatewayApiClient.adminAddIncoming({
|
||||||
amount: "TESTKUDOS:115",
|
amount: "TESTKUDOS:115",
|
||||||
@ -134,7 +138,7 @@ export async function runBankApiTest(t: GlobalTestState) {
|
|||||||
reservePub: encodeCrock(res.eddsaPub),
|
reservePub: encodeCrock(res.eddsaPub),
|
||||||
});
|
});
|
||||||
|
|
||||||
balResp = await BankAccessApi.getAccountBalance(bank, bankUser);
|
balResp = await bankClient.getAccountBalance(bankUser.username);
|
||||||
t.assertAmountEquals(balResp.balance.amount, "TESTKUDOS:15");
|
t.assertAmountEquals(balResp.balance.amount, "TESTKUDOS:15");
|
||||||
t.assertTrue(
|
t.assertTrue(
|
||||||
balResp.balance.credit_debit_indicator === CreditDebitIndicator.Debit,
|
balResp.balance.credit_debit_indicator === CreditDebitIndicator.Debit,
|
||||||
|
@ -49,7 +49,6 @@ export async function runExchangeDepositTest(t: GlobalTestState) {
|
|||||||
const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t);
|
const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t);
|
||||||
|
|
||||||
const http = createPlatformHttpLib({
|
const http = createPlatformHttpLib({
|
||||||
allowHttp: true,
|
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
});
|
});
|
||||||
const cryptiDisp = new CryptoDispatcher(
|
const cryptiDisp = new CryptoDispatcher(
|
||||||
|
@ -28,8 +28,7 @@ import {
|
|||||||
} from "../harness/harness.js";
|
} from "../harness/harness.js";
|
||||||
import {
|
import {
|
||||||
WalletApiOperation,
|
WalletApiOperation,
|
||||||
BankApi,
|
BankAccessApiClient,
|
||||||
BankAccessApi,
|
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
import {
|
import {
|
||||||
ExchangesListResponse,
|
ExchangesListResponse,
|
||||||
@ -266,10 +265,11 @@ export async function runExchangeManagementTest(
|
|||||||
|
|
||||||
// Create withdrawal operation
|
// Create withdrawal operation
|
||||||
|
|
||||||
const user = await BankApi.createRandomBankUser(bank);
|
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
|
||||||
const wop = await BankAccessApi.createWithdrawalOperation(
|
|
||||||
bank,
|
const user = await bankClient.createRandomBankUser();
|
||||||
user,
|
const wop = await bankClient.createWithdrawalOperation(
|
||||||
|
user.username,
|
||||||
"TESTKUDOS:10",
|
"TESTKUDOS:10",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -94,7 +94,6 @@ function getDenomInfoFromKeys(ek: ExchangeKeysJson): DenomInfo[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const http = createPlatformHttpLib({
|
const http = createPlatformHttpLib({
|
||||||
allowHttp: true,
|
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,8 +28,7 @@ import {
|
|||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
|
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
|
||||||
import {
|
import {
|
||||||
BankAccessApi,
|
BankAccessApiClient,
|
||||||
BankApi,
|
|
||||||
WalletApiOperation,
|
WalletApiOperation,
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
import * as http from "node:http";
|
import * as http from "node:http";
|
||||||
@ -305,9 +304,11 @@ export async function runKycTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Withdraw digital cash into the wallet.
|
// Withdraw digital cash into the wallet.
|
||||||
|
|
||||||
|
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
|
||||||
|
|
||||||
const amount = "TESTKUDOS:20";
|
const amount = "TESTKUDOS:20";
|
||||||
const user = await BankApi.createRandomBankUser(bank);
|
const user = await bankClient.createRandomBankUser();
|
||||||
const wop = await BankAccessApi.createWithdrawalOperation(bank, user, amount);
|
const wop = await bankClient.createWithdrawalOperation(user.username, amount);
|
||||||
|
|
||||||
// Hand it to the wallet
|
// Hand it to the wallet
|
||||||
|
|
||||||
@ -332,7 +333,7 @@ export async function runKycTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Confirm it
|
// Confirm it
|
||||||
|
|
||||||
await BankApi.confirmWithdrawalOperation(bank, user, wop);
|
await bankClient.confirmWithdrawalOperation(user.username, wop);
|
||||||
|
|
||||||
const kycNotificationCond = walletClient.waitForNotificationCond((x) => {
|
const kycNotificationCond = walletClient.waitForNotificationCond((x) => {
|
||||||
if (
|
if (
|
||||||
@ -376,7 +377,6 @@ export async function runKycTest(t: GlobalTestState) {
|
|||||||
// which would usually done in the browser.
|
// which would usually done in the browser.
|
||||||
|
|
||||||
const httpLib = createPlatformHttpLib({
|
const httpLib = createPlatformHttpLib({
|
||||||
allowHttp: true,
|
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
});
|
});
|
||||||
const kycServerResp = await httpLib.fetch(kycUrl);
|
const kycServerResp = await httpLib.fetch(kycUrl);
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
import { CoreApiResponse, MerchantApiClient } from "@gnu-taler/taler-util";
|
import { CoreApiResponse, MerchantApiClient } from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
BankAccessApi,
|
BankAccessApiClient,
|
||||||
BankApi,
|
|
||||||
WalletApiOperation,
|
WalletApiOperation,
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
import { defaultCoinConfig } from "../harness/denomStructures.js";
|
import { defaultCoinConfig } from "../harness/denomStructures.js";
|
||||||
@ -127,10 +126,11 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Create withdrawal operation
|
// Create withdrawal operation
|
||||||
|
|
||||||
const user = await BankApi.createRandomBankUser(bank);
|
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
|
||||||
const wop = await BankAccessApi.createWithdrawalOperation(
|
|
||||||
bank,
|
const user = await bankClient.createRandomBankUser();
|
||||||
user,
|
const wop = await bankClient.createWithdrawalOperation(
|
||||||
|
user.username,
|
||||||
"TESTKUDOS:20",
|
"TESTKUDOS:20",
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Confirm it
|
// Confirm it
|
||||||
|
|
||||||
await BankApi.confirmWithdrawalOperation(bank, user, wop);
|
await bankClient.confirmWithdrawalOperation(user.username, wop);
|
||||||
|
|
||||||
await wallet.runUntilDone();
|
await wallet.runUntilDone();
|
||||||
|
|
||||||
|
@ -38,10 +38,9 @@ export async function runTippingTest(t: GlobalTestState) {
|
|||||||
const { walletClient, bank, exchange, merchant, exchangeBankAccount } =
|
const { walletClient, bank, exchange, merchant, exchangeBankAccount } =
|
||||||
await createSimpleTestkudosEnvironmentV2(t);
|
await createSimpleTestkudosEnvironmentV2(t);
|
||||||
|
|
||||||
const bankAccessApiClient = new BankAccessApiClient({
|
const bankAccessApiClient = new BankAccessApiClient(
|
||||||
allowHttp: true,
|
bank.bankAccessApiBaseUrl,
|
||||||
baseUrl: bank.bankAccessApiBaseUrl,
|
);
|
||||||
});
|
|
||||||
const mbu = await bankAccessApiClient.createRandomBankUser();
|
const mbu = await bankAccessApiClient.createRandomBankUser();
|
||||||
|
|
||||||
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
|
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
|
||||||
@ -59,12 +58,15 @@ export async function runTippingTest(t: GlobalTestState) {
|
|||||||
exchangeBankAccount.accountPaytoUri,
|
exchangeBankAccount.accountPaytoUri,
|
||||||
);
|
);
|
||||||
|
|
||||||
const wireGatewayApiClient = new WireGatewayApiClient({
|
const wireGatewayApiClient = new WireGatewayApiClient(
|
||||||
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
|
exchangeBankAccount.wireGatewayApiBaseUrl,
|
||||||
accountName: exchangeBankAccount.accountName,
|
{
|
||||||
accountPassword: exchangeBankAccount.accountPassword,
|
auth: {
|
||||||
allowHttp: true,
|
username: exchangeBankAccount.accountName,
|
||||||
});
|
password: exchangeBankAccount.accountPassword,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await wireGatewayApiClient.adminAddIncoming({
|
await wireGatewayApiClient.adminAddIncoming({
|
||||||
amount: "TESTKUDOS:10",
|
amount: "TESTKUDOS:10",
|
||||||
|
@ -123,10 +123,9 @@ export async function runWalletNotificationsTest(t: GlobalTestState) {
|
|||||||
skipDefaults: true,
|
skipDefaults: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const bankAccessApiClient = new BankAccessApiClient({
|
const bankAccessApiClient = new BankAccessApiClient(
|
||||||
allowHttp: true,
|
bank.bankAccessApiBaseUrl,
|
||||||
baseUrl: bank.bankAccessApiBaseUrl,
|
);
|
||||||
});
|
|
||||||
const user = await bankAccessApiClient.createRandomBankUser();
|
const user = await bankAccessApiClient.createRandomBankUser();
|
||||||
bankAccessApiClient.setAuth(user);
|
bankAccessApiClient.setAuth(user);
|
||||||
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
||||||
|
@ -36,10 +36,9 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Create a withdrawal operation
|
// Create a withdrawal operation
|
||||||
|
|
||||||
const bankAccessApiClient = new BankAccessApiClient({
|
const bankAccessApiClient = new BankAccessApiClient(
|
||||||
allowHttp: true,
|
bank.bankAccessApiBaseUrl,
|
||||||
baseUrl: bank.bankAccessApiBaseUrl,
|
);
|
||||||
});
|
|
||||||
const user = await bankAccessApiClient.createRandomBankUser();
|
const user = await bankAccessApiClient.createRandomBankUser();
|
||||||
bankAccessApiClient.setAuth(user);
|
bankAccessApiClient.setAuth(user);
|
||||||
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
*/
|
*/
|
||||||
import { GlobalTestState } from "../harness/harness.js";
|
import { GlobalTestState } from "../harness/harness.js";
|
||||||
import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.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 {
|
import {
|
||||||
j2s,
|
j2s,
|
||||||
NotificationType,
|
NotificationType,
|
||||||
@ -40,10 +43,9 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Create a withdrawal operation
|
// Create a withdrawal operation
|
||||||
|
|
||||||
const bankAccessApiClient = new BankAccessApiClient({
|
const bankAccessApiClient = new BankAccessApiClient(
|
||||||
allowHttp: true,
|
bank.bankAccessApiBaseUrl,
|
||||||
baseUrl: bank.bankAccessApiBaseUrl,
|
);
|
||||||
});
|
|
||||||
const user = await bankAccessApiClient.createRandomBankUser();
|
const user = await bankAccessApiClient.createRandomBankUser();
|
||||||
bankAccessApiClient.setAuth(user);
|
bankAccessApiClient.setAuth(user);
|
||||||
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
||||||
|
@ -110,10 +110,9 @@ export async function runWithdrawalFeesTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
const amount = "TESTKUDOS:7.5";
|
const amount = "TESTKUDOS:7.5";
|
||||||
|
|
||||||
const bankAccessApiClient = new BankAccessApiClient({
|
const bankAccessApiClient = new BankAccessApiClient(
|
||||||
allowHttp: true,
|
bank.bankAccessApiBaseUrl,
|
||||||
baseUrl: bank.bankAccessApiBaseUrl,
|
);
|
||||||
});
|
|
||||||
const user = await bankAccessApiClient.createRandomBankUser();
|
const user = await bankAccessApiClient.createRandomBankUser();
|
||||||
bankAccessApiClient.setAuth(user);
|
bankAccessApiClient.setAuth(user);
|
||||||
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
const wop = await bankAccessApiClient.createWithdrawalOperation(
|
||||||
|
@ -39,10 +39,9 @@ export async function runWithdrawalManualTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
// Create a withdrawal operation
|
// Create a withdrawal operation
|
||||||
|
|
||||||
const bankAccessApiClient = new BankAccessApiClient({
|
const bankAccessApiClient = new BankAccessApiClient(
|
||||||
baseUrl: bank.bankAccessApiBaseUrl,
|
bank.bankAccessApiBaseUrl,
|
||||||
allowHttp: true,
|
);
|
||||||
});
|
|
||||||
|
|
||||||
const user = await bankAccessApiClient.createRandomBankUser();
|
const user = await bankAccessApiClient.createRandomBankUser();
|
||||||
|
|
||||||
@ -74,12 +73,15 @@ export async function runWithdrawalManualTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
const reservePub: string = wres.reservePub;
|
const reservePub: string = wres.reservePub;
|
||||||
|
|
||||||
const wireGatewayApiClient = new WireGatewayApiClient({
|
const wireGatewayApiClient = new WireGatewayApiClient(
|
||||||
wireGatewayApiBaseUrl: exchangeBankAccount.wireGatewayApiBaseUrl,
|
exchangeBankAccount.wireGatewayApiBaseUrl,
|
||||||
accountName: exchangeBankAccount.accountName,
|
{
|
||||||
accountPassword: exchangeBankAccount.accountPassword,
|
auth: {
|
||||||
allowHttp: true,
|
username: exchangeBankAccount.accountName,
|
||||||
});
|
password: exchangeBankAccount.accountPassword,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await wireGatewayApiClient.adminAddIncoming({
|
await wireGatewayApiClient.adminAddIncoming({
|
||||||
amount: "TESTKUDOS:10",
|
amount: "TESTKUDOS:10",
|
||||||
|
@ -55,7 +55,6 @@ interface PubkeyConf {
|
|||||||
|
|
||||||
const httpLib = createPlatformHttpLib({
|
const httpLib = createPlatformHttpLib({
|
||||||
enableThrottling: false,
|
enableThrottling: false,
|
||||||
allowHttp: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
interface ShellResult {
|
interface ShellResult {
|
||||||
|
@ -138,10 +138,7 @@ export class MerchantApiClient {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient = createPlatformHttpLib({
|
httpClient = createPlatformHttpLib();
|
||||||
allowHttp: true,
|
|
||||||
enableThrottling: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
async changeAuth(auth: MerchantAuthConfiguration): Promise<void> {
|
async changeAuth(auth: MerchantAuthConfiguration): Promise<void> {
|
||||||
const url = new URL("private/auth", this.baseUrl);
|
const url = new URL("private/auth", this.baseUrl);
|
||||||
|
@ -436,7 +436,10 @@ export function getExpiry(
|
|||||||
|
|
||||||
export interface HttpLibArgs {
|
export interface HttpLibArgs {
|
||||||
enableThrottling?: boolean;
|
enableThrottling?: boolean;
|
||||||
allowHttp?: boolean;
|
/**
|
||||||
|
* Only allow HTTPS connections, not plain http.
|
||||||
|
*/
|
||||||
|
requireTls?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function encodeBody(body: any): ArrayBuffer {
|
export function encodeBody(body: any): ArrayBuffer {
|
||||||
|
@ -63,11 +63,11 @@ const textDecoder = new TextDecoder();
|
|||||||
export class HttpLibImpl implements HttpRequestLibrary {
|
export class HttpLibImpl implements HttpRequestLibrary {
|
||||||
private throttle = new RequestThrottler();
|
private throttle = new RequestThrottler();
|
||||||
private throttlingEnabled = true;
|
private throttlingEnabled = true;
|
||||||
private allowHttp = false;
|
private requireTls = false;
|
||||||
|
|
||||||
constructor(args?: HttpLibArgs) {
|
constructor(args?: HttpLibArgs) {
|
||||||
this.throttlingEnabled = args?.enableThrottling ?? false;
|
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`,
|
`request to origin ${parsedUrl.origin} was throttled`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!this.allowHttp && parsedUrl.protocol !== "https:") {
|
if (this.requireTls && parsedUrl.protocol !== "https:") {
|
||||||
throw TalerError.fromDetail(
|
throw TalerError.fromDetail(
|
||||||
TalerErrorCode.WALLET_NETWORK_ERROR,
|
TalerErrorCode.WALLET_NETWORK_ERROR,
|
||||||
{
|
{
|
||||||
|
@ -41,11 +41,11 @@ const textDecoder = new TextDecoder();
|
|||||||
export class HttpLibImpl implements HttpRequestLibrary {
|
export class HttpLibImpl implements HttpRequestLibrary {
|
||||||
private throttle = new RequestThrottler();
|
private throttle = new RequestThrottler();
|
||||||
private throttlingEnabled = true;
|
private throttlingEnabled = true;
|
||||||
private allowHttp = false;
|
private requireTls = false;
|
||||||
|
|
||||||
constructor(args?: HttpLibArgs) {
|
constructor(args?: HttpLibArgs) {
|
||||||
this.throttlingEnabled = args?.enableThrottling ?? false;
|
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`,
|
`request to origin ${parsedUrl.origin} was throttled`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!this.allowHttp && parsedUrl.protocol !== "https:") {
|
if (this.requireTls && parsedUrl.protocol !== "https:") {
|
||||||
throw TalerError.fromDetail(
|
throw TalerError.fromDetail(
|
||||||
TalerErrorCode.WALLET_NETWORK_ERROR,
|
TalerErrorCode.WALLET_NETWORK_ERROR,
|
||||||
{
|
{
|
||||||
|
@ -244,7 +244,7 @@ async function createLocalWallet(
|
|||||||
const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
|
const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
|
||||||
const myHttpLib = createPlatformHttpLib({
|
const myHttpLib = createPlatformHttpLib({
|
||||||
enableThrottling: walletCliArgs.wallet.noThrottle ? false : true,
|
enableThrottling: walletCliArgs.wallet.noThrottle ? false : true,
|
||||||
allowHttp: walletCliArgs.wallet.noHttp ? false : true,
|
requireTls: walletCliArgs.wallet.noHttp,
|
||||||
});
|
});
|
||||||
const wallet = await createNativeWalletHost({
|
const wallet = await createNativeWalletHost({
|
||||||
persistentStoragePath: dbPath !== ":memory:" ? dbPath : undefined,
|
persistentStoragePath: dbPath !== ":memory:" ? dbPath : undefined,
|
||||||
@ -1259,10 +1259,7 @@ advancedCli
|
|||||||
help: "Run the 'bench-internal' benchmark",
|
help: "Run the 'bench-internal' benchmark",
|
||||||
})
|
})
|
||||||
.action(async (args) => {
|
.action(async (args) => {
|
||||||
const myHttpLib = createPlatformHttpLib({
|
const myHttpLib = createPlatformHttpLib();
|
||||||
enableThrottling: false,
|
|
||||||
allowHttp: true,
|
|
||||||
});
|
|
||||||
const res = await createNativeWalletHost2({
|
const res = await createNativeWalletHost2({
|
||||||
// No persistent DB storage.
|
// No persistent DB storage.
|
||||||
persistentStoragePath: undefined,
|
persistentStoragePath: undefined,
|
||||||
|
@ -99,177 +99,9 @@ const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
|
|||||||
.property("taler_withdraw_uri", codecForString())
|
.property("taler_withdraw_uri", codecForString())
|
||||||
.build("WithdrawalOperationInfo");
|
.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 {
|
export interface BankAccessApiClientArgs {
|
||||||
baseUrl: string;
|
|
||||||
auth?: { username: string; password: string };
|
auth?: { username: string; password: string };
|
||||||
enableThrottling?: boolean;
|
httpClient?: HttpRequestLibrary;
|
||||||
allowHttp?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BankAccessApiCreateTransactionRequest {
|
export interface BankAccessApiCreateTransactionRequest {
|
||||||
@ -278,11 +110,11 @@ export interface BankAccessApiCreateTransactionRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class WireGatewayApiClientArgs {
|
export class WireGatewayApiClientArgs {
|
||||||
accountName: string;
|
auth?: {
|
||||||
accountPassword: string;
|
username: string;
|
||||||
wireGatewayApiBaseUrl: string;
|
password: string;
|
||||||
enableThrottling?: boolean;
|
};
|
||||||
allowHttp?: boolean;
|
httpClient?: HttpRequestLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,11 +124,21 @@ export class WireGatewayApiClientArgs {
|
|||||||
export class WireGatewayApiClient {
|
export class WireGatewayApiClient {
|
||||||
httpLib;
|
httpLib;
|
||||||
|
|
||||||
constructor(private args: WireGatewayApiClientArgs) {
|
constructor(
|
||||||
this.httpLib = createPlatformHttpLib({
|
private baseUrl: string,
|
||||||
enableThrottling: !!args.enableThrottling,
|
private args: WireGatewayApiClientArgs = {},
|
||||||
allowHttp: !!args.allowHttp,
|
) {
|
||||||
});
|
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: {
|
async adminAddIncoming(params: {
|
||||||
@ -304,7 +146,7 @@ export class WireGatewayApiClient {
|
|||||||
reservePub: string;
|
reservePub: string;
|
||||||
debitAccountPayto: string;
|
debitAccountPayto: string;
|
||||||
}): Promise<void> {
|
}): 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, {
|
const resp = await this.httpLib.fetch(url.href, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {
|
body: {
|
||||||
@ -312,12 +154,7 @@ export class WireGatewayApiClient {
|
|||||||
reserve_pub: params.reservePub,
|
reserve_pub: params.reservePub,
|
||||||
debit_account: params.debitAccountPayto,
|
debit_account: params.debitAccountPayto,
|
||||||
},
|
},
|
||||||
headers: {
|
headers: this.makeAuthHeader(),
|
||||||
Authorization: makeBasicAuthHeader(
|
|
||||||
this.args.accountName,
|
|
||||||
this.args.accountPassword,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
logger.info(`add-incoming response status: ${resp.status}`);
|
logger.info(`add-incoming response status: ${resp.status}`);
|
||||||
await checkSuccessResponseOrThrow(resp);
|
await checkSuccessResponseOrThrow(resp);
|
||||||
@ -331,11 +168,11 @@ export class WireGatewayApiClient {
|
|||||||
export class BankAccessApiClient {
|
export class BankAccessApiClient {
|
||||||
httpLib: HttpRequestLibrary;
|
httpLib: HttpRequestLibrary;
|
||||||
|
|
||||||
constructor(private args: BankAccessApiClientArgs) {
|
constructor(
|
||||||
this.httpLib = createPlatformHttpLib({
|
private baseUrl: string,
|
||||||
enableThrottling: !!args.enableThrottling,
|
private args: BankAccessApiClientArgs = {},
|
||||||
allowHttp: !!args.allowHttp,
|
) {
|
||||||
});
|
this.httpLib = args.httpClient ?? createPlatformHttpLib();
|
||||||
}
|
}
|
||||||
|
|
||||||
setAuth(auth: { username: string; password: string }) {
|
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> {
|
async getTransactions(username: string): Promise<void> {
|
||||||
const auth = this.args.auth;
|
const reqUrl = new URL(`accounts/${username}/transactions`, this.baseUrl);
|
||||||
const reqUrl = new URL(
|
|
||||||
`accounts/${username}/transactions`,
|
|
||||||
this.args.baseUrl,
|
|
||||||
);
|
|
||||||
const resp = await this.httpLib.fetch(reqUrl.href, {
|
const resp = await this.httpLib.fetch(reqUrl.href, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
@ -376,10 +219,7 @@ export class BankAccessApiClient {
|
|||||||
username: string,
|
username: string,
|
||||||
req: BankAccessApiCreateTransactionRequest,
|
req: BankAccessApiCreateTransactionRequest,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const reqUrl = new URL(
|
const reqUrl = new URL(`accounts/${username}/transactions`, this.baseUrl);
|
||||||
`accounts/${username}/transactions`,
|
|
||||||
this.args.baseUrl,
|
|
||||||
);
|
|
||||||
|
|
||||||
const resp = await this.httpLib.fetch(reqUrl.href, {
|
const resp = await this.httpLib.fetch(reqUrl.href, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -395,9 +235,9 @@ export class BankAccessApiClient {
|
|||||||
password: string,
|
password: string,
|
||||||
options: {
|
options: {
|
||||||
iban?: string;
|
iban?: string;
|
||||||
},
|
} = {},
|
||||||
): Promise<BankUser> {
|
): 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, {
|
const resp = await this.httpLib.fetch(url.href, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {
|
body: {
|
||||||
@ -447,7 +287,7 @@ export class BankAccessApiClient {
|
|||||||
user: string,
|
user: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
): Promise<WithdrawalOperationInfo> {
|
): 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, {
|
const resp = await this.httpLib.fetch(url.href, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {
|
body: {
|
||||||
@ -467,7 +307,7 @@ export class BankAccessApiClient {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`accounts/${username}/withdrawals/${wopi.withdrawal_id}/confirm`,
|
`accounts/${username}/withdrawals/${wopi.withdrawal_id}/confirm`,
|
||||||
this.args.baseUrl,
|
this.baseUrl,
|
||||||
);
|
);
|
||||||
logger.info(`confirming withdrawal operation via ${url.href}`);
|
logger.info(`confirming withdrawal operation via ${url.href}`);
|
||||||
const resp = await this.httpLib.fetch(url.href, {
|
const resp = await this.httpLib.fetch(url.href, {
|
||||||
@ -488,7 +328,7 @@ export class BankAccessApiClient {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`accounts/${accountName}/withdrawals/${wopi.withdrawal_id}/abort`,
|
`accounts/${accountName}/withdrawals/${wopi.withdrawal_id}/abort`,
|
||||||
this.args.baseUrl,
|
this.baseUrl,
|
||||||
);
|
);
|
||||||
const resp = await this.httpLib.fetch(url.href, {
|
const resp = await this.httpLib.fetch(url.href, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -48,24 +48,20 @@ import {
|
|||||||
parsePaytoUri,
|
parsePaytoUri,
|
||||||
UnblindedSignature,
|
UnblindedSignature,
|
||||||
} from "@gnu-taler/taler-util";
|
} 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 {
|
import {
|
||||||
HttpRequestLibrary,
|
HttpRequestLibrary,
|
||||||
readSuccessResponseJsonOrThrow,
|
readSuccessResponseJsonOrThrow,
|
||||||
} from "@gnu-taler/taler-util/http";
|
} 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 {
|
import {
|
||||||
getBankStatusUrl,
|
getBankStatusUrl,
|
||||||
getBankWithdrawalInfo,
|
getBankWithdrawalInfo,
|
||||||
} from "./operations/withdraw.js";
|
} 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");
|
const logger = new Logger("dbless.ts");
|
||||||
|
|
||||||
@ -125,10 +121,10 @@ export async function topupReserveWithDemobank(
|
|||||||
bankAccessApiBaseUrl: bankAccessApiBaseUrl,
|
bankAccessApiBaseUrl: bankAccessApiBaseUrl,
|
||||||
http,
|
http,
|
||||||
};
|
};
|
||||||
const bankUser = await BankApi.createRandomBankUser(bankHandle);
|
const bankClient = new BankAccessApiClient(bankAccessApiBaseUrl);
|
||||||
const wopi = await BankAccessApi.createWithdrawalOperation(
|
const bankUser = await bankClient.createRandomBankUser();
|
||||||
bankHandle,
|
const wopi = await bankClient.createWithdrawalOperation(
|
||||||
bankUser,
|
bankUser.username,
|
||||||
amount,
|
amount,
|
||||||
);
|
);
|
||||||
const bankInfo = await getBankWithdrawalInfo(http, wopi.taler_withdraw_uri);
|
const bankInfo = await getBankWithdrawalInfo(http, wopi.taler_withdraw_uri);
|
||||||
@ -149,7 +145,7 @@ export async function topupReserveWithDemobank(
|
|||||||
httpResp,
|
httpResp,
|
||||||
codecForBankWithdrawalOperationPostResponse(),
|
codecForBankWithdrawalOperationPostResponse(),
|
||||||
);
|
);
|
||||||
await BankApi.confirmWithdrawalOperation(bankHandle, bankUser, wopi);
|
await bankClient.confirmWithdrawalOperation(bankUser.username, wopi);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function withdrawCoin(args: {
|
export async function withdrawCoin(args: {
|
||||||
|
@ -134,7 +134,7 @@ export async function createNativeWalletHost2(
|
|||||||
} else {
|
} else {
|
||||||
myHttpLib = createPlatformHttpLib({
|
myHttpLib = createPlatformHttpLib({
|
||||||
enableThrottling: true,
|
enableThrottling: true,
|
||||||
allowHttp: args.config?.features?.allowHttp,
|
requireTls: !args.config?.features?.allowHttp,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ export async function createNativeWalletHost2(
|
|||||||
} else {
|
} else {
|
||||||
myHttpLib = createPlatformHttpLib({
|
myHttpLib = createPlatformHttpLib({
|
||||||
enableThrottling: true,
|
enableThrottling: true,
|
||||||
allowHttp: args.config?.features?.allowHttp,
|
requireTls: !args.config?.features?.allowHttp,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user