@wasit-dev/cli 0.2.0 → 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.
- package/README.md +35 -2
- package/dist/dashboard/App.d.ts +9 -0
- package/dist/dashboard/App.js +39 -0
- package/dist/dashboard/CatalogueView.d.ts +5 -0
- package/dist/dashboard/CatalogueView.js +23 -0
- package/dist/dashboard/Home.d.ts +8 -0
- package/dist/dashboard/Home.js +54 -0
- package/dist/dashboard/RunView.d.ts +10 -0
- package/dist/dashboard/RunView.js +165 -0
- package/dist/dashboard/TargetForm.d.ts +8 -0
- package/dist/dashboard/TargetForm.js +60 -0
- package/dist/dashboard/WalletView.d.ts +5 -0
- package/dist/dashboard/WalletView.js +253 -0
- package/dist/dashboard/banner.d.ts +12 -0
- package/dist/dashboard/banner.js +32 -0
- package/dist/dashboard/env-file.d.ts +20 -0
- package/dist/dashboard/env-file.js +67 -0
- package/dist/dashboard/environment.d.ts +14 -0
- package/dist/dashboard/environment.js +25 -0
- package/dist/dashboard/format.d.ts +6 -0
- package/dist/dashboard/format.js +10 -0
- package/dist/dashboard/runners.d.ts +15 -0
- package/dist/dashboard/runners.js +45 -0
- package/dist/dashboard/theme.d.ts +21 -0
- package/dist/dashboard/theme.js +21 -0
- package/dist/dashboard/useElapsedMs.d.ts +10 -0
- package/dist/dashboard/useElapsedMs.js +21 -0
- package/dist/dashboard/useSpinnerFrame.d.ts +7 -0
- package/dist/dashboard/useSpinnerFrame.js +20 -0
- package/dist/dashboard/wallet-actions.d.ts +41 -0
- package/dist/dashboard/wallet-actions.js +64 -0
- package/dist/index.js +15 -2
- package/dist/version.d.ts +1 -0
- package/dist/version.js +8 -0
- package/dist/wallet-command.d.ts +14 -0
- package/dist/wallet-command.js +311 -0
- package/package.json +17 -4
|
@@ -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,6 +1,11 @@
|
|
|
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";
|
|
6
|
+
import { App } from "./dashboard/App.js";
|
|
7
|
+
import { CLI_VERSION } from "./version.js";
|
|
8
|
+
import { registerWalletCommand } from "./wallet-command.js";
|
|
4
9
|
import { CHECK_CATALOGUE, PROTOCOL_IDS, checkStatus, runMppChannelSuite, runMppChargeSuite, runX402PaymentChecks, runX402ReadChecks, summarize, toStructuredRun, } from "@wasit-dev/core";
|
|
5
10
|
/** Which wasit subcommand runs each protocol's checks — for `wasit checks` output. */
|
|
6
11
|
const COMMAND_BY_PROTOCOL = {
|
|
@@ -29,13 +34,14 @@ const program = new Command();
|
|
|
29
34
|
program
|
|
30
35
|
.name("wasit")
|
|
31
36
|
.description("Protocol-compliance testing for x402 / MPP on Stellar")
|
|
32
|
-
.version(
|
|
37
|
+
.version(CLI_VERSION)
|
|
33
38
|
.addHelpText("after", `
|
|
34
39
|
Examples:
|
|
35
40
|
$ wasit checks
|
|
36
41
|
$ wasit test --target https://api.example.com/paid-endpoint --read-only
|
|
37
42
|
$ wasit mpp-charge --target https://api.example.com/paid-endpoint --payer-key S...
|
|
38
43
|
$ wasit mpp-channel --target https://api.example.com/paid-endpoint
|
|
44
|
+
$ wasit wallet create --role mpp-charge --fund
|
|
39
45
|
|
|
40
46
|
Run "wasit <command> --help" for that command's own options and cost notes.
|
|
41
47
|
Add --json to test/mpp-charge/mpp-channel for machine-readable output.
|
|
@@ -266,4 +272,11 @@ a real payment and moves testnet funds, because charge mode has no dry run.`)
|
|
|
266
272
|
});
|
|
267
273
|
process.exit(report(results, jsonMode));
|
|
268
274
|
});
|
|
269
|
-
program
|
|
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;
|
package/dist/version.js
ADDED
|
@@ -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;
|
|
@@ -0,0 +1,311 @@
|
|
|
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 { oraPromise } from "ora";
|
|
14
|
+
import { createUsdcTrustline, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, getTestnetWalletStatus, publicKeyFromSecret, sendUsdcFromDistributor, TESTNET_USDC_ISSUER, } from "@wasit-dev/core";
|
|
15
|
+
/** Every role a key can be generated for. */
|
|
16
|
+
const ROLES = ["x402", "mpp-charge", "mpp-channel"];
|
|
17
|
+
/**
|
|
18
|
+
* Roles that own a funded Stellar account, and are therefore the only ones
|
|
19
|
+
* `status` and `fund` can say anything about. `mpp-channel` is deliberately
|
|
20
|
+
* absent: `COMMITMENT_SECRET_HEX` is a raw ed25519 seed that only ever signs
|
|
21
|
+
* commitment bytes off-chain, so it has no address and no balance to report.
|
|
22
|
+
*/
|
|
23
|
+
const ACCOUNT_ROLES = ["x402", "mpp-charge"];
|
|
24
|
+
/** Which .env variable holds each role's key. */
|
|
25
|
+
const ROLE_ENV_VAR = {
|
|
26
|
+
x402: "STELLAR_PRIVATE_KEY",
|
|
27
|
+
"mpp-charge": "MPP_PAYER_SECRET",
|
|
28
|
+
"mpp-channel": "COMMITMENT_SECRET_HEX",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Validates --role against the roles the calling subcommand actually
|
|
32
|
+
* supports, printing the same "Unknown option" style as the rest of the CLI.
|
|
33
|
+
*
|
|
34
|
+
* `allowed` is per-subcommand rather than global because `create` works for
|
|
35
|
+
* all three roles while `status` and `fund` only work for the two that have
|
|
36
|
+
* an on-chain account. Accepting a role a subcommand cannot serve and only
|
|
37
|
+
* discovering it deeper in — where it surfaced as an SDK stack trace — was
|
|
38
|
+
* the behavior this replaces.
|
|
39
|
+
*/
|
|
40
|
+
function requireRole(value, allowed) {
|
|
41
|
+
if (value !== undefined && allowed.includes(value)) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
console.error(`--role is required. Expected one of: ${allowed.join(", ")}.`);
|
|
46
|
+
process.exit(2);
|
|
47
|
+
}
|
|
48
|
+
const knownButUnsupported = ROLES.includes(value);
|
|
49
|
+
console.error(knownButUnsupported
|
|
50
|
+
? `--role "${value}" is not supported by this command. Expected one of: ` +
|
|
51
|
+
`${allowed.join(", ")}. ${ROLE_ENV_VAR[value]} signs off-chain ` +
|
|
52
|
+
`and has no account to inspect or fund — see docs/guides/configuration.md.`
|
|
53
|
+
: `Unknown --role "${value}". Expected one of: ${allowed.join(", ")}.`);
|
|
54
|
+
process.exit(2);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolves a role's configured secret to its public key, exiting 2 with a
|
|
58
|
+
* readable message when the variable is unset or holds something that is not
|
|
59
|
+
* a Stellar secret key. Without this a typo in .env reached
|
|
60
|
+
* `Keypair.fromSecret` unguarded and terminated the process with an SDK stack
|
|
61
|
+
* trace instead of the CLI's own error contract.
|
|
62
|
+
*/
|
|
63
|
+
function resolvePublicKey(role) {
|
|
64
|
+
const envVar = ROLE_ENV_VAR[role];
|
|
65
|
+
const secret = process.env[envVar];
|
|
66
|
+
if (!secret) {
|
|
67
|
+
console.error(`${envVar} is not set. Run \`wasit wallet create --role ${role}\` first.`);
|
|
68
|
+
process.exit(2);
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return { secret, publicKey: publicKeyFromSecret(secret, envVar) };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error(messageOf(error));
|
|
75
|
+
process.exit(2);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function messageOf(error) {
|
|
79
|
+
return error instanceof Error ? error.message : String(error);
|
|
80
|
+
}
|
|
81
|
+
/** Says what Friendbot actually did, rather than always claiming a transfer. */
|
|
82
|
+
function friendbotText(outcome) {
|
|
83
|
+
return outcome === "funded"
|
|
84
|
+
? "Funded: 10,000 XLM."
|
|
85
|
+
: "Already funded — Friendbot left the existing balance alone.";
|
|
86
|
+
}
|
|
87
|
+
function formatBalance(balance) {
|
|
88
|
+
const note = balance.issuer === TESTNET_USDC_ISSUER ? " (Circle testnet USDC)" : "";
|
|
89
|
+
return ` ${balance.code.padEnd(10)} ${balance.balance}${note}`;
|
|
90
|
+
}
|
|
91
|
+
function printWalletStatus(role, publicKey, status) {
|
|
92
|
+
console.log(`${role} ${publicKey}`);
|
|
93
|
+
if (!status.exists) {
|
|
94
|
+
console.log(` Not yet created on-chain. Run: wasit wallet fund --role ${role}`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
for (const balance of status.balances) {
|
|
98
|
+
console.log(formatBalance(balance));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function registerWalletCommand(program) {
|
|
102
|
+
const wallet = program
|
|
103
|
+
.command("wallet")
|
|
104
|
+
.description("Generate, fund, and inspect disposable Stellar testnet wallets");
|
|
105
|
+
wallet
|
|
106
|
+
.command("status")
|
|
107
|
+
.description("Show balances for the configured payer role(s)")
|
|
108
|
+
.option("--role <role>", `One of: ${ACCOUNT_ROLES.join(", ")}. Default: check both.`)
|
|
109
|
+
.option("--json", "Print as JSON instead of formatted text", false)
|
|
110
|
+
.addHelpText("after", `
|
|
111
|
+
Examples:
|
|
112
|
+
$ wasit wallet status
|
|
113
|
+
$ wasit wallet status --role mpp-charge --json
|
|
114
|
+
|
|
115
|
+
Testnet only — there is no --network flag. mpp-channel is not accepted here
|
|
116
|
+
even when configured: COMMITMENT_SECRET_HEX only ever signs off-chain (see
|
|
117
|
+
docs/guides/configuration.md) and has no on-chain balance of its own.`)
|
|
118
|
+
.action(async (opts) => {
|
|
119
|
+
const jsonMode = opts.json === true;
|
|
120
|
+
const roles = opts.role !== undefined ? [requireRole(opts.role, ACCOUNT_ROLES)] : ACCOUNT_ROLES;
|
|
121
|
+
const rows = [];
|
|
122
|
+
for (const role of roles) {
|
|
123
|
+
const envVar = ROLE_ENV_VAR[role];
|
|
124
|
+
const secret = process.env[envVar];
|
|
125
|
+
if (!secret) {
|
|
126
|
+
rows.push({ role, configured: false });
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
// A malformed key is this role's own problem, not the run's: the
|
|
130
|
+
// other role is still worth reporting, so it is recorded as that
|
|
131
|
+
// row's error rather than exiting the whole command.
|
|
132
|
+
let publicKey;
|
|
133
|
+
try {
|
|
134
|
+
publicKey = publicKeyFromSecret(secret, envVar);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
rows.push({ role, configured: true, error: messageOf(error) });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const status = jsonMode
|
|
142
|
+
? await getTestnetWalletStatus(publicKey)
|
|
143
|
+
: await oraPromise(getTestnetWalletStatus(publicKey), `Checking ${role}...`);
|
|
144
|
+
rows.push({ role, configured: true, publicKey, status });
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
// One role's Horizon lookup failing (a network hiccup, most
|
|
148
|
+
// likely) should not stop the rest of the roles from reporting.
|
|
149
|
+
rows.push({ role, configured: true, publicKey, error: messageOf(error) });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (jsonMode) {
|
|
153
|
+
console.log(JSON.stringify(rows, null, 2));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
for (const row of rows) {
|
|
157
|
+
if (!row.configured) {
|
|
158
|
+
console.log(`${row.role} (${ROLE_ENV_VAR[row.role]} not set)`);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (row.error !== undefined) {
|
|
162
|
+
console.log(`${row.role} ${row.publicKey ?? `(${ROLE_ENV_VAR[row.role]} unreadable)`}`);
|
|
163
|
+
console.log(` Could not check: ${row.error}`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
printWalletStatus(row.role, row.publicKey, row.status);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
wallet
|
|
170
|
+
.command("create")
|
|
171
|
+
.description("Generate a new testnet key for a payer role")
|
|
172
|
+
.requiredOption("--role <role>", `One of: ${ROLES.join(", ")}`)
|
|
173
|
+
.option("--fund", "Immediately fund the new key with testnet XLM", false)
|
|
174
|
+
.addHelpText("after", `
|
|
175
|
+
Examples:
|
|
176
|
+
$ wasit wallet create --role mpp-charge --fund
|
|
177
|
+
$ wasit wallet create --role mpp-channel
|
|
178
|
+
|
|
179
|
+
Testnet only. Prints the exact .env line(s) to paste — never writes to .env
|
|
180
|
+
itself, so it can never silently overwrite something already there.
|
|
181
|
+
|
|
182
|
+
The generated secret is printed to stdout: do not run this on a screen you
|
|
183
|
+
are recording, and never paste a pubnet key into these variables.`)
|
|
184
|
+
.action(async (opts) => {
|
|
185
|
+
const role = requireRole(opts.role, ROLES);
|
|
186
|
+
if (role === "mpp-channel") {
|
|
187
|
+
const key = generateCommitmentKey();
|
|
188
|
+
console.log("Generated a new MPP commitment key (a signing key, not a funded account " +
|
|
189
|
+
"— see docs/guides/configuration.md):\n");
|
|
190
|
+
console.log("Paste into .env:\n");
|
|
191
|
+
console.log(`COMMITMENT_SECRET_HEX=${key.secretHex}`);
|
|
192
|
+
console.log(`COMMITMENT_PUBKEY_HEX=${key.publicKeyHex}`);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const generated = generateTestnetWallet();
|
|
196
|
+
console.log(`Generated a new testnet keypair for ${role}:\n`);
|
|
197
|
+
console.log(`Public: ${generated.publicKey}`);
|
|
198
|
+
console.log(`Secret: ${generated.secretKey}\n`);
|
|
199
|
+
console.log("Paste into .env:\n");
|
|
200
|
+
if (role === "x402") {
|
|
201
|
+
console.log(`STELLAR_PRIVATE_KEY=${generated.secretKey}`);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
console.log(`MPP_PAYER_SECRET=${generated.secretKey}`);
|
|
205
|
+
console.log(`MPP_PAYER_PUBLIC=${generated.publicKey}`);
|
|
206
|
+
}
|
|
207
|
+
console.log("\nTestnet only — never reuse this key, and never put a pubnet secret here.");
|
|
208
|
+
if (opts.fund === true) {
|
|
209
|
+
console.log();
|
|
210
|
+
try {
|
|
211
|
+
await oraPromise(fundWithFriendbot(generated.publicKey), {
|
|
212
|
+
text: "Funding with testnet XLM via Friendbot...",
|
|
213
|
+
successText: (result) => friendbotText(result),
|
|
214
|
+
failText: (error) => `Could not fund via Friendbot: ${messageOf(error)}`,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
wallet
|
|
223
|
+
.command("fund")
|
|
224
|
+
.description("Fund a configured payer role with testnet XLM or USDC")
|
|
225
|
+
.requiredOption("--role <role>", `One of: ${ACCOUNT_ROLES.join(", ")}`)
|
|
226
|
+
.option("--asset <asset>", "xlm or usdc", "xlm")
|
|
227
|
+
.option("--amount <amount>", "USDC amount to request from the distributor account", "50")
|
|
228
|
+
.addHelpText("after", `
|
|
229
|
+
Examples:
|
|
230
|
+
$ wasit wallet fund --role mpp-charge
|
|
231
|
+
$ wasit wallet fund --role mpp-charge --asset usdc
|
|
232
|
+
|
|
233
|
+
--asset xlm calls Stellar's public Friendbot directly — fully automatic.
|
|
234
|
+
--asset usdc creates a trustline to Circle's testnet USDC automatically, but
|
|
235
|
+
actually receiving a balance needs either a manual visit to
|
|
236
|
+
https://faucet.circle.com (paste the printed public key) or
|
|
237
|
+
WASIT_USDC_DISTRIBUTOR_SECRET set in .env, naming an account you already
|
|
238
|
+
funded that way once — there is no scriptable USDC faucet for Stellar.`)
|
|
239
|
+
.action(async (opts) => {
|
|
240
|
+
const role = requireRole(opts.role, ACCOUNT_ROLES);
|
|
241
|
+
const { secret, publicKey } = resolvePublicKey(role);
|
|
242
|
+
const asset = opts.asset;
|
|
243
|
+
if (asset !== "xlm" && asset !== "usdc") {
|
|
244
|
+
console.error(`Unknown --asset "${asset}". Expected "xlm" or "usdc".`);
|
|
245
|
+
process.exit(2);
|
|
246
|
+
}
|
|
247
|
+
if (asset === "xlm") {
|
|
248
|
+
try {
|
|
249
|
+
await oraPromise(fundWithFriendbot(publicKey), {
|
|
250
|
+
text: `Funding ${publicKey} with testnet XLM via Friendbot...`,
|
|
251
|
+
successText: (result) => friendbotText(result),
|
|
252
|
+
failText: (error) => `Could not fund via Friendbot: ${messageOf(error)}`,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
let before;
|
|
261
|
+
try {
|
|
262
|
+
before = await oraPromise(getTestnetWalletStatus(publicKey), "Checking XLM balance...");
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.error(`Could not read the account: ${messageOf(error)}`);
|
|
266
|
+
process.exit(1);
|
|
267
|
+
}
|
|
268
|
+
const xlmBalance = before.balances.find((balance) => balance.code === "XLM");
|
|
269
|
+
if (!before.exists || Number(xlmBalance?.balance ?? "0") < 2) {
|
|
270
|
+
try {
|
|
271
|
+
await oraPromise(fundWithFriendbot(publicKey), {
|
|
272
|
+
text: "Funding XLM first — a trustline needs a small reserve and fee...",
|
|
273
|
+
successText: (result) => friendbotText(result),
|
|
274
|
+
failText: (error) => `Could not fund via Friendbot: ${messageOf(error)}`,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
process.exit(1);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
await oraPromise(createUsdcTrustline(secret, ROLE_ENV_VAR[role]), {
|
|
283
|
+
text: "Creating a trustline to testnet USDC...",
|
|
284
|
+
successText: "Trustline created.",
|
|
285
|
+
failText: (error) => `Could not create the trustline: ${messageOf(error)}`,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
const distributorSecret = process.env.WASIT_USDC_DISTRIBUTOR_SECRET;
|
|
292
|
+
if (!distributorSecret) {
|
|
293
|
+
console.log(`\nNo USDC balance yet. Get some at https://faucet.circle.com ` +
|
|
294
|
+
`(Stellar Testnet, paste ${publicKey}),\n` +
|
|
295
|
+
"or set WASIT_USDC_DISTRIBUTOR_SECRET in .env to an account you've already funded " +
|
|
296
|
+
"that\nway, then rerun this command to send automatically.");
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const amount = opts.amount;
|
|
300
|
+
try {
|
|
301
|
+
await oraPromise(sendUsdcFromDistributor(distributorSecret, publicKey, amount), {
|
|
302
|
+
text: `Sending ${amount} USDC from the distributor account...`,
|
|
303
|
+
successText: `Sent ${amount} USDC.`,
|
|
304
|
+
failText: (error) => `Could not send USDC: ${messageOf(error)}`,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
process.exit(1);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wasit-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "CLI for x402/MPP protocol-conformance testing on Stellar \u2014 verifies a service's payment flow settles on-chain per spec.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -36,11 +36,24 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "tsc -p tsconfig.json"
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"test": "node --import tsx --test \"test/unit/**/*.test.ts*\"",
|
|
41
|
+
"typecheck": "tsc -p test/tsconfig.json"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
42
|
-
"@wasit-dev/core": "^0.
|
|
44
|
+
"@wasit-dev/core": "^0.3.0",
|
|
45
|
+
"cfonts": "^3.3.1",
|
|
43
46
|
"commander": "^15.0.0",
|
|
44
|
-
"dotenv": "^17.4.2"
|
|
47
|
+
"dotenv": "^17.4.2",
|
|
48
|
+
"ink": "^7.1.1",
|
|
49
|
+
"ink-select-input": "^6.2.0",
|
|
50
|
+
"ink-text-input": "^6.0.0",
|
|
51
|
+
"ora": "^9.4.1",
|
|
52
|
+
"react": "^19.2.8"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/react": "^19.2.18",
|
|
56
|
+
"ink-testing-library": "^4.0.0",
|
|
57
|
+
"tsx": "^4.23.1"
|
|
45
58
|
}
|
|
46
59
|
}
|