taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit daf91276b5fc16d92cd6d0886e4aa4d433461b7e
parent c75dd99d0ffd2aa06dccd4d61291fbaa03661124
Author: Sebastian <sebasjm@gmail.com>
Date:   Tue,  8 Apr 2025 07:46:13 -0300

merchant tools in harness

Diffstat:
Mpackages/taler-harness/package.json | 1+
Mpackages/taler-harness/src/index.ts | 106++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mpnpm-lock.yaml | 31++++++++++++++++++-------------
3 files changed, 124 insertions(+), 14 deletions(-)

diff --git a/packages/taler-harness/package.json b/packages/taler-harness/package.json @@ -40,6 +40,7 @@ "dependencies": { "@gnu-taler/taler-util": "workspace:*", "@gnu-taler/taler-wallet-core": "workspace:*", + "postgres": "^3.4.5", "tslib": "^2.6.2" } } diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts @@ -25,12 +25,16 @@ import { BalancesResponse, Configuration, Duration, + EddsaPrivP, HttpStatusCode, Logger, MerchantAuthMethod, PaytoString, + ReserveAccount, + ReservePub, TalerBankConversionHttpClient, TalerCoreBankHttpClient, + TalerExchangeHttpClient, TalerKycAml, TalerMerchantInstanceHttpClient, TalerMerchantManagementHttpClient, @@ -42,10 +46,14 @@ import { encodeCrock, generateIban, getRandomBytes, + hashNormalizedPaytoUri, + isOperationFail, j2s, + parsePaytoUri, randomBytes, rsaBlind, setGlobalLogLevelFromString, + setPrintHttpRequestAsCurl, stringifyPayTemplateUri, succeedOrThrow, } from "@gnu-taler/taler-util"; @@ -89,6 +97,8 @@ import { import { AML_PROGRAM_TEST_KYC_NEW_MEASURES_PROG } from "./integrationtests/test-kyc-new-measures-prog.js"; import { getTestInfo, runTests } from "./integrationtests/testrunner.js"; import { lintExchangeDeployment, lintExchangeUrl } from "./lint.js"; +import postgres from "postgres"; +import { URLImpl } from "../../taler-util/src/whatwg-url.js"; const logger = new Logger("taler-harness:index.ts"); @@ -1062,7 +1072,7 @@ deploymentCli `unable to login into bank accountfor user ${id}, 2fa required`, ); console.error(j2s(resp.body)); - process.exit(2); + process.exit(2); } console.error( `unable to login into bank accountfor user ${id}, status ${resp.case}`, @@ -1700,6 +1710,100 @@ amlProgramCli console.log(j2s(outcome)); }); +export const merchantCli = talerHarnessCli.subcommand("merchant", "merchant", { + help: "Merchant backend tools.", +}); + +merchantCli + .subcommand("checkKyc", "check-kyc", { + help: "gets updated information about the kyc state" + }) + .requiredArgument("config", clk.STRING, { + help: "configuration file" + }) + .maybeOption("id", ["--id"], clk.STRING, { + help: "selected instance id of the merchant backend, default to 'admin'", + default: "admin", + }) + .action(async (args) => { + const config = Configuration.load(args.checkKyc.config); + + const db = merchantDatabase(config); + + const instanceId = args.checkKyc.id ?? "admin"; + const { merchant_priv } = await db.getInstancePrivateKey(instanceId); + + const allAccounts = await db.getInstanceKycStatus(instanceId); + + const httpLib = createPlatformHttpLib(); + const info = await Promise.all( + allAccounts.map(async ({ exchange_url, payto_uri }) => { + const exchangeApi = new TalerExchangeHttpClient(exchange_url, httpLib); + const kyc_status = await exchangeApi.checkKycStatus( + merchant_priv, + encodeCrock(hashNormalizedPaytoUri(parsePaytoUri(payto_uri)!)), + ); + return { + payto_uri, + exchange_url, + kyc_status, + }; + }), + ); + db.close(); + console.log(j2s(info)); + }); + export function main() { talerHarnessCli.run(); } + +function merchantDatabase(config: Configuration) { + const dbUrl = config.getString("MERCHANTDB-POSTGRES", "CONFIG").getValue(); + if (!dbUrl) { + throw Error("missing dbUrl"); + } + + let path: string | undefined; + const { hostname: DB_HOST, port: DB_PORT } = new URLImpl(dbUrl); + if (DB_HOST.startsWith("%2F")) { + path = `${decodeURIComponent(DB_HOST)}/.s.PGSQL.${DB_PORT}`; + } + const postgresql = postgres(dbUrl, { path }); + + return { + close() { + return postgresql.end(); + }, + async getInstancePrivateKey(instanceId: string) { + type Result = { merchant_priv: EddsaPrivP }[]; + return ( + await postgresql<Result>` + SELECT merchant_priv + FROM merchant.merchant_keys AS mk + JOIN merchant.merchant_instances AS mi ON mi.merchant_serial = mk.merchant_serial + WHERE mi.merchant_id = ${instanceId}` + )[0]; + }, + async getInstanceKycStatus(instanceId: string) { + type Result = { + // merchant_kyc + kyc_ok: boolean; + exchange_url: string; + access_token: string | undefined; + exchange_http_status: number; + exchange_ec_code: number; + aml_review: boolean; + jaccount_limits: object; + // merchant_accounts + payto_uri: string; + }[]; + return await postgresql<Result>` + SELECT kyc.*, ma.payto_uri + FROM merchant.merchant_instances AS mi + JOIN merchant.merchant_kyc as kyc ON kyc.kyc_serial_id = mi.merchant_serial + JOIN merchant.merchant_accounts ma ON ma.account_serial = kyc.account_serial + WHERE mi.merchant_id = ${instanceId}`; + }, + }; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml @@ -403,7 +403,7 @@ importers: version: 6.19.0(eslint@8.56.0)(typescript@5.7.3) autoprefixer: specifier: ^10.4.14 - version: 10.4.14(postcss@8.4.23) + version: 10.4.14(postcss@8.4.49) chai: specifier: ^4.3.6 version: 4.3.6 @@ -818,6 +818,9 @@ importers: '@gnu-taler/taler-wallet-core': specifier: workspace:* version: link:../taler-wallet-core + postgres: + specifier: ^3.4.5 + version: 3.4.5 tslib: specifier: ^2.6.2 version: 2.6.2 @@ -4036,6 +4039,7 @@ packages: bulma-timeline@3.0.5: resolution: {integrity: sha512-gBwdx7PmAEZ/+5zSn/ZBJBqkenT8wi+9nlD0uP8lXa3rGcbhG+fp8Oz98+3O10LQPlUEdKPYEUxtQ55okRfhTQ==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. bulma-upload-control@1.2.0: resolution: {integrity: sha512-2raueVPVoG3KjHH+7Aok44nGSPIl76qzdkLKX/ziHAOwbiXBrlEYHXca8Hk0UDa0KElLiPT6Eb2Cvz+8FFUwBw==} @@ -5661,7 +5665,7 @@ packages: resolution: {integrity: sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==} engines: {node: '>= 4.0'} os: [darwin] - deprecated: Upgrade to fsevents v2 to mitigate potential security issues + deprecated: The v1 package contains DANGEROUS / INSECURE binaries. Upgrade to safe fsevents v2 fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} @@ -8209,6 +8213,10 @@ packages: resolution: {integrity: sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA==} engines: {node: ^10 || ^12 || >=14} + postgres@3.4.5: + resolution: {integrity: sha512-cDWgoah1Gez9rN3H4165peY9qfpEo+SA61oQv65O3cRUE1pOEoJWwddwcqKE8XZYjbblOJlYDlLV4h67HrEVDg==} + engines: {node: '>=12'} + preact-cli@3.4.1: resolution: {integrity: sha512-/4be0PuBmAIAox9u8GLJublFpEymq7Lk4JW4PEPz9ErFH/ncZf/oBPhECtXGq9IPqNOEe4r2l8sA+3uqKVwBfw==} engines: {node: '>=12'} @@ -9513,9 +9521,6 @@ packages: tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - tslib@2.8.1: - resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - tsutils@3.21.0: resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} @@ -14712,7 +14717,7 @@ snapshots: camel-case@4.1.2: dependencies: pascal-case: 3.1.2 - tslib: 2.8.1 + tslib: 2.6.2 camelcase-css@2.0.1: {} @@ -15677,7 +15682,7 @@ snapshots: dot-case@3.0.4: dependencies: no-case: 3.0.4 - tslib: 2.8.1 + tslib: 2.6.2 dot-prop@5.3.0: dependencies: @@ -18016,7 +18021,7 @@ snapshots: lower-case@2.0.2: dependencies: - tslib: 2.8.1 + tslib: 2.6.2 lowercase-keys@1.0.1: {} @@ -18431,7 +18436,7 @@ snapshots: no-case@3.0.4: dependencies: lower-case: 2.0.2 - tslib: 2.8.1 + tslib: 2.6.2 node-domexception@1.0.0: {} @@ -18823,7 +18828,7 @@ snapshots: param-case@3.0.4: dependencies: dot-case: 3.0.4 - tslib: 2.8.1 + tslib: 2.6.2 parent-module@1.0.1: dependencies: @@ -18876,7 +18881,7 @@ snapshots: pascal-case@3.1.2: dependencies: no-case: 3.0.4 - tslib: 2.8.1 + tslib: 2.6.2 pascalcase@0.1.1: {} @@ -19480,6 +19485,8 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 + postgres@3.4.5: {} + preact-cli@3.4.1(encoding@0.1.13)(eslint@8.56.0)(preact-render-to-string@5.2.6(preact@10.11.3))(preact@10.11.3)(ts-node@10.9.1(@types/node@18.11.17)(typescript@5.7.3)): dependencies: '@babel/core': 7.18.9 @@ -21069,8 +21076,6 @@ snapshots: tslib@2.6.2: {} - tslib@2.8.1: {} - tsutils@3.21.0(typescript@5.7.3): dependencies: tslib: 1.14.1