mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Fix nip19 npub decoding with proper positive type guard
Use positive type guard (decoded.type === 'npub' && typeof decoded.data === 'string') to properly narrow the union type. TypeScript requires both conditions to infer the correct type for decoded.data when dealing with discriminated unions.
This commit is contained in:
1 parent
ecec383f2f
commit
c037bd1376
1 file changed
+4
-2
@@ -218,10 +218,12 @@ export function PullRequestDialog({
|
||||
if (pubkeyOrNpub.startsWith('npub1')) {
|
||||
try {
|
||||
const decoded = nip19.decode(pubkeyOrNpub);
|
||||
if (decoded.type !== 'npub') {
|
||||
// Type guard: ensure we have an npub
|
||||
if (decoded.type === 'npub' && typeof decoded.data === 'string') {
|
||||
owner = decoded.data; // hex pubkey
|
||||
} else {
|
||||
throw new Error('Expected npub but got ' + decoded.type);
|
||||
}
|
||||
owner = decoded.data; // hex pubkey
|
||||
} catch (err) {
|
||||
console.error('Failed to decode npub:', err);
|
||||
setError('Invalid npub in Nostr URL');
|
||||
|
||||
Reference in new issue
Block a user