@wasit-dev/cli 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +39 -5
  2. package/dist/dashboard/App.d.ts +9 -0
  3. package/dist/dashboard/App.js +39 -0
  4. package/dist/dashboard/CatalogueView.d.ts +5 -0
  5. package/dist/dashboard/CatalogueView.js +23 -0
  6. package/dist/dashboard/Home.d.ts +8 -0
  7. package/dist/dashboard/Home.js +54 -0
  8. package/dist/dashboard/RunView.d.ts +10 -0
  9. package/dist/dashboard/RunView.js +165 -0
  10. package/dist/dashboard/TargetForm.d.ts +8 -0
  11. package/dist/dashboard/TargetForm.js +60 -0
  12. package/dist/dashboard/WalletView.d.ts +5 -0
  13. package/dist/dashboard/WalletView.js +253 -0
  14. package/dist/dashboard/banner.d.ts +12 -0
  15. package/dist/dashboard/banner.js +32 -0
  16. package/dist/dashboard/env-file.d.ts +20 -0
  17. package/dist/dashboard/env-file.js +67 -0
  18. package/dist/dashboard/environment.d.ts +14 -0
  19. package/dist/dashboard/environment.js +25 -0
  20. package/dist/dashboard/format.d.ts +6 -0
  21. package/dist/dashboard/format.js +10 -0
  22. package/dist/dashboard/runners.d.ts +15 -0
  23. package/dist/dashboard/runners.js +45 -0
  24. package/dist/dashboard/theme.d.ts +21 -0
  25. package/dist/dashboard/theme.js +21 -0
  26. package/dist/dashboard/useElapsedMs.d.ts +10 -0
  27. package/dist/dashboard/useElapsedMs.js +21 -0
  28. package/dist/dashboard/useSpinnerFrame.d.ts +7 -0
  29. package/dist/dashboard/useSpinnerFrame.js +20 -0
  30. package/dist/dashboard/wallet-actions.d.ts +41 -0
  31. package/dist/dashboard/wallet-actions.js +64 -0
  32. package/dist/index.js +139 -12
  33. package/dist/version.d.ts +1 -0
  34. package/dist/version.js +8 -0
  35. package/dist/wallet-command.d.ts +14 -0
  36. package/dist/wallet-command.js +311 -0
  37. package/package.json +21 -11
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Bridges the dashboard's wallet screen to `@wasit-dev/core`'s wallet
3
+ * primitives — the same relationship runners.ts has to the check suites.
4
+ *
5
+ * Everything the wallet screen needs from core comes through this module,
6
+ * including plain constants: the screen importing some things from here and
7
+ * others straight from core is how a "the dashboard only talks to core via
8
+ * the bridge" rule quietly stops being true.
9
+ */
10
+ import { createUsdcTrustline, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, sendUsdcFromDistributor, TESTNET_USDC_ISSUER, type FriendbotOutcome, type GeneratedCommitmentKey, type GeneratedWallet, type WalletStatus } from "@wasit-dev/core";
11
+ export type WalletRole = "x402" | "mpp-charge" | "mpp-channel";
12
+ export declare const WALLET_ROLES: readonly WalletRole[];
13
+ /** Which .env variable holds each role's key. */
14
+ export declare const ROLE_ENV_VAR: Record<WalletRole, string>;
15
+ export declare const ROLE_LABEL: Record<WalletRole, string>;
16
+ export interface RoleOverview {
17
+ readonly role: WalletRole;
18
+ readonly configured: boolean;
19
+ readonly publicKey?: string;
20
+ /** Undefined for mpp-channel: a signing key, not a funded account. */
21
+ readonly status?: WalletStatus;
22
+ readonly error?: string;
23
+ }
24
+ /** Core classifies its own failures, so rendering the message is enough. */
25
+ export declare function describeError(error: unknown): string;
26
+ /** Says what Friendbot actually did, rather than always claiming a transfer. */
27
+ export declare function friendbotText(outcome: FriendbotOutcome): string;
28
+ /**
29
+ * What the wallet screen shows for one role. mpp-channel never has a
30
+ * status to fetch — it only ever signs commitment bytes off-chain (see
31
+ * mpp/channel-commitment.ts) and has no balance of its own.
32
+ *
33
+ * This never rejects. Deriving the public key is inside the try for the same
34
+ * reason the Horizon call is: a malformed key in .env is one role's problem,
35
+ * and letting it escape as a rejected promise took down the whole dashboard
36
+ * — the screen has no way to render an exception, so it simply stopped on
37
+ * its loading spinner.
38
+ */
39
+ export declare function loadRoleOverview(role: WalletRole): Promise<RoleOverview>;
40
+ export { createUsdcTrustline, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, sendUsdcFromDistributor, TESTNET_USDC_ISSUER, };
41
+ export type { FriendbotOutcome, GeneratedCommitmentKey, GeneratedWallet, WalletStatus };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Bridges the dashboard's wallet screen to `@wasit-dev/core`'s wallet
3
+ * primitives — the same relationship runners.ts has to the check suites.
4
+ *
5
+ * Everything the wallet screen needs from core comes through this module,
6
+ * including plain constants: the screen importing some things from here and
7
+ * others straight from core is how a "the dashboard only talks to core via
8
+ * the bridge" rule quietly stops being true.
9
+ */
10
+ import { createUsdcTrustline, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, getTestnetWalletStatus, publicKeyFromSecret, sendUsdcFromDistributor, TESTNET_USDC_ISSUER, } from "@wasit-dev/core";
11
+ export const WALLET_ROLES = ["x402", "mpp-charge", "mpp-channel"];
12
+ /** Which .env variable holds each role's key. */
13
+ export const ROLE_ENV_VAR = {
14
+ x402: "STELLAR_PRIVATE_KEY",
15
+ "mpp-charge": "MPP_PAYER_SECRET",
16
+ "mpp-channel": "COMMITMENT_SECRET_HEX",
17
+ };
18
+ export const ROLE_LABEL = {
19
+ x402: "x402 payer",
20
+ "mpp-charge": "MPP charge payer",
21
+ "mpp-channel": "MPP channel commitment key",
22
+ };
23
+ /** Core classifies its own failures, so rendering the message is enough. */
24
+ export function describeError(error) {
25
+ return error instanceof Error ? error.message : String(error);
26
+ }
27
+ /** Says what Friendbot actually did, rather than always claiming a transfer. */
28
+ export function friendbotText(outcome) {
29
+ return outcome === "funded"
30
+ ? "Funded: 10,000 XLM."
31
+ : "Already funded — Friendbot left the existing balance alone.";
32
+ }
33
+ /**
34
+ * What the wallet screen shows for one role. mpp-channel never has a
35
+ * status to fetch — it only ever signs commitment bytes off-chain (see
36
+ * mpp/channel-commitment.ts) and has no balance of its own.
37
+ *
38
+ * This never rejects. Deriving the public key is inside the try for the same
39
+ * reason the Horizon call is: a malformed key in .env is one role's problem,
40
+ * and letting it escape as a rejected promise took down the whole dashboard
41
+ * — the screen has no way to render an exception, so it simply stopped on
42
+ * its loading spinner.
43
+ */
44
+ export async function loadRoleOverview(role) {
45
+ const secret = process.env[ROLE_ENV_VAR[role]];
46
+ if (!secret)
47
+ return { role, configured: false };
48
+ if (role === "mpp-channel")
49
+ return { role, configured: true };
50
+ try {
51
+ const publicKey = publicKeyFromSecret(secret, ROLE_ENV_VAR[role]);
52
+ try {
53
+ const status = await getTestnetWalletStatus(publicKey);
54
+ return { role, configured: true, publicKey, status };
55
+ }
56
+ catch (error) {
57
+ return { role, configured: true, publicKey, error: describeError(error) };
58
+ }
59
+ }
60
+ catch (error) {
61
+ return { role, configured: true, error: describeError(error) };
62
+ }
63
+ }
64
+ export { createUsdcTrustline, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, sendUsdcFromDistributor, TESTNET_USDC_ISSUER, };
package/dist/index.js CHANGED
@@ -1,7 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import "dotenv/config";
3
+ import { createElement } from "react";
4
+ import { render } from "ink";
3
5
  import { Command } from "commander";
