Commit 1f417e3
committed
fix(wallet): type key-resolution failures, and validate refs at init
Finding 6 and the validation trio.
**Key resolution failures are typed at the throw.**
`resolveKeyRef` and the keystore decrypt run at *use* time, from inside
the client construction every signing command performs before its try
block — so a plain Error reached incur's top-level handler and rendered
as `{ code: 'UNKNOWN' }`, no code and no `retryable`. That is what an
agent saw for the most common failure a vault-backed wallet has:
installed, but not logged in.
The obvious fix — move construction inside each command's try — would
have made it worse. Those catches end in `out.fail('UPLOAD_FAILED', …)`,
`'COSTS_FAILED'`, `'DATASET_LIST_FAILED'`, so a key that could not be
fetched would be reported as an upload that failed: typed, and wrong.
Throwing `Errors.IncurError` instead fixes all 15 commands at once,
plus any command that does not exist yet, and needs no command edits.
Codes are shared with the ones `walletPreflight` already emits for the
same conditions — whether the guard caught it or the resolver did is an
implementation detail, and the fix is identical either way. New at use
time: `KEY_REF_RESOLUTION_FAILED` (provider ran and refused — explicitly
not retryable, since every cause needs a deliberate act),
`KEY_REF_NOT_A_KEY`, `KEY_REF_AMBIGUOUS`, `KEYSTORE_DECRYPT_FAILED`,
`KEYSTORE_NOT_A_KEY`, `KEYSTORE_AMBIGUOUS`.
**A leading `-` is no longer a legal reference.**
`clawdi:--project` passed SAFE_REF and reached argv as `clawdi vault
resolve --project`, so config steered the helper's own option parsing
rather than naming a secret. Not arbitrary execution, but more than
"only the reference comes from config" allows. A dash anywhere else
stays legal — `FILECOIN-PRIVATE-KEY` still resolves.
**`wallet init` refuses what no command could resolve.**
It validated the `<provider>:<ref>` shape and nothing else, so
`clawdi:MY KEY&touch x` returned `configured`, cleared the previous
wallet, and left every later command failing with "re-run `foc-cli
wallet init`" — pointing back at the command that had just accepted it.
The check is shared with the resolver via `unsafeRefReason`, and the
preflight applies it too so a config already holding one gets a CTA
instead of a bare throw mid-command.
**`--keyProject` on its own now does what both docs promise.**
No branch consumed it: the command fell through to `already_configured`,
wrote nothing, and reported success, so the caller believed a scope was
pinned that never was and every command kept resolving against the
provider's default project. It now re-scopes the configured reference.
Without one it fails `KEY_PROJECT_WITHOUT_KEY_REF`, and combined with
`--auto`/`--privateKey`/`--keystore` it is refused rather than shadowing
them — answering a contradiction by quietly picking one is the same
silent-ignore this removes.1 parent ee5309d commit 1f417e3
7 files changed
Lines changed: 479 additions & 63 deletions
File tree
- cli
- src
- commands/wallet
- tests
- skills/foc-cli/references
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
29 | 46 | | |
30 | 47 | | |
31 | 48 | | |
| |||
76 | 93 | | |
77 | 94 | | |
78 | 95 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 96 | + | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
| |||
95 | 105 | | |
96 | 106 | | |
97 | 107 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
105 | 126 | | |
106 | 127 | | |
107 | 128 | | |
| |||
220 | 241 | | |
221 | 242 | | |
222 | 243 | | |
223 | | - | |
224 | | - | |
225 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
226 | 249 | | |
227 | 250 | | |
228 | 251 | | |
| |||
249 | 272 | | |
250 | 273 | | |
251 | 274 | | |
252 | | - | |
253 | | - | |
254 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
255 | 281 | | |
256 | | - | |
257 | | - | |
258 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
259 | 287 | | |
260 | 288 | | |
261 | 289 | | |
| |||
265 | 293 | | |
266 | 294 | | |
267 | 295 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
271 | 301 | | |
272 | 302 | | |
273 | | - | |
274 | | - | |
275 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
276 | 307 | | |
277 | 308 | | |
278 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
326 | 327 | | |
327 | 328 | | |
328 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
329 | 403 | | |
330 | 404 | | |
331 | 405 | | |
| |||
349 | 423 | | |
350 | 424 | | |
351 | 425 | | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
352 | 448 | | |
353 | 449 | | |
354 | 450 | | |
| |||
0 commit comments