summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2024-05-22 20:24:27 +0200
committerChristian Blättler <blatc2@bfh.ch>2024-05-22 20:24:27 +0200
commit631027a807138ed9125befc7a2a7c0d8219e17c6 (patch)
treef088a606d4852b524e1f62fe549f68df367ff2ca /packages/taler-wallet-core/src/wallet.ts
parent349cd9a1f46a2ea8e8d9e502577196c7ed1847eb (diff)
parent027b26d1ac9d88a4cfc901cc2465e45bfe13e812 (diff)
downloadwallet-core-feature/tokens.tar.gz
wallet-core-feature/tokens.tar.bz2
wallet-core-feature/tokens.zip
Merge branch 'master' into feature/tokensfeature/tokens
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts65
1 files changed, 52 insertions, 13 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index ea47ffad7..68da15410 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -84,6 +84,7 @@ import {
codecForAny,
codecForApplyDevExperiment,
codecForCanonicalizeBaseUrlRequest,
+ codecForCheckPayTemplateRequest,
codecForCheckPeerPullPaymentRequest,
codecForCheckPeerPushDebitRequest,
codecForConfirmPayRequest,
@@ -134,6 +135,7 @@ import {
codecForSuspendTransaction,
codecForTestPayArgs,
codecForTestingGetDenomStatsRequest,
+ codecForTestingGetReserveHistoryRequest,
codecForTestingListTasksForTransactionRequest,
codecForTestingSetTimetravelRequest,
codecForTransactionByIdRequest,
@@ -154,7 +156,10 @@ import {
setDangerousTimetravel,
validateIban,
} from "@gnu-taler/taler-util";
-import type { HttpRequestLibrary } from "@gnu-taler/taler-util/http";
+import {
+ readSuccessResponseJsonOrThrow,
+ type HttpRequestLibrary,
+} from "@gnu-taler/taler-util/http";
import {
getUserAttentions,
getUserAttentionsUnreadCount,
@@ -224,6 +229,7 @@ import {
observeTalerCrypto,
} from "./observable-wrappers.js";
import {
+ checkPayForTemplate,
confirmPay,
getContractTermsDetails,
preparePayForTemplate,
@@ -656,9 +662,6 @@ async function handlePrepareWithdrawExchange(
}
const exchangeBaseUrl = parsedUri.exchangeBaseUrl;
const exchange = await fetchFreshExchange(wex, exchangeBaseUrl);
- if (parsedUri.exchangePub && exchange.masterPub != parsedUri.exchangePub) {
- throw Error("mismatch of exchange master public key (URI vs actual)");
- }
if (parsedUri.amount) {
const amt = Amounts.parseOrThrow(parsedUri.amount);
if (amt.currency !== exchange.currency) {
@@ -818,9 +821,7 @@ async function dispatchRequestInternal(
}
case WalletApiOperation.AddExchange: {
const req = codecForAddExchangeRequest().decode(payload);
- await fetchFreshExchange(wex, req.exchangeBaseUrl, {
- expectedMasterPub: req.masterPub,
- });
+ await fetchFreshExchange(wex, req.exchangeBaseUrl, {});
return {};
}
case WalletApiOperation.TestingPing: {
@@ -905,9 +906,36 @@ async function dispatchRequestInternal(
}
case WalletApiOperation.GetWithdrawalDetailsForUri: {
const req = codecForGetWithdrawalDetailsForUri().decode(payload);
- return await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri, {
- restrictAge: req.restrictAge,
+ return await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri);
+ }
+ case WalletApiOperation.TestingGetReserveHistory: {
+ const req = codecForTestingGetReserveHistoryRequest().decode(payload);
+ const reserve = await wex.db.runReadOnlyTx(
+ { storeNames: ["reserves"] },
+ async (tx) => {
+ return tx.reserves.indexes.byReservePub.get(req.reservePub);
+ },
+ );
+ if (!reserve) {
+ throw Error("no reserve pub found");
+ }
+ const sigResp = await wex.cryptoApi.signReserveHistoryReq({
+ reservePriv: reserve.reservePriv,
+ startOffset: 0,
});
+ const exchangeBaseUrl = req.exchangeBaseUrl;
+ const url = new URL(
+ `reserves/${req.reservePub}/history`,
+ exchangeBaseUrl,
+ );
+ const resp = await wex.http.fetch(url.href, {
+ headers: { ["Taler-Reserve-History-Signature"]: sigResp.sig },
+ });
+ const historyJson = await readSuccessResponseJsonOrThrow(
+ resp,
+ codecForAny(),
+ );
+ return historyJson;
}
case WalletApiOperation.AcceptManualWithdrawal: {
const req = codecForAcceptManualWithdrawalRequest().decode(payload);
@@ -972,16 +1000,14 @@ async function dispatchRequestInternal(
}
case WalletApiOperation.ConfirmWithdrawal: {
const req = codecForConfirmWithdrawalRequestRequest().decode(payload);
- return confirmWithdrawal(wex, req.transactionId);
+ return confirmWithdrawal(wex, req);
}
case WalletApiOperation.PrepareBankIntegratedWithdrawal: {
const req =
codecForPrepareBankIntegratedWithdrawalRequest().decode(payload);
return prepareBankIntegratedWithdrawal(wex, {
- selectedExchange: req.exchangeBaseUrl,
talerWithdrawUri: req.talerWithdrawUri,
- forcedDenomSel: req.forcedDenomSel,
- restrictAge: req.restrictAge,
+ selectedExchange: req.selectedExchange,
});
}
case WalletApiOperation.GetExchangeTos: {
@@ -1028,6 +1054,10 @@ async function dispatchRequestInternal(
const req = codecForPreparePayTemplateRequest().decode(payload);
return preparePayForTemplate(wex, req);
}
+ case WalletApiOperation.CheckPayForTemplate: {
+ const req = codecForCheckPayTemplateRequest().decode(payload);
+ return checkPayForTemplate(wex, req);
+ }
case WalletApiOperation.ConfirmPay: {
const req = codecForConfirmPayRequest().decode(payload);
let transactionId;
@@ -1595,6 +1625,14 @@ async function handleCoreApiRequest(
id: string,
payload: unknown,
): Promise<CoreApiResponse> {
+ if (operation !== WalletApiOperation.InitWallet) {
+ if (!ws.initCalled) {
+ throw Error("init must be called first");
+ }
+ // Might be lazily initialized!
+ await ws.taskScheduler.ensureRunning();
+ }
+
let wex: WalletExecutionContext;
let oc: ObservabilityContext;
@@ -1683,6 +1721,7 @@ export function applyRunConfigDefaults(
skipDefaults: wcp?.testing?.skipDefaults ?? false,
emitObservabilityEvents: wcp?.testing?.emitObservabilityEvents ?? false,
},
+ lazyTaskLoop: wcp?.lazyTaskLoop ?? false,
};
}