4
- import { checkStatus, runMppChannelSuite, runMppChargeSuite, runX402PaymentChecks, runX402ReadChecks, summarize, } from "@wasit-dev/core";
6
+ import { App } from "./dashboard/App.js";
7
+ import { CLI_VERSION } from "./version.js";
8
+ import { registerWalletCommand } from "./wallet-command.js";
9
+ import { CHECK_CATALOGUE, PROTOCOL_IDS, checkStatus, runMppChannelSuite, runMppChargeSuite, runX402PaymentChecks, runX402ReadChecks, summarize, toStructuredRun, } from "@wasit-dev/core";
10
+ /** Which wasit subcommand runs each protocol's checks — for `wasit checks` output. */
11
+ const COMMAND_BY_PROTOCOL = {
12
+ x402: "test",
13
+ "mpp-charge": "mpp-charge",
14
+ "mpp-channel": "mpp-channel",
15
+ };
5
16
  /**
6
17
  * Accumulates repeated --header flags into one object.
7
18
  *
@@ -23,21 +34,55 @@ const program = new Command();
23
34
  program
24
35
  .name("wasit")
25
36
  .description("Protocol-compliance testing for x402 / MPP on Stellar")
26
- .version("0.1.0");
37
+ .version(CLI_VERSION)
38
+ .addHelpText("after", `
39
+ Examples:
40
+ $ wasit checks
41
+ $ wasit test --target https://api.example.com/paid-endpoint --read-only
42
+ $ wasit mpp-charge --target https://api.example.com/paid-endpoint --payer-key S...
43
+ $ wasit mpp-channel --target https://api.example.com/paid-endpoint
44
+ $ wasit wallet create --role mpp-charge --fund
45
+
46
+ Run "wasit <command> --help" for that command's own options and cost notes.
47
+ Add --json to test/mpp-charge/mpp-channel for machine-readable output.
48
+ Full check catalogue (every check ID, spec reference, pass criteria):
49
+ https://github.com/wasit-dev/wasit/blob/main/docs/CHECKS.md`);
50
+ /**
51
+ * Prints an advisory/status line meant for a human watching the terminal —
52
+ * never part of the run's actual result. Routed to stderr when --json is
53
+ * set, so stdout stays parseable JSON and a script piping it (jq, etc.)
54
+ * never has to skip past prose first.
55
+ */
56
+ function note(json, message) {
57
+ if (json) {
58
+ console.error(message);
59
+ }
60
+ else {
61
+ console.log(message);
62
+ }
63
+ }
27
64
  /**
28
65
  * Prints results and returns the process exit code.
29
66
  *
30
67
  * A skipped check carries `pass: false` so it can never be counted as
31
68
  * conformance, but it is not a failure and must not fail the run. An errored
32
69
  * check produced no verdict at all and is reported separately again.
70
+ *
71
+ * `--json` reuses `toStructuredRun()` from core — the same reshape the MCP
72
+ * server calls for its own structured output — rather than defining a
73
+ * second JSON shape here that could drift from it.
33
74
  */
