This commit is contained in:
Florian Dold 2020-06-21 18:20:39 +05:30
parent 76fffdedd7
commit 06d9aab47c
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 53 additions and 47 deletions

View File

@ -25,7 +25,11 @@ import * as clk from "./clk";
import { BridgeIDBFactory } from "idb-bridge"; import { BridgeIDBFactory } from "idb-bridge";
import { Logger } from "../util/logging"; import { Logger } from "../util/logging";
import { Amounts } from "../util/amounts"; import { Amounts } from "../util/amounts";
import { decodeCrock, setupRefreshPlanchet, encodeCrock } from "../crypto/talerCrypto"; import {
decodeCrock,
setupRefreshPlanchet,
encodeCrock,
} from "../crypto/talerCrypto";
import { OperationFailedAndReportedError } from "../operations/errors"; import { OperationFailedAndReportedError } from "../operations/errors";
import { Bank } from "./bank"; import { Bank } from "./bank";
import { classifyTalerUri, TalerUriType } from "../util/taleruri"; import { classifyTalerUri, TalerUriType } from "../util/taleruri";
@ -368,41 +372,42 @@ advancedCli
fs.writeFileSync(1, decodeCrock(enc.trim())); fs.writeFileSync(1, decodeCrock(enc.trim()));
}); });
advancedCli advancedCli
.subcommand("withdrawManually", "withdraw-manually", { .subcommand("withdrawManually", "withdraw-manually", {
help: "Withdraw manually from an exchange.", help: "Withdraw manually from an exchange.",
}) })
.requiredOption("exchange", ["--exchange"], clk.STRING, { .requiredOption("exchange", ["--exchange"], clk.STRING, {
help: "Base URL of the exchange.", help: "Base URL of the exchange.",
}) })
.requiredOption("amount", ["--amount"], clk.STRING, { .requiredOption("amount", ["--amount"], clk.STRING, {
help: "Amount to withdraw", help: "Amount to withdraw",
}) })
.action(async (args) => { .action(async (args) => {
await withWallet(args, async (wallet) => { await withWallet(args, async (wallet) => {
const exchange = await wallet.updateExchangeFromUrl(args.withdrawManually.exchange); const exchange = await wallet.updateExchangeFromUrl(
const acct = exchange.wireInfo?.accounts[0]; args.withdrawManually.exchange,
if (!acct) { );
console.log("exchange has no accounts"); const acct = exchange.wireInfo?.accounts[0];
return; if (!acct) {
} console.log("exchange has no accounts");
const reserve = await wallet.createReserve({ return;
amount: Amounts.parseOrThrow(args.withdrawManually.amount), }
exchangeWire: acct.payto_uri, const reserve = await wallet.createReserve({
exchange: exchange.baseUrl, amount: Amounts.parseOrThrow(args.withdrawManually.amount),
exchangeWire: acct.payto_uri,
exchange: exchange.baseUrl,
});
await wallet.confirmReserve({
reservePub: reserve.reservePub,
});
const completePaytoUri = addPaytoQueryParams(acct.payto_uri, {
amount: args.withdrawManually.amount,
message: `Taler top-up ${reserve.reservePub}`,
});
console.log("Created reserve", reserve.reservePub);
console.log("Payto URI", completePaytoUri);
}); });
await wallet.confirmReserve({
reservePub: reserve.reservePub,
});
const completePaytoUri = addPaytoQueryParams(acct.payto_uri, {
amount: args.withdrawManually.amount,
message: `Taler top-up ${reserve.reservePub}`,
});
console.log("Created reserve", reserve.reservePub);
console.log("Payto URI", completePaytoUri);
}); });
});
const reservesCli = advancedCli.subcommand("reserves", "reserves", { const reservesCli = advancedCli.subcommand("reserves", "reserves", {
help: "Manage reserves.", help: "Manage reserves.",
@ -572,19 +577,17 @@ const testCli = walletCli.subcommand("testingArgs", "testing", {
help: "Subcommands for testing GNU Taler deployments.", help: "Subcommands for testing GNU Taler deployments.",
}); });
testCli testCli.subcommand("vectors", "vectors").action(async (args) => {
.subcommand("vectors", "vectors") const secretSeed = nacl.randomBytes(64);
.action(async (args) => { const coinIndex = Math.ceil(Math.random() * 100);
const secretSeed = nacl.randomBytes(64); const p = setupRefreshPlanchet(secretSeed, coinIndex);
const coinIndex = Math.ceil(Math.random() * 100) console.log("setupRefreshPlanchet");
const p = setupRefreshPlanchet(secretSeed, coinIndex); console.log(` (in) secret seed: ${encodeCrock(secretSeed)}`);
console.log("setupRefreshPlanchet") console.log(` (in) coin index: ${coinIndex}`);
console.log(` (in) secret seed: ${encodeCrock(secretSeed)}`); console.log(` (out) blinding secret: ${encodeCrock(p.bks)}`);
console.log(` (in) coin index: ${coinIndex}`); console.log(` (out) coin priv: ${encodeCrock(p.coinPriv)}`);
console.log(` (out) blinding secret: ${encodeCrock(p.bks)}`); console.log(` (out) coin pub: ${encodeCrock(p.coinPub)}`);
console.log(` (out) coin priv: ${encodeCrock(p.coinPriv)}`); });
console.log(` (out) coin pub: ${encodeCrock(p.coinPub)}`);
});
testCli testCli
.subcommand("integrationtestBasic", "integrationtest-basic") .subcommand("integrationtestBasic", "integrationtest-basic")

View File

@ -25,7 +25,10 @@ const paytoPfx = "payto://";
/** /**
* Add query parameters to a payto URI * Add query parameters to a payto URI
*/ */
export function addPaytoQueryParams(s: string, params: { [name: string]: string }): string { export function addPaytoQueryParams(
s: string,
params: { [name: string]: string },
): string {
const [acct, search] = s.slice(paytoPfx.length).split("?"); const [acct, search] = s.slice(paytoPfx.length).split("?");
const searchParams = new URLSearchParams(search || ""); const searchParams = new URLSearchParams(search || "");
for (const k of Object.keys(params)) { for (const k of Object.keys(params)) {