@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.
- package/README.md +39 -5
- 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 +139 -12
- 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 +21 -11
|
@@ -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": {
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
],
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/
|
|
14
|
+
"url": "git+https://github.com/wasit-dev/wasit.git",
|
|
15
15
|
"directory": "packages/cli"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/
|
|
17
|
+
"homepage": "https://github.com/wasit-dev/wasit#readme",
|
|
18
18
|
"bugs": {
|
|
19
|
-
"url": "https://github.com/
|
|
19
|
+
"url": "https://github.com/wasit-dev/wasit/issues"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"stellar",
|
|
@@ -36,14 +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
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
44
|
+
"@wasit-dev/core": "^0.3.0",
|
|
45
|
+
"cfonts": "^3.3.1",
|
|
46
|
+
"commander": "^15.0.0",
|
|
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"
|
|
48
58
|
}
|
|
49
59
|
}
|