34
- function report(results) {
75
+ function report(results, json) {
76
+ const counts = summarize(results);
77
+ if (json) {
78
+ console.log(JSON.stringify(toStructuredRun(results), null, 2));
79
+ return counts.exitCode;
80
+ }
35
81
  for (const result of results) {
36
82
  const flag = result.destructive ? " [destructive]" : "";
37
83
  console.log(`${checkStatus(result)} ${result.id} ${result.name}${flag}`);
38
84
  console.log(` ${result.detail}\n`);
39
85
  }
40
- const counts = summarize(results);
41
86
  const line = [`${counts.passed} passed`];
42
87
  if (counts.failed > 0)
43
88
  line.push(`${counts.failed} failed`);
@@ -52,6 +97,48 @@ function report(results) {
52
97
  }
53
98
  return counts.exitCode;
54
99
  }
100
+ program
101
+ .command("checks")
102
+ .description("List the check catalogue: every check wasit can run, by ID")
103
+ .option("--protocol <name>", `Filter to one protocol (${PROTOCOL_IDS.join(", ")}) — matches the wasit subcommand that runs it`)
104
+ .option("--json", "Print as JSON instead of a formatted list", false)
105
+ .addHelpText("after", `
106
+ Examples:
107
+ $ wasit checks
108
+ $ wasit checks --protocol mpp-channel
109
+ $ wasit checks --json
110
+
111
+ Full pass-criteria prose, spec citations, and revision notes for every check
112
+ live in docs/CHECKS.md — this command is a quick reference, not a
113
+ replacement for it.`)
114
+ .action((opts) => {
115
+ const protocol = opts.protocol;
116
+ if (protocol !== undefined && !PROTOCOL_IDS.includes(protocol)) {
117
+ console.error(`Unknown --protocol "${protocol}". Expected one of: ${PROTOCOL_IDS.join(", ")}.`);
118
+ process.exit(2);
119
+ }
120
+ const entries = CHECK_CATALOGUE.filter((entry) => protocol === undefined || entry.protocol === protocol);
121
+ if (opts.json === true) {
122
+ console.log(JSON.stringify(entries, null, 2));
123
+ return;
124
+ }
125
+ let currentProtocol;
126
+ for (const entry of entries) {
127
+ if (entry.protocol !== currentProtocol) {
128
+ currentProtocol = entry.protocol;
129
+ console.log(`\n${currentProtocol} (wasit ${COMMAND_BY_PROTOCOL[currentProtocol]})`);
130
+ }
131
+ const flags = [
132
+ entry.negative ? "negative" : null,
133
+ entry.destructive ? "destructive" : null,
134
+ entry.costsFunds ? "costs funds" : null,
135
+ ].filter((flag) => flag !== null);
136
+ const flagText = flags.length > 0 ? ` [${flags.join(", ")}]` : "";
137
+ console.log(` ${entry.id} ${entry.name}${flagText}`);
138
+ console.log(` ${entry.summary}`);
139
+ }
140
+ console.log(`\n${entries.length} check${entries.length === 1 ? "" : "s"}.`);
141
+ });
55
142
  program
56
143
  .command("test")
57
144
  .description("Run x402 compliance checks against a target service")
@@ -63,7 +150,19 @@ program
63
150
  .option("--body <json>", "Request body, sent verbatim. Implies Content-Type: application/json.")
64
151
  .option("--header <name:value>", "Extra request header the endpoint needs before it will issue a challenge. Repeatable.", collectHeader)
65
152
  .option("--read-only", "Skip payment checks (X402-06/07)", false)
153
+ .option("--json", "Print results as JSON instead of formatted text", false)
154
+ .addHelpText("after", `
155
+ Examples:
156
+ $ wasit test --target https://api.example.com/paid-endpoint --read-only
157
+ $ wasit test --target https://api.example.com/paid-endpoint --payer-key S...
158
+ $ wasit test --target https://api.example.com/paid-endpoint --read-only --json
159
+
160
+ X402-01..05 (challenge/header checks) always run and cost nothing. X402-06/07
161
+ (real payment checks) run only when a payer key is available and --read-only
162
+ is not set: X402-06 settles a payment, X402-07 attempts one with a corrupted
163
+ signature. See docs/CHECKS.md for what each check ID verifies.`)
66
164
  .action(async (opts) => {
165
+ const jsonMode = opts.json === true;
67
166
  const shape = {
68
167
  ...(opts.method ? { method: opts.method } : {}),
69
168
  ...(opts.body !== undefined ? { body: opts.body } : {}),
@@ -72,13 +171,13 @@ program
72
171
  const results = await runX402ReadChecks({ target: opts.target, ...shape });
73
172
  const payerKey = opts.payerKey ?? process.env.STELLAR_PRIVATE_KEY;
74
173
  if (opts.readOnly) {
75
- console.log("(--read-only set: skipping payment checks)\n");
174
+ note(jsonMode, "(--read-only set: skipping payment checks)\n");
76
175
  }
77
176
  else if (!payerKey) {
78
- console.log("(no payer key: set STELLAR_PRIVATE_KEY in .env or pass --payer-key — skipping payment checks)\n");
177
+ note(jsonMode, "(no payer key: set STELLAR_PRIVATE_KEY in .env or pass --payer-key — skipping payment checks)\n");
79
178
  }
80
179
  else {
81
- console.log("X402-06 settles a real payment and X402-07 attempts one. Testnet funds will move.\n");
180
+ note(jsonMode, "X402-06 settles a real payment and X402-07 attempts one. Testnet funds will move.\n");
82
181
  results.push(...(await runX402PaymentChecks({
83
182
  target: opts.target,
84
183
  network: opts.network,
@@ -86,7 +185,7 @@ program
86
185
  ...shape,
87
186
  })));
88
187
  }
89
- process.exit(report(results));
188
+ process.exit(report(results, jsonMode));
90
189
  });
91
190
  program
92
191
  .command("mpp-channel")
@@ -103,7 +202,19 @@ program
103
202
  .option("--expect-refund-period <ledgers>", "MPP-10: expected refund waiting period")
104
203
  .option("--allow-destructive", "Enable MPP-13. Closing settles on-chain and permanently ends the channel.", false)
105
204
  .option("--destructive-channel <address>", "Channel MPP-13 is permitted to close (default: CHANNEL_CONTRACT_DISPOSABLE)")
205
+ .option("--json", "Print results as JSON instead of formatted text", false)
206
+ .addHelpText("after", `
207
+ Examples:
208
+ $ wasit mpp-channel --target https://api.example.com/paid-endpoint
209
+ $ wasit mpp-channel --target https://api.example.com/paid-endpoint --allow-destructive --destructive-channel C...
210
+ $ wasit mpp-channel --target https://api.example.com/paid-endpoint --json
211
+
212
+ MPP-10, MPP-11, MPP-12, MPP-14 run by default and are non-destructive.
213
+ MPP-13 (channel close) only runs with --allow-destructive, and only against
214
+ the channel named by --destructive-channel — running it permanently ends
215
+ that channel.`)
106
216
  .action(async (opts) => {
217
+ const jsonMode = opts.json === true;
107
218
  const commitmentSecretHex = opts.commitmentKey ?? process.env.COMMITMENT_SECRET_HEX;
108
219
  if (!commitmentSecretHex) {
109
220
  console.error("No commitment key. Pass --commitment-key or set COMMITMENT_SECRET_HEX in .env.");
@@ -128,7 +239,7 @@ program
128
239
  ...(Number.isInteger(refundWaitingPeriod) ? { refundWaitingPeriod } : {}),
129
240
  },
130
241
  });
131
- process.exit(report(results));
242
+ process.exit(report(results, jsonMode));
132
243
  });
