From ea6220277da93060217ba4473b7730046d95ddc3 Mon Sep 17 00:00:00 2001 From: Gigi Date: Fri, 17 Oct 2025 10:37:45 +0200 Subject: [PATCH] =?UTF-8?q?feat(debug):=20add=20/debug=20page=20with=20NIP?= =?UTF-8?q?-46=20encrypt=E2=86=92decrypt=20probes=20for=20nip04/nip44?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 ++ src/components/Debug.tsx | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/components/Debug.tsx diff --git a/src/App.tsx b/src/App.tsx index 1b9d5253..f368f1fb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,6 +17,7 @@ import { useToast } from './hooks/useToast' import { useOnlineStatus } from './hooks/useOnlineStatus' import { RELAYS } from './config/relays' import { SkeletonThemeProvider } from './components/Skeletons' +import Debug from './components/Debug' const DEFAULT_ARTICLE = import.meta.env.VITE_DEFAULT_ARTICLE_NADDR || 'naddr1qvzqqqr4gupzqmjxss3dld622uu8q25gywum9qtg4w4cv4064jmg20xsac2aam5nqqxnzd3cxqmrzv3exgmr2wfesgsmew' @@ -168,6 +169,7 @@ function AppRoutes({ /> } /> + } /> } /> ) diff --git a/src/components/Debug.tsx b/src/components/Debug.tsx new file mode 100644 index 00000000..22918495 --- /dev/null +++ b/src/components/Debug.tsx @@ -0,0 +1,59 @@ +import React, { useMemo, useState } from 'react' +import { Hooks } from 'applesauce-react' + +const Debug: React.FC = () => { + const activeAccount = Hooks.useActiveAccount() + const [result, setResult] = useState('') + const [error, setError] = useState('') + + const signer = useMemo(() => (activeAccount as unknown as { signer?: unknown })?.signer, [activeAccount]) + const hasNip04 = typeof (signer as { nip04?: { encrypt?: unknown; decrypt?: unknown } } | undefined)?.nip04?.encrypt === 'function' + const hasNip44 = typeof (signer as { nip44?: { encrypt?: unknown; decrypt?: unknown } } | undefined)?.nip44?.encrypt === 'function' + const pubkey = (activeAccount as unknown as { pubkey?: string })?.pubkey + + const doRoundtrip = async (mode: 'nip04' | 'nip44') => { + setResult('') + setError('') + if (!signer || !pubkey) { + setError('No active signer/pubkey') + return + } + try { + const api = (signer as any)[mode] + if (!api || typeof api.encrypt !== 'function' || typeof api.decrypt !== 'function') { + setError(`${mode} not available on signer`) + return + } + const cipher = await api.encrypt(pubkey, `debug-${mode}-${Date.now()}`) + const plain = await api.decrypt(pubkey, cipher) + setResult(String(plain)) + } catch (e) { + setError(e instanceof Error ? e.message : String(e)) + } + } + + return ( +
+

Debug / NIP-46 Echo

+
+
+
Active pubkey: {pubkey || 'none'}
+
Signer has nip04: {hasNip04 ? 'yes' : 'no'}
+
Signer has nip44: {hasNip44 ? 'yes' : 'no'}
+
+ + +
+ {result && ( +
Plaintext: {result}
+ )} + {error && ( +
Error: {error}
+ )} +
+
+
+ ) +} + +export default Debug