commit 592bbe8eda310b531f38105f666c8dabc341cad9
parent e6b58c34b64a866e71cba09cf5e5dfad0912e318
Author: Sebastian <sebasjm@gmail.com>
Date: Thu, 10 Apr 2025 09:08:53 -0300
fix kyc auth http api
Diffstat:
4 files changed, 55 insertions(+), 65 deletions(-)
diff --git a/packages/taler-harness/src/harness/environments.ts b/packages/taler-harness/src/harness/environments.ts
@@ -46,9 +46,12 @@ import {
succeedOrThrow,
TalerCorebankApiClient,
TalerCoreBankHttpClient,
+ TalerExchangeApi,
+ TalerExchangeHttpClient,
TalerMerchantApi,
TalerMerchantInstanceHttpClient,
TalerProtocolTimestamp,
+ TalerWireGatewayHttpClient,
TransactionIdStr,
TransactionMajorState,
TransactionMinorState,
@@ -89,6 +92,7 @@ import {
} from "./harness.js";
import * as fs from "node:fs";
+import { deprecate } from "node:util";
const logger = new Logger("helpers.ts");
@@ -1093,7 +1097,14 @@ export interface KycTestEnv {
walletService: WalletService;
amlKeypair: EddsaKeyPairStrings;
merchant: MerchantService;
+ /**
+ * @deprecated
+ */
wireGatewayApiClient: WireGatewayApiClient;
+ bankApi: TalerCoreBankHttpClient;
+ exchangeApi: TalerExchangeHttpClient;
+ wireGatewayApi: TalerWireGatewayHttpClient;
+ merchantApi: TalerMerchantInstanceHttpClient;
}
export async function createKycTestkudosEnvironment(
@@ -1245,6 +1256,27 @@ export async function createKycTestkudosEnvironment(
t.logStep("env-setup-done");
+ const bankApi = new TalerCoreBankHttpClient(
+ bankClient.baseUrl,
+ harnessHttpLib,
+ );
+
+ const wireGatewayApi = new TalerWireGatewayHttpClient(
+ bankApi.getWireGatewayAPI(exchangeBankAccount.accountName).href,
+ exchangeBankAccount.accountName,
+ harnessHttpLib,
+ );
+
+ const merchantApi = new TalerMerchantInstanceHttpClient(
+ merchant.makeInstanceBaseUrl(),
+ harnessHttpLib,
+ );
+
+ const exchangeApi = new TalerExchangeHttpClient(
+ exchange.baseUrl,
+ harnessHttpLib,
+ );
+
return {
commonDb: db,
exchange,
@@ -1255,6 +1287,10 @@ export async function createKycTestkudosEnvironment(
exchangeBankAccount,
merchant,
wireGatewayApiClient,
+ bankApi,
+ wireGatewayApi,
+ merchantApi,
+ exchangeApi,
};
}
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
@@ -85,11 +85,15 @@ function adjustExchangeConfig(config: Configuration) {
async function retryUntil<T, X extends T>(
fx: () => Promise<T>,
condition: (x: T, i: number) => boolean,
+ maxRetry: number = 10,
waitMs: number = 500,
): Promise<X> {
let i = 0;
let x = await fx();
while (!condition(x, i)) {
+ if (i > maxRetry) {
+ throw Error("Too many retries");
+ }
logger.info(
`retrying since condition was false: ${j2s({ value: x, time: i })}`,
);
@@ -104,54 +108,16 @@ export async function runKycMerchantDepositRewriteTest(t: GlobalTestState) {
// Set up test environment
const {
- merchant,
- bankClient,
- exchange,
exchangeBankAccount,
- wireGatewayApiClient,
amlKeypair,
+ bankApi,
+ merchantApi,
+ wireGatewayApi,
+ exchangeApi,
} = await createKycTestkudosEnvironment(t, {
adjustExchangeConfig,
});
- // let accountPub: string;
-
- // const instanceUrl = new URL("private", merchant.makeInstanceBaseUrl());
- // {
- // const resp = await harnessHttpLib.fetch(instanceUrl.href);
- // const parsedResp = await readSuccessResponseJsonOrThrow(
- // resp,
- // codecForQueryInstancesResponse(),
- // );
- // accountPub = parsedResp.merchant_pub;
- // }
-
- // const wireGatewayApiClient = new WireGatewayApiClient(
- // exchangeBankAccount.wireGatewayApiBaseUrl,
- // {
- // auth: {
- // username: "admin",
- // password: "admin-password",
- // },
- // },
- // );
-
- const bankApi = new TalerCoreBankHttpClient(
- bankClient.baseUrl,
- harnessHttpLib,
- );
-
- const wireGatewayApi = new TalerWireGatewayHttpClient(
- bankApi.getWireGatewayAPI(exchangeBankAccount.accountName).href,
- exchangeBankAccount.accountName,
- harnessHttpLib,
- );
-
- const merchantApi = new TalerMerchantInstanceHttpClient(
- merchant.makeInstanceBaseUrl(),
- harnessHttpLib,
- );
-
let exchangeWireTarget: string | undefined;
let merchantBankAccount: string | undefined;
{
@@ -212,12 +178,6 @@ export async function runKycMerchantDepositRewriteTest(t: GlobalTestState) {
);
logger.info("Creating an order failed, which is ok ");
- // const adminLogin = succeedOrThrow(
- // await bankApi.createAccessTokenBasic("admin", "admin-password", {
- // scope: "readwrite",
- // }),
- // );
-
succeedOrThrow(
await bankApi.createAccount(undefined, {
name: "merchant-default",
@@ -228,25 +188,19 @@ export async function runKycMerchantDepositRewriteTest(t: GlobalTestState) {
);
logger.info("Bank account created");
-
const info = succeedOrThrow(
await merchantApi.getCurrentInstanceDetails(undefined),
);
- // FIXME: why admin? this should be wired to the exchange bank account
- await wireGatewayApiClient.adminAddKycauth({
- amount: "TESTKUDOS:0.1",
- debitAccountPayto: merchantBankAccount,
- accountPub: info.merchant_pub,
- });
+ succeedOrThrow(
+ await wireGatewayApi.addKycAuth(exchangeBankAccount.accountPassword, {
+ account_pub: info.merchant_pub,
+ amount: "TESTKUDOS:0.1",
+ debit_account: merchantBankAccount,
+ }),
+ );
logger.info("Money wired");
- // wireGatewayApi.addKycAuth(exchangeBankAccount.accountPassword, {
- // reserve_pub: info.merchant_pub,
- // amount: "TESTKUDOS:0.1",
- // debit_account: merchantBankAccount,
- // });
-
let merchantAmlAccount;
{
const kycStatus = await retryUntil(
@@ -286,7 +240,7 @@ export async function runKycMerchantDepositRewriteTest(t: GlobalTestState) {
await postAmlDecisionNoRules(t, {
amlPriv: amlKeypair.priv,
amlPub: amlKeypair.pub,
- exchangeBaseUrl: exchange.baseUrl,
+ exchangeBaseUrl: exchangeApi.baseUrl,
paytoHash: merchantAmlAccount,
});
@@ -313,7 +267,6 @@ export async function runKycMerchantDepositRewriteTest(t: GlobalTestState) {
t.assertTrue(!!kycStatus);
logger.info(`kyc resp 3: ${j2s(kycStatus)}`);
}
-
}
runKycMerchantDepositRewriteTest.suites = ["wallet", "merchant", "kyc"];
diff --git a/packages/taler-util/src/http-client/bank-wire.ts b/packages/taler-util/src/http-client/bank-wire.ts
@@ -309,7 +309,7 @@ export class TalerWireGatewayHttpClient {
* https://docs.taler.net/core/api-bank-wire.html#post--admin-add-kycauth
*
*/
- async addKycAuth(auth: string, body: TalerWireGatewayApi.AddIncomingRequest) {
+ async addKycAuth(auth: string, body: TalerWireGatewayApi.AddKycauthRequest) {
const url = new URL(`admin/add-kycauth`, this.baseUrl);
const resp = await this.httpLib.fetch(url.href, {
method: "POST",
diff --git a/packages/taler-util/src/types-taler-challenger.ts b/packages/taler-util/src/types-taler-challenger.ts
@@ -60,7 +60,7 @@ export interface ChallengerTermsOfServiceResponse {
restrictions: Record<string, Restriction> | undefined;
// @since v2.
- address_type: "email" | "phone";
+ address_type: "email" | "phone" | "address";
}
export interface ChallengeSetupResponse {
@@ -210,6 +210,7 @@ export const codecForChallengerTermsOfServiceResponse =
codecForEither(
codecForConstString("phone"),
codecForConstString("email"),
+ codecForConstString("address"),
),
)
.build("ChallengerApi.ChallengerTermsOfServiceResponse");