diff options
Diffstat (limited to 'packages/taler-wallet-cli/src/index.ts')
-rw-r--r-- | packages/taler-wallet-cli/src/index.ts | 273 |
1 files changed, 4 insertions, 269 deletions
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index 8fad3bdbf..90dc2fdd1 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -17,20 +17,13 @@ /** * Imports. */ -import { deepStrictEqual } from "assert"; -import fs from "fs"; -import os from "os"; -import path from "path"; -// Polyfill for encoding which isn't present globally in older nodejs versions import { addPaytoQueryParams, AgeRestriction, - Amounts, classifyTalerUri, clk, codecForList, codecForString, - Configuration, decodeCrock, encodeCrock, getRandomBytes, @@ -39,12 +32,11 @@ import { parsePaytoUri, PreparePayResultType, RecoveryMergeStrategy, - rsaBlind, setDangerousTimetravel, setGlobalLogLevelFromString, TalerUriType, - parseDevExperimentUri, } from "@gnu-taler/taler-util"; +import type { TalerCryptoInterface } from "@gnu-taler/taler-wallet-core"; import { CryptoDispatcher, getDefaultNodeWallet, @@ -60,20 +52,8 @@ import { WalletCoreApiClient, walletCoreDebugFlags, } from "@gnu-taler/taler-wallet-core"; -import type { TalerCryptoInterface } from "@gnu-taler/taler-wallet-core"; -import { TextDecoder, TextEncoder } from "util"; -import { runBench1 } from "./bench1.js"; -import { runBench2 } from "./bench2.js"; -import { runBench3 } from "./bench3.js"; -import { runEnv1 } from "./env1.js"; -import { GlobalTestState, runTestWithState } from "./harness/harness.js"; -import { getTestInfo, runTests } from "./integrationtests/testrunner.js"; -import { lintExchangeDeployment } from "./lint.js"; -import { runEnvFull } from "./env-full.js"; -// @ts-ignore -global.TextEncoder = TextEncoder; -// @ts-ignore -global.TextDecoder = TextDecoder; +import fs from "fs"; +import os from "os"; // This module also serves as the entry point for the crypto // thread worker, and thus must expose these two handlers. @@ -895,75 +875,6 @@ advancedCli }); advancedCli - .subcommand("bench1", "bench1", { - help: "Run the 'bench1' benchmark", - }) - .requiredOption("configJson", ["--config-json"], clk.STRING) - .action(async (args) => { - let config: any; - try { - config = JSON.parse(args.bench1.configJson); - } catch (e) { - console.log("Could not parse config JSON"); - } - await runBench1(config); - }); - -advancedCli - .subcommand("bench2", "bench2", { - help: "Run the 'bench2' benchmark", - }) - .requiredOption("configJson", ["--config-json"], clk.STRING) - .action(async (args) => { - let config: any; - try { - config = JSON.parse(args.bench2.configJson); - } catch (e) { - console.log("Could not parse config JSON"); - } - await runBench2(config); - }); - -advancedCli - .subcommand("bench3", "bench3", { - help: "Run the 'bench3' benchmark", - }) - .requiredOption("configJson", ["--config-json"], clk.STRING) - .action(async (args) => { - let config: any; - try { - config = JSON.parse(args.bench3.configJson); - } catch (e) { - console.log("Could not parse config JSON"); - } - await runBench3(config); - }); - -advancedCli - .subcommand("envFull", "env-full", { - help: "Run a test environment for bench1", - }) - .action(async (args) => { - const testDir = fs.mkdtempSync(path.join(os.tmpdir(), "taler-env-full-")); - const testState = new GlobalTestState({ - testDir, - }); - await runTestWithState(testState, runEnvFull, "env-full", true); - }); - -advancedCli - .subcommand("env1", "env1", { - help: "Run a test environment for bench1", - }) - .action(async (args) => { - const testDir = fs.mkdtempSync(path.join(os.tmpdir(), "taler-env1-")); - const testState = new GlobalTestState({ - testDir, - }); - await runTestWithState(testState, runEnv1, "env1", true); - }); - -advancedCli .subcommand("withdrawFakebank", "withdraw-fakebank", { help: "Withdraw via a fakebank.", }) @@ -992,7 +903,7 @@ advancedCli }) .action((args) => { const enc = fs.readFileSync(0, "utf8"); - fs.writeFileSync(1, decodeCrock(enc.trim())); + console.log(decodeCrock(enc.trim())); }); advancedCli @@ -1207,92 +1118,6 @@ advancedCli }); }); -const deploymentCli = walletCli.subcommand("deploymentArgs", "deployment", { - help: "Subcommands for handling GNU Taler deployments.", -}); - -deploymentCli - .subcommand("lintExchange", "lint-exchange", { - help: "Run checks on the exchange deployment.", - }) - .flag("cont", ["--continue"], { - help: "Continue after errors if possible", - }) - .flag("debug", ["--debug"], { - help: "Output extra debug info", - }) - .action(async (args) => { - await lintExchangeDeployment( - args.lintExchange.debug, - args.lintExchange.cont, - ); - }); - -deploymentCli - .subcommand("coincfg", "gen-coin-config", { - help: "Generate a coin/denomination configuration for the exchange.", - }) - .requiredOption("minAmount", ["--min-amount"], clk.STRING, { - help: "Smallest denomination", - }) - .requiredOption("maxAmount", ["--max-amount"], clk.STRING, { - help: "Largest denomination", - }) - .action(async (args) => { - let out = ""; - - const stamp = Math.floor(new Date().getTime() / 1000); - - const min = Amounts.parseOrThrow(args.coincfg.minAmount); - const max = Amounts.parseOrThrow(args.coincfg.maxAmount); - if (min.currency != max.currency) { - console.error("currency mismatch"); - process.exit(1); - } - const currency = min.currency; - let x = min; - let n = 1; - - out += "# Coin configuration for the exchange.\n"; - out += '# Should be placed in "/etc/taler/conf.d/exchange-coins.conf".\n'; - out += "\n"; - - while (Amounts.cmp(x, max) < 0) { - out += `[COIN-${currency}-n${n}-t${stamp}]\n`; - out += `VALUE = ${Amounts.stringify(x)}\n`; - out += `DURATION_WITHDRAW = 7 days\n`; - out += `DURATION_SPEND = 2 years\n`; - out += `DURATION_LEGAL = 6 years\n`; - out += `FEE_WITHDRAW = ${currency}:0\n`; - out += `FEE_DEPOSIT = ${Amounts.stringify(min)}\n`; - out += `FEE_REFRESH = ${currency}:0\n`; - out += `FEE_REFUND = ${currency}:0\n`; - out += `RSA_KEYSIZE = 2048\n`; - out += "\n"; - x = Amounts.add(x, x).amount; - n++; - } - - console.log(out); - }); - -const deploymentConfigCli = deploymentCli.subcommand("configArgs", "config", { - help: "Subcommands the Taler configuration.", -}); - -deploymentConfigCli - .subcommand("show", "show") - .flag("diagnostics", ["-d", "--diagnostics"]) - .maybeArgument("cfgfile", clk.STRING, {}) - .action(async (args) => { - const cfg = Configuration.load(args.show.cfgfile); - console.log( - cfg.stringify({ - diagnostics: args.show.diagnostics, - }), - ); - }); - const testCli = walletCli.subcommand("testingArgs", "testing", { help: "Subcommands for testing.", }); @@ -1426,102 +1251,12 @@ testCli.subcommand("logtest", "logtest").action(async (args) => { logger.error("This is an error message."); }); -testCli - .subcommand("listIntegrationtests", "list-integrationtests") - .action(async (args) => { - for (const t of getTestInfo()) { - let s = t.name; - if (t.suites.length > 0) { - s += ` (suites: ${t.suites.join(",")})`; - } - if (t.excludeByDefault) { - s += ` [excluded by default]`; - } - console.log(s); - } - }); - -testCli - .subcommand("runIntegrationtests", "run-integrationtests") - .maybeArgument("pattern", clk.STRING, { - help: "Glob pattern to select which tests to run", - }) - .maybeOption("suites", ["--suites"], clk.STRING, { - help: "Only run selected suites (comma-separated list)", - }) - .flag("dryRun", ["--dry"], { - help: "Only print tests that will be selected to run.", - }) - .flag("quiet", ["--quiet"], { - help: "Produce less output.", - }) - .action(async (args) => { - await runTests({ - includePattern: args.runIntegrationtests.pattern, - suiteSpec: args.runIntegrationtests.suites, - dryRun: args.runIntegrationtests.dryRun, - verbosity: args.runIntegrationtests.quiet ? 0 : 1, - }); - }); - async function read(stream: NodeJS.ReadStream) { const chunks = []; for await (const chunk of stream) chunks.push(chunk); return Buffer.concat(chunks).toString("utf8"); } -testCli.subcommand("tvgcheck", "tvgcheck").action(async (args) => { - const data = await read(process.stdin); - - const lines = data.match(/[^\r\n]+/g); - - if (!lines) { - throw Error("can't split lines"); - } - - const vals: Record<string, string> = {}; - - let inBlindSigningSection = false; - - for (const line of lines) { - if (line === "blind signing:") { - inBlindSigningSection = true; - continue; - } - if (line[0] !== " ") { - inBlindSigningSection = false; - continue; - } - if (inBlindSigningSection) { - const m = line.match(/ (\w+) (\w+)/); - if (!m) { - console.log("bad format"); - process.exit(2); - } - vals[m[1]] = m[2]; - } - } - - console.log(vals); - - const req = (k: string) => { - if (!vals[k]) { - throw Error(`no value for ${k}`); - } - return decodeCrock(vals[k]); - }; - - const myBm = rsaBlind( - req("message_hash"), - req("blinding_key_secret"), - req("rsa_public_key"), - ); - - deepStrictEqual(req("blinded_message"), myBm); - - console.log("check passed!"); -}); - testCli .subcommand("cryptoworker", "cryptoworker") .maybeOption("impl", ["--impl"], clk.STRING) |