fix: accept buzz-admin hex secrets in desktop key import (#2815) - #4504
fix: accept buzz-admin hex secrets in desktop key import (#2815)#4504Chessing234 wants to merge 4 commits into
Conversation
buzz-admin was only emitting a hex secret, so operators following the bootstrap hint could not paste into desktop onboarding (block#2815). Signed-off-by: Taksh <takshkothari09@gmail.com>
Match Keys::parse / BUZZ_PRIVATE_KEY so buzz-admin generate-key output enables Next instead of sitting on 'waiting for nsec1' (block#2815, block#3880). Signed-off-by: Taksh <takshkothari09@gmail.com>
Lock buzz-admin hex secrets through classify/submit and npub preview. Signed-off-by: Taksh <takshkothari09@gmail.com>
|
hex import for buzz-admin secrets — pairs with the #3880/#2815 confusion. @wesbillman if hosted/onboarding is on your plate. |
|
@jurgenhaas @ashbrener small desktop fix for buzz-admin hex secrets on key import (#2815). easy review if you're in that area. |
ashbrener
left a comment
There was a problem hiding this comment.
Read this closely because it fixes a papercut I hit yesterday: buzz-admin generate-key prints hex, the import form gated on startsWith("nsec1"), so the key it just gave me was rejected by the app. Frontend stricter than the backend for no reason. Adding npub to the generate-key output is a nice extra — I spent real time yesterday converting a hex pubkey by hand to find which identity a relay was configured with.
Two things I checked specifically, since they are where this kind of change tends to break, and both are fine:
The new "hex" kind cannot fall into a wrong branch. KeyImportKind is only ever branched on at keyImportInput.ts:123 (kind === "ncryptsec") and NostrKeyImportForm.tsx:66. Everything else routes through nsecToNpub, which now normalizes hex. No exhaustive switch to update.
Hex cannot leak into the keyring. The form submits the raw input, so I expected to find hex being persisted where the rest of the system assumes bech32 — but import_identity (commands/identity.rs:336) passes the parsed Keys object to persist_imported_identity, not the string. Storage stays normalized.
One inconsistency worth a look, inline below.
|
|
||
| const HEX_PUBKEY_REGEX = /^[0-9a-f]{64}$/; | ||
| /** 32-byte secret as 64 hex chars — what `buzz-admin generate-key` prints. */ | ||
| const HEX_SECRET_REGEX = /^[0-9a-fA-F]{64}$/; |
There was a problem hiding this comment.
HEX_SECRET_REGEX is case-insensitive while HEX_PUBKEY_REGEX on the line above is lowercase-only. After this PR, pasting an uppercase hex secret works but an uppercase hex pubkey still does not — same file, same shape, different tolerance. parsePubkeyInput already lowercases bech32 input, so accepting uppercase hex there would be consistent with its own behaviour.
Not blocking, and arguably out of scope for this PR, but the two constants sitting adjacent with different character classes will read as an oversight later.
The same regex is also declared a second time in keyImportInput.ts. Exporting one from here and importing it there would keep them from drifting.
Align pubkey/secret hex tolerance and stop duplicating the pattern in keyImportInput. Signed-off-by: Taksh <takshkothari09@gmail.com>
|
good catch — tip now exports a shared case-insensitive |
Summary
buzz-admin generate-keynow prints both hex andnsec1forms (plus npub)Keys::parse/BUZZ_PRIVATE_KEYalready dobuzz-admin generate-keyemits a hex secret that desktop onboarding rejects (expectsnsec1) #2815 and the hex-paste ask on Unable to make different identity key on Windows desktop #3880Test plan
buzz-admin generate-keyshows hex + nseccd desktop && npm test -- src/shared/lib/nostrUtils.test.mjs src/features/onboarding/lib/keyImportInput.test.mjs