diff options
author | Florian Dold <florian@dold.me> | 2022-10-13 15:24:47 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-10-13 15:24:47 +0200 |
commit | ca8da4ed380b308abdc894145c7e1a102bfd6cf0 (patch) | |
tree | 876ed35c7bd5f4c75967885d36eb3a3eecd06307 /packages/taler-wallet-core/src | |
parent | 83d4a1addc313f71a71463f7811f1fcc622b51b6 (diff) | |
download | wallet-core-ca8da4ed380b308abdc894145c7e1a102bfd6cf0.tar.xz |
wallet-core: only allow enabling dev mode via separate request
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/dev-experiments.ts | 33 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet-api-types.ts | 9 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 8 |
3 files changed, 34 insertions, 16 deletions
diff --git a/packages/taler-wallet-core/src/dev-experiments.ts b/packages/taler-wallet-core/src/dev-experiments.ts index c3167b3e4..6516db929 100644 --- a/packages/taler-wallet-core/src/dev-experiments.ts +++ b/packages/taler-wallet-core/src/dev-experiments.ts @@ -36,20 +36,11 @@ import { const logger = new Logger("dev-experiments.ts"); -/** - * Apply a dev experiment to the wallet database / state. - */ -export async function applyDevExperiment( +export async function setDevMode( ws: InternalWalletState, - uri: string, + enabled: boolean, ): Promise<void> { - logger.info(`applying dev experiment ${uri}`); - const parsedUri = parseDevExperimentUri(uri); - if (!parsedUri) { - logger.info("unable to parse dev experiment URI"); - return; - } - if (parsedUri.devExperimentId == "enable-devmode") { + if (enabled) { logger.info("enabling devmode"); await ws.db .mktx((x) => [x.config]) @@ -60,9 +51,7 @@ export async function applyDevExperiment( }); }); await maybeInitDevMode(ws); - return; - } - if (parsedUri.devExperimentId === "disable-devmode") { + } else { logger.info("disabling devmode"); await ws.db .mktx((x) => [x.config]) @@ -73,6 +62,20 @@ export async function applyDevExperiment( }); }); await leaveDevMode(ws); + } +} + +/** + * Apply a dev experiment to the wallet database / state. + */ +export async function applyDevExperiment( + ws: InternalWalletState, + uri: string, +): Promise<void> { + logger.info(`applying dev experiment ${uri}`); + const parsedUri = parseDevExperimentUri(uri); + if (!parsedUri) { + logger.info("unable to parse dev experiment URI"); return; } if (!ws.devModeActive) { diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index cecdd1281..63d960f81 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -67,6 +67,7 @@ import { RecoveryLoadRequest, RetryTransactionRequest, SetCoinSuspendedRequest, + SetDevModeRequest, SetWalletDeviceIdRequest, TestPayArgs, TestPayResult, @@ -140,6 +141,7 @@ export enum WalletApiOperation { AcceptPeerPullPayment = "acceptPeerPullPayment", ClearDb = "clearDb", Recycle = "recycle", + SetDevMode = "setDevMode", ApplyDevExperiment = "applyDevExperiment", } @@ -529,6 +531,12 @@ export type ApplyDevExperimentOp = { response: {}; }; +export type SetDevModeOp = { + op: WalletApiOperation.SetDevMode; + request: SetDevModeRequest; + response: {}; +}; + /** * Run a simple integration test on a test deployment * of the exchange and merchant. @@ -676,6 +684,7 @@ export type WalletOperations = { [WalletApiOperation.ClearDb]: ClearDbOp; [WalletApiOperation.Recycle]: RecycleOp; [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp; + [WalletApiOperation.SetDevMode]: SetDevModeOp; }; export type RequestType< diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 48d379931..254648064 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -94,6 +94,7 @@ import { URL, WalletCoreVersion, WalletNotification, + codecForSetDevModeRequest, } from "@gnu-taler/taler-util"; import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js"; import { @@ -111,7 +112,7 @@ import { importDb, WalletStoresV1, } from "./db.js"; -import { applyDevExperiment, maybeInitDevMode } from "./dev-experiments.js"; +import { applyDevExperiment, maybeInitDevMode, setDevMode } from "./dev-experiments.js"; import { getErrorDetailFromException, TalerError } from "./errors.js"; import { ActiveLongpollInfo, @@ -1334,6 +1335,11 @@ async function dispatchRequestInternal( await applyDevExperiment(ws, req.devExperimentUri); return {}; } + case "setDevMode": { + const req = codecForSetDevModeRequest().decode(payload); + await setDevMode(ws, req.devModeEnabled); + return {}; + } case "getVersion": { const version: WalletCoreVersion = { hash: GIT_HASH, |