taler-typescript-core

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

commit d3f5967df502f17907da56c13199c45bd956f2af
parent 4b414dbd7764d40ffec93acfd466f02a731e9a3a
Author: Florian Dold <florian@dold.me>
Date:   Wed, 19 Feb 2025 18:30:11 +0100

wallet-core: report missing exchange entry via gana EC

Corresponding EC is WALLET_EXCHANGE_ENTRY_NOT_FOUND.

Diffstat:
M.vscode/settings.json | 3++-
Mpackages/taler-util/src/taler-error-codes.ts | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Mpackages/taler-wallet-core/src/exchanges.ts | 11+++++++++--
3 files changed, 140 insertions(+), 20 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json @@ -49,5 +49,6 @@ "typescript.preferences.importModuleSpecifierEnding": "js", "typescript.preferences.importModuleSpecifier": "project-relative", "javascript.preferences.importModuleSpecifier": "project-relative", - "javascript.preferences.importModuleSpecifierEnding": "js" + "javascript.preferences.importModuleSpecifierEnding": "js", + "makefile.configureOnOpen": false } diff --git a/packages/taler-util/src/taler-error-codes.ts b/packages/taler-util/src/taler-error-codes.ts @@ -217,7 +217,7 @@ export enum TalerErrorCode { /** - * The service refused the request due to lack of proper authorization. + * The service refused the request due to lack of proper authorization. Accessing this endpoint requires an access token from the account owner. * Returned with an HTTP status code of #MHD_HTTP_UNAUTHORIZED (401). * (A value of 0 indicates that the error is generated client-side). */ @@ -225,7 +225,7 @@ export enum TalerErrorCode { /** - * The service refused the request as the given authorization token is unknown. + * The service refused the request as the given authorization token is unknown. You should request a valid access token from the account owner. * Returned with an HTTP status code of #MHD_HTTP_UNAUTHORIZED (401). * (A value of 0 indicates that the error is generated client-side). */ @@ -233,7 +233,7 @@ export enum TalerErrorCode { /** - * The service refused the request as the given authorization token expired. + * The service refused the request as the given authorization token expired. You should request a fresh authorization token from the account owner. * Returned with an HTTP status code of #MHD_HTTP_UNAUTHORIZED (401). * (A value of 0 indicates that the error is generated client-side). */ @@ -241,7 +241,7 @@ export enum TalerErrorCode { /** - * The service refused the request as the given authorization token is malformed. + * The service refused the request as the given authorization token is invalid or malformed. You should check that you have the right credentials. * Returned with an HTTP status code of #MHD_HTTP_UNAUTHORIZED (401). * (A value of 0 indicates that the error is generated client-side). */ @@ -249,7 +249,7 @@ export enum TalerErrorCode { /** - * The service refused the request due to lack of proper rights on the resource. + * The service refused the request due to lack of proper rights on the resource. You may need different credentials to be allowed to perform this operation. * Returned with an HTTP status code of #MHD_HTTP_FORBIDDEN (403). * (A value of 0 indicates that the error is generated client-side). */ @@ -690,7 +690,7 @@ export enum TalerErrorCode { /** * The KYC operation failed. This could be because the KYC provider rejected the KYC data provided, or because the user aborted the KYC process. - * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500). * (A value of 0 indicates that the error is generated client-side). */ EXCHANGE_GENERIC_KYC_FAILED = 1038, @@ -698,7 +698,7 @@ export enum TalerErrorCode { /** * A fallback measure for a KYC operation failed. This is a bug. Users should contact the exchange operator. - * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500). * (A value of 0 indicates that the error is generated client-side). */ EXCHANGE_GENERIC_KYC_FALLBACK_FAILED = 1039, @@ -706,7 +706,7 @@ export enum TalerErrorCode { /** * The specified fallback measure for a KYC operation is unknown. This is a bug. Users should contact the exchange operator. - * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500). * (A value of 0 indicates that the error is generated client-side). */ EXCHANGE_GENERIC_KYC_FALLBACK_UNKNOWN = 1040, @@ -721,6 +721,22 @@ export enum TalerErrorCode { /** + * The AML processing at the exchange did not terminate in an adequate timeframe. This is likely a configuration problem at the payment service provider. Users should contact the exchange operator. + * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_GENERIC_AML_PROGRAM_RECURSION_DETECTED = 1042, + + + /** + * A check against sanction lists failed. This is indicative of an internal error in the sanction list processing logic. This needs to be investigated by the exchange operator. + * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_GENERIC_KYC_SANCTION_LIST_CHECK_FAILED = 1043, + + + /** * The exchange did not find information about the specified transaction in the database. * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404). * (A value of 0 indicates that the error is generated client-side). @@ -857,7 +873,7 @@ export enum TalerErrorCode { /** - * The client re-used a withdraw nonce, which is not allowed. + * The client reused a withdraw nonce, which is not allowed. * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). */ @@ -869,7 +885,7 @@ export enum TalerErrorCode { * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). * (A value of 0 indicates that the error is generated client-side). */ - EXCHANGE_AGE_WITHDRAW_COMMITMENT_UNKNOWN = 1161, + EXCHANGE_WITHDRAW_COMMITMENT_UNKNOWN = 1161, /** @@ -877,7 +893,7 @@ export enum TalerErrorCode { * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500). * (A value of 0 indicates that the error is generated client-side). */ - EXCHANGE_AGE_WITHDRAW_AMOUNT_OVERFLOW = 1162, + EXCHANGE_WITHDRAW_AMOUNT_OVERFLOW = 1162, /** @@ -893,7 +909,7 @@ export enum TalerErrorCode { * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). * (A value of 0 indicates that the error is generated client-side). */ - EXCHANGE_AGE_WITHDRAW_REVEAL_INVALID_HASH = 1164, + EXCHANGE_WITHDRAW_REVEAL_INVALID_HASH = 1164, /** @@ -901,7 +917,7 @@ export enum TalerErrorCode { * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). */ - EXCHANGE_AGE_WITHDRAW_MAXIMUM_AGE_TOO_LARGE = 1165, + EXCHANGE_WITHDRAW_MAXIMUM_AGE_TOO_LARGE = 1165, /** @@ -909,7 +925,7 @@ export enum TalerErrorCode { * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). */ - EXCHANGE_WITHDRAW_BATCH_IDEMPOTENT_PLANCHET = 1175, + EXCHANGE_WITHDRAW_IDEMPOTENT_PLANCHET = 1175, /** @@ -1785,6 +1801,22 @@ export enum TalerErrorCode { /** + * The exchange already has this denomination key configured, but with different meta data. This should not be possible, contact the developers for support. + * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_MANAGEMENT_CONFLICTING_DENOMINATION_META_DATA = 1832, + + + /** + * The exchange already has this signing key configured, but with different meta data. This should not be possible, contact the developers for support. + * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_MANAGEMENT_CONFLICTING_SIGNKEY_META_DATA = 1833, + + + /** * The purse was previously created with different meta data. * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). @@ -1953,6 +1985,14 @@ export enum TalerErrorCode { /** + * The exchange tried to run an AML program, but that program did not terminate on time. Contact the exchange operator to address the AML program bug or performance issue. If it is not a performance issue, the timeout might have to be increased (requires changes to the source code). + * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_KYC_GENERIC_AML_PROGRAM_TIMEOUT = 1918, + + + /** * The KYC info access token is not recognized. Hence the request was denied. * Returned with an HTTP status code of #MHD_HTTP_FORBIDDEN (403). * (A value of 0 indicates that the error is generated client-side). @@ -2473,6 +2513,30 @@ export enum TalerErrorCode { /** + * The token family is not known to the backend. + * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_GENERIC_TOKEN_FAMILY_UNKNOWN = 2026, + + + /** + * The token family key is not known to the backend. Check the local system time on the client, maybe an expired (or not yet valid) token was used. + * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_GENERIC_TOKEN_KEY_UNKNOWN = 2027, + + + /** + * The merchant backend is not configured to support the DONAU protocol. + * Returned with an HTTP status code of #MHD_HTTP_NOT_IMPLEMENTED (501). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_GENERIC_DONAU_NOT_CONFIGURED = 2028, + + + /** * The exchange failed to provide a valid answer to the tracking request, thus those details are not in the response. * Returned with an HTTP status code of #MHD_HTTP_OK (200). * (A value of 0 indicates that the error is generated client-side). @@ -2513,6 +2577,14 @@ export enum TalerErrorCode { /** + * The contract terms version is not invalid. + * Returned with an HTTP status code of #MHD_HTTP_FORBIDDEN (403). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_GET_ORDERS_ID_INVALID_CONTRACT_VERSION = 2107, + + + /** * The exchange responded saying that funds were insufficient (for example, due to double-spending). * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). @@ -2778,7 +2850,7 @@ export enum TalerErrorCode { /** * The payment violates a transaction limit configured at the given exchange. The wallet has a bug in that it failed to check exchange limits during coin selection. Please report the bug to your wallet developer. - * Returned with an HTTP status code of #MHD_HTTP_FORBIDDEN (403). + * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). * (A value of 0 indicates that the error is generated client-side). */ MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_TRANSACTION_LIMIT_VIOLATION = 2184, @@ -3073,7 +3145,7 @@ export enum TalerErrorCode { /** - * The backend does not trust any exchange that would allow funds to be wired to any bank account of this instance using the wire method specified with the order. Note that right now, we do not support the use of exchange bank accounts with mandatory currency conversion. + * The backend does not trust any exchange that would allow funds to be wired to any bank account of this instance using the wire method specified with the order. (Note that right now, we do not support the use of exchange bank accounts with mandatory currency conversion.) One likely cause for this is that the taler-merchant-exchangekeyupdate process is not running. * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). */ @@ -3113,6 +3185,14 @@ export enum TalerErrorCode { /** + * A currency specified to be paid in the contract is not supported by any exchange that this instance can currently use. Possible solutions include (1) specifying a different currency, (2) adding additional suitable exchange operators to the merchant backend configuration, or (3) satisfying compliance rules of an configured exchange to begin using the service of that provider. + * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_PRIVATE_POST_ORDERS_NO_EXCHANGE_FOR_CURRENCY = 2514, + + + /** * The order provided to the backend could not be deleted, our offer is still valid and awaiting payment. Deletion may work later after the offer has expired if it remains unpaid. * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). @@ -3937,6 +4017,30 @@ export enum TalerErrorCode { /** + * Bank account is locked and cannot authenticate using his password. + * Returned with an HTTP status code of #MHD_HTTP_FORBIDDEN (403). + * (A value of 0 indicates that the error is generated client-side). + */ + BANK_ACCOUNT_LOCKED = 5152, + + + /** + * The client attempted to update a transaction' details that was already aborted. + * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). + * (A value of 0 indicates that the error is generated client-side). + */ + BANK_UPDATE_ABORT_CONFLICT = 5153, + + + /** + * The wtid for a request to transfer funds has already been used, but with a different request unpaid. + * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). + * (A value of 0 indicates that the error is generated client-side). + */ + BANK_TRANSFER_WTID_REUSED = 5154, + + + /** * The sync service failed find the account in its database. * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404). * (A value of 0 indicates that the error is generated client-side). @@ -4417,6 +4521,14 @@ export enum TalerErrorCode { /** + * The wallet does not have an entry for the requested exchange. + * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * (A value of 0 indicates that the error is generated client-side). + */ + WALLET_EXCHANGE_ENTRY_NOT_FOUND = 7045, + + + /** * We encountered a timeout with our payment backend. * Returned with an HTTP status code of #MHD_HTTP_GATEWAY_TIMEOUT (504). * (A value of 0 indicates that the error is generated client-side). @@ -5025,7 +5137,7 @@ export enum TalerErrorCode { /** - * The client re-used a unique donor identifier nonce, which is not allowed. + * The client reused a unique donor identifier nonce, which is not allowed. * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409). * (A value of 0 indicates that the error is generated client-side). */ diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts @@ -550,7 +550,7 @@ export async function lookupExchangeByUri( wex: WalletExecutionContext, req: GetExchangeEntryByUrlRequest, ): Promise<ExchangeListItem> { - return await wex.db.runReadOnlyTx( + const res = await wex.db.runReadOnlyTx( { storeNames: [ "exchanges", @@ -564,7 +564,7 @@ export async function lookupExchangeByUri( async (tx) => { const exchangeRec = await tx.exchanges.get(req.exchangeBaseUrl); if (!exchangeRec) { - throw Error("exchange not found"); + return undefined; } const exchangeDetails = await getExchangeRecordsInternal( tx, @@ -589,6 +589,13 @@ export async function lookupExchangeByUri( ); }, ); + if (!res) { + throw TalerError.fromDetail( + TalerErrorCode.WALLET_EXCHANGE_ENTRY_NOT_FOUND, + {}, + ); + } + return res; } /**