133
244
  program
134
245
  .command("mpp-charge")
@@ -137,19 +248,35 @@ program
137
248
  .option("--payer-key <key>", "Payer secret key, S... (default: MPP_PAYER_SECRET)")
138
249
  .option("--network <network>", "CAIP-2 network id (default: MPP_STELLAR_NETWORK)")
139
250
  .option("--rpc-url <url>", "Override the default Soroban RPC endpoint")
251
+ .option("--json", "Print results as JSON instead of formatted text", false)
252
+ .addHelpText("after", `
253
+ Examples:
254
+ $ wasit mpp-charge --target https://api.example.com/paid-endpoint --payer-key S...
255
+ $ wasit mpp-charge --target https://api.example.com/paid-endpoint --payer-key S... --json
256
+
257
+ Runs MPP-01 only. Not idempotent and has no read-only mode: every run settles
258
+ a real payment and moves testnet funds, because charge mode has no dry run.`)
140
259
  .action(async (opts) => {
260
+ const jsonMode = opts.json === true;
141
261
  const payerSecretKey = opts.payerKey ?? process.env.MPP_PAYER_SECRET;
142
262
  if (!payerSecretKey) {
143
263
  console.error("No payer key. Pass --payer-key or set MPP_PAYER_SECRET in .env.");
144
264
  process.exit(2);
145
265
  }
146
- console.log("MPP-01 settles a real payment. If the target is reachable, testnet funds will move.\n");
266
+ note(jsonMode, "MPP-01 settles a real payment. If the target is reachable, testnet funds will move.\n");
147
267
  const results = await runMppChargeSuite({
148
268
  target: opts.target,
149
269
  network: opts.network ?? process.env.MPP_STELLAR_NETWORK ?? "stellar:testnet",
150
270
  payerSecretKey,
151
271
  ...(opts.rpcUrl ? { rpcUrl: opts.rpcUrl } : {}),
152
272
  });
153
- process.exit(report(results));
273
+ process.exit(report(results, jsonMode));
154
274
  });
