diff --git a/example-apps/dashnote/src/components/LoginModal.tsx b/example-apps/dashnote/src/components/LoginModal.tsx index cb6e2e2..3dda78d 100644 --- a/example-apps/dashnote/src/components/LoginModal.tsx +++ b/example-apps/dashnote/src/components/LoginModal.tsx @@ -1,6 +1,8 @@ -import { useEffect, useState, type FormEvent } from "react"; +import { useEffect, useMemo, useState, type FormEvent } from "react"; import { registerContract } from "../dash/contract"; +import { useWifPreview } from "../hooks/useWifPreview"; +import { detectSecretShape } from "../lib/detectSecretShape"; import { errorMessage } from "../lib/logger"; import { useSession } from "../session/useSession"; import { Modal } from "./Modal"; @@ -13,7 +15,7 @@ export interface LoginModalProps { export function LoginModal({ open, onClose }: LoginModalProps) { const session = useSession(); - const [mnemonic, setMnemonic] = useState(""); + const [secret, setSecret] = useState(""); const [identityIndex, setIdentityIndex] = useState("0"); const [contractInput, setContractInput] = useState(session.contractId ?? ""); const [error, setError] = useState(null); @@ -26,6 +28,17 @@ export function LoginModal({ open, onClose }: LoginModalProps) { const showRememberedPanel = Boolean( session.rememberedIdentityId && !useDifferentIdentity, ); + // Detect what the user pasted so we can hide the identity-index field for + // single-key WIF input (where DIP-13 derivation doesn't apply). + const secretShape = useMemo( + () => (secret.trim() ? detectSecretShape(secret) : null), + [secret], + ); + const isWifInput = secretShape === "wif"; + const wifPreview = useWifPreview(session.sdk, secret, isWifInput); + const previewBlocksLogin = + wifPreview.status === "wrong-purpose" || + wifPreview.status === "key-disabled"; useEffect(() => { setContractInput(session.contractId ?? ""); @@ -36,7 +49,7 @@ export function LoginModal({ open, onClose }: LoginModalProps) { setRememberMe(true); setUseDifferentIdentity(false); setError(null); - setMnemonic(""); + setSecret(""); } }, [open]); @@ -69,11 +82,11 @@ export function LoginModal({ open, onClose }: LoginModalProps) { setSubmitting(true); try { const index = Number.parseInt(identityIndex, 10); - await session.login(mnemonic, { + await session.login(secret, { identityIndex: Number.isNaN(index) ? 0 : index, rememberMe, }); - setMnemonic(""); + setSecret(""); onClose(); } catch (err) { setError(errorMessage(err)); @@ -240,7 +253,9 @@ export function LoginModal({ open, onClose }: LoginModalProps) { {session.rememberedIdentityId && ( @@ -320,18 +378,20 @@ export function LoginModal({ open, onClose }: LoginModalProps) { {showAdvanced && (
- + {!isWifInput && ( + + )}
@@ -363,15 +423,14 @@ export function LoginModal({ open, onClose }: LoginModalProps) { )}

- Your mnemonic stays in browser memory and is never sent or saved. - Only the public identity ID is persisted, and only when “Remember - me” is checked. + Your secret never leaves this browser. Only the public identity ID + is stored when this identity is remembered on this device.