taler-typescript-core

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

commit ab67954124d3d768e40045c9acadbe4a3802b4ea
parent 92fe83b4c40419349b80b425824fdd66b7ee0205
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Thu, 22 Oct 2026 14:51:10 +0200

mailbox/taldir: correctly use progress token logic for HTTP calls

Diffstat:
Mpackages/taler-wallet-core/src/mailbox.ts | 67+++++++++++++++++++++++++++++++++++++++++++------------------------
Mpackages/taler-wallet-core/src/taldir.ts | 38+++++++++++++++++++++++++-------------
2 files changed, 68 insertions(+), 37 deletions(-)

diff --git a/packages/taler-wallet-core/src/mailbox.ts b/packages/taler-wallet-core/src/mailbox.ts @@ -65,6 +65,7 @@ import { import { WalletExecutionContext } from "./wallet.js"; import { runWithMaybeProgressContext, + runWithProgressRetries, } from "./progress.js"; @@ -205,7 +206,9 @@ async function internalRegisterMailbox( wex.http, ); - const resp = await mailboxClient.registerMailbox(httpReq); + const resp = await runWithProgressRetries(wex, async () => + await mailboxClient.registerMailbox(httpReq), + ); switch (resp.case) { case "ok": return resp.body; @@ -274,10 +277,12 @@ async function internalInitializeMailbox( expiration: AbsoluteTime.toProtocolTimestamp(nowInAYear), }; - const resp = await registerMailbox(wex, { - mailboxConf: mailboxConf, - progressToken: req.progressToken, - }); + const resp = await runWithProgressRetries(wex, async () => + await registerMailbox(wex, { + mailboxConf: mailboxConf, + progressToken: req.progressToken, + }), + ); if (resp.status == "payment-required") { if (!resp.talerUri) { throw TalerError.fromDetail( @@ -351,7 +356,9 @@ async function internalRefreshMailbox( // Refresh message size var message_size; var message_response_limit; - const resConf = await mailboxClient.getConfig(); + const resConf = await runWithProgressRetries(wex, async () => + await mailboxClient.getConfig(), + ); switch (resConf.case) { case "ok": message_size = resConf.body.message_body_bytes; @@ -387,9 +394,11 @@ async function internalRefreshMailbox( batchIndex < MAX_MAILBOX_REFRESH_BATCHES; batchIndex++ ) { - const res = await mailboxClient.getMessages({ - hMailbox: mailboxConf.hAddress, - }); + const res = await runWithProgressRetries(wex, async () => + await mailboxClient.getMessages({ + hMailbox: mailboxConf.hAddress, + }), + ); if (res.case !== "ok") { throw TalerError.fromDetail( TalerErrorCode.WALLET_MAILBOX_UNAVAILABLE, @@ -430,7 +439,9 @@ async function internalRefreshMailbox( downloadedAt: now, }; records.push(newMessage); - await addMailboxMessage(wex, { message: newMessage }); + await runWithProgressRetries(wex, async () => + await addMailboxMessage(wex, { message: newMessage }), + ); } const messageBuffer = new ArrayBuffer(16); @@ -443,13 +454,15 @@ async function internalRefreshMailbox( new Uint8Array(messageBuffer), privateSigningKey, ); - succeedOrThrow( - await mailboxClient.deleteMessages({ - mailboxConf, - matchIf: res.body.etag, - count: numMessages, - signature: encodeCrock(signature), - }), + await runWithProgressRetries(wex, async () => + succeedOrThrow( + await mailboxClient.deleteMessages({ + mailboxConf, + matchIf: res.body.etag, + count: numMessages, + signature: encodeCrock(signature), + }), + ), ); if (!mailboxBatchMayHaveMoreMessages(numMessages, message_response_limit)) { @@ -518,7 +531,9 @@ async function internalSendTalerUriMessage( ); // Get message size var paddedMessageSize; - const resConf = await mailboxClient.getConfig(); + const resConf = await runWithProgressRetries(wex, async () => + await mailboxClient.getConfig(), + ); switch (resConf.case) { case "ok": paddedMessageSize = resConf.body.message_body_bytes; @@ -530,8 +545,10 @@ async function internalSendTalerUriMessage( "could not read the configuration of the mailbox service", ); } - const resKeys = await mailboxClient.getMailboxInfo( - req.contact.mailboxAddress, + const resKeys = await runWithProgressRetries(wex, async () => + await mailboxClient.getMailboxInfo( + req.contact.mailboxAddress, + ), ); var keys; switch (resKeys.case) { @@ -557,10 +574,12 @@ async function internalSendTalerUriMessage( req.talerUri, paddedMessageSize, ); - const resSend = await mailboxClient.sendMessage({ - h_address: req.contact.mailboxAddress, - body: encryptedMessage, - }); + const resSend = await runWithProgressRetries(wex, async () => + await mailboxClient.sendMessage({ + h_address: req.contact.mailboxAddress, + body: encryptedMessage, + }), + ); switch (resSend.case) { case "ok": return {}; diff --git a/packages/taler-wallet-core/src/taldir.ts b/packages/taler-wallet-core/src/taldir.ts @@ -35,10 +35,12 @@ import { EmptyObject, TalerError, TalerErrorCode, + succeedOrThrow, } from "@gnu-taler/taler-util"; import { WalletExecutionContext } from "./wallet.js"; import { runWithMaybeProgressContext, + runWithProgressRetries, } from "./progress.js"; const logger = new Logger("taldir.ts"); @@ -80,7 +82,9 @@ async function internalGetSupportedAliases( wex.http, ); // Refresh message size - const resConf = await taldirClient.getConfig(); + const resConf = await runWithProgressRetries(wex, async () => + await taldirClient.getConfig(), + ) switch (resConf.case) { case "ok": { return { @@ -120,7 +124,9 @@ async function internalLookupAlias( wex.http, ); // Refresh message size - const resConf = await taldirClient.getConfig(); + const resConf = await runWithProgressRetries(wex, async () => + await taldirClient.getConfig(), + ); switch (resConf.case) { case "ok": { let supported_types = resConf.body.alias_types; @@ -150,7 +156,9 @@ async function internalLookupAlias( lookupRequest.alias, ); const hAlias = encodeCrock(sha512(hAliasBuffer)); - const res = await taldirClient.lookupAlias({ hAlias: hAlias }); + const res = await runWithProgressRetries(wex, async () => + await taldirClient.lookupAlias({ hAlias: hAlias }), + ); switch (res.case) { case "ok": return { @@ -194,12 +202,14 @@ async function internalRegisterAlias( registerRequest.mailboxBaseUrl && registerRequest.mailboxAddress ? `${registerRequest.mailboxBaseUrl.replace(/\/+$/, "")}/${registerRequest.mailboxAddress}` : ""; - const res = await taldirClient.postRegistrationRequest({ - alias: registerRequest.alias, - aliasType: registerRequest.aliasType, - targetUri: targetUri, - duration: registerRequest.duration, - }); + const res = await runWithProgressRetries(wex, async () => + await taldirClient.postRegistrationRequest({ + alias: registerRequest.alias, + aliasType: registerRequest.aliasType, + targetUri: targetUri, + duration: registerRequest.duration, + }), + ); switch (res.case) { case "ok": return res.body; @@ -258,10 +268,12 @@ async function internalCompleteAliasRegistration( completionRequest.alias, ); const hAlias = encodeCrock(sha512(hAliasBuffer)); - const res = await taldirClient.postRegistration({ - hAlias: hAlias, - solution: solution, - }); + const res = await runWithProgressRetries(wex, async () => + await taldirClient.postRegistration({ + hAlias: hAlias, + solution: solution, + }), + ); switch (res.case) { case "ok": return {};