155
- program.parse();
275
+ registerWalletCommand(program);
276
+ const isBareInteractiveInvocation = process.argv.length <= 2 && process.stdout.isTTY === true;
277
+ if (isBareInteractiveInvocation) {
278
+ render(createElement(App));
279
+ }
280
+ else {
281
+ program.parse();
282
+ }
@@ -0,0 +1 @@
1
+ export declare const CLI_VERSION: string;
@@ -0,0 +1,8 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+ // Read this package's own version at runtime so `wasit --version` and the
4
+ // dashboard's footer can never drift from what npm actually published.
5
+ // Resolved relative to the compiled file (dist/version.js), not the source
6
+ // layout, since only the compiled output ships to consumers.
7
+ const { version } = require("../package.json");
8
+ export const CLI_VERSION = version;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `wasit wallet` — testnet-only convenience commands for the payer keys the
3
+ * other subcommands already read from .env. Deliberately has no --network
4
+ * flag: Friendbot, the printed USDC issuer, and the whole idea of a
5
+ * throwaway generated key only make sense on testnet, so there is nothing
6
+ * here that could be pointed at pubnet by mistake.
7
+ *
8
+ * Every failure path here exits 2 (configuration) or 1 (the operation ran and
9
+ * failed) with a single-line message, the same contract the check subcommands
10
+ * follow — core's wallet layer classifies its own errors, so nothing in this
11
+ * file ever has to inspect a Stellar SDK error type to decide which it is.
12
+ */
13
+ import type { Command } from "commander";
14
+ export declare function registerWalletCommand(program: Command): void;