summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts35
1 files changed, 34 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 6092830f6..25cfd7f6f 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -51,12 +51,15 @@ import {
ManualWithdrawalDetails,
MerchantUsingTemplateDetails,
NotificationType,
+ PrepareWithdrawExchangeRequest,
+ PrepareWithdrawExchangeResponse,
RecoverStoredBackupRequest,
RefreshReason,
ScopeType,
StoredBackupList,
TalerError,
TalerErrorCode,
+ TalerUriAction,
TaskThrottler,
TestingWaitTransactionRequest,
TransactionState,
@@ -109,6 +112,7 @@ import {
codecForPreparePeerPushCreditRequest,
codecForPrepareRefundRequest,
codecForPrepareRewardRequest,
+ codecForPrepareWithdrawExchangeRequest,
codecForRecoverStoredBackupRequest,
codecForResumeTransaction,
codecForRetryTransactionRequest,
@@ -133,6 +137,7 @@ import {
j2s,
parsePayTemplateUri,
parsePaytoUri,
+ parseTalerUri,
sampleWalletCoreTransactions,
setDangerousTimetravel,
validateIban,
@@ -1045,6 +1050,31 @@ async function recoverStoredBackup(
logger.info(`import done`);
}
+async function handlePrepareWithdrawExchange(
+ ws: InternalWalletState,
+ req: PrepareWithdrawExchangeRequest,
+): Promise<PrepareWithdrawExchangeResponse> {
+ const parsedUri = parseTalerUri(req.talerUri);
+ if (parsedUri?.type !== TalerUriAction.WithdrawExchange) {
+ throw Error("expected a taler://withdraw-exchange URI");
+ }
+ const exchangeBaseUrl = parsedUri.exchangeBaseUrl;
+ const exchange = await updateExchangeFromUrl(ws, exchangeBaseUrl);
+ if (exchange.exchangeDetails.masterPublicKey != 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.exchangeDetails.currency) {
+ throw Error("mismatch of currency (URI vs exchange)");
+ }
+ }
+ return {
+ exchangeBaseUrl,
+ amount: parsedUri.amount,
+ };
+}
+
/**
* Implementation of the "wallet-core" API.
*/
@@ -1313,7 +1343,10 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
const req = codecForSharePaymentRequest().decode(payload);
return await sharePayment(ws, req.merchantBaseUrl, req.orderId);
}
-
+ case WalletApiOperation.PrepareWithdrawExchange: {
+ const req = codecForPrepareWithdrawExchangeRequest().decode(payload);
+ return handlePrepareWithdrawExchange(ws, req);
+ }
case WalletApiOperation.PreparePayForUri: {
const req = codecForPreparePayRequest().decode(payload);
return await preparePayForUri(ws, req.talerPayUri);