{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sign-message",
  "title": "Sign Message",
  "description": "Button that signs a message (EIP-191, useSignMessage) or typed data (EIP-712, useSignTypedData), opening the wallet picker when disconnected. Labeled steps, optional verification through the RPC (works for ERC-1271/6492 smart wallets), message preview, signature with copy. A rejected request shows as cancelled. Exports useSignFlow and SignPhase.",
  "dependencies": [
    "wagmi",
    "viem",
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "@0xui/connect-wallet",
    "@0xui/copy-button",
    "@0xui/morph-text",
    "@0xui/0xui-utils"
  ],
  "files": [
    {
      "path": "registry/default/components/sign-message.tsx",
      "content": "// Docs: https://0xui.io/components/sign-message.md\nimport { CheckIcon, Loader2Icon } from \"lucide-react\";\nimport { useState, type ComponentProps, type ReactNode } from \"react\";\nimport type { Hex, SignableMessage, TypedDataDefinition } from \"viem\";\nimport { useConnection, usePublicClient, useSignMessage, useSignTypedData } from \"wagmi\";\nimport { ConnectWalletDialog } from \"@/components/connect-wallet\";\nimport { CopyButton } from \"@/components/copy-button\";\nimport { MorphText } from \"@/components/morph-text\";\nimport { Button } from \"@/components/ui/button\";\nimport { agentConfirmText, errorCode, isUserRejection, truncateAddress } from \"@/lib/0xui-utils\";\nimport { cn } from \"@/lib/utils\";\n\nexport type SignPhase =\n  | \"idle\"\n  | \"signing\"\n  | \"verifying\"\n  | \"signed\"\n  | \"invalid\"\n  | \"cancelled\"\n  | \"error\";\n\nexport type SignRequest =\n  | { message: SignableMessage; typedData?: never }\n  | { typedData: TypedDataDefinition; message?: never };\n\n/**\n * Sign a message (EIP-191) or typed data (EIP-712) with the connected\n * wallet, and optionally verify the signature. Verification goes through\n * the RPC, so smart-contract wallets (ERC-1271/6492) verify too.\n */\nexport function useSignFlow(\n  request: SignRequest,\n  { verify = false, onSigned }: { verify?: boolean; onSigned?: (signature: Hex) => void } = {},\n) {\n  const { address } = useConnection();\n  const client = usePublicClient();\n  const signMessage = useSignMessage();\n  const signTypedData = useSignTypedData();\n  const [phase, setPhase] = useState<SignPhase>(\"idle\");\n  const [signature, setSignature] = useState<Hex>();\n  const [error, setError] = useState<Error>();\n\n  const sign = async () => {\n    if (!address) return;\n    setError(undefined);\n    setSignature(undefined);\n    setPhase(\"signing\");\n    try {\n      const sig = request.typedData\n        ? await signTypedData.mutateAsync(request.typedData)\n        : await signMessage.mutateAsync({ message: request.message! });\n      setSignature(sig);\n      onSigned?.(sig);\n      if (verify && client) {\n        setPhase(\"verifying\");\n        const valid = request.typedData\n          ? await client.verifyTypedData({ ...request.typedData, address, signature: sig })\n          : await client.verifyMessage({ address, signature: sig, message: request.message! });\n        setPhase(valid ? \"signed\" : \"invalid\");\n      } else {\n        setPhase(\"signed\");\n      }\n    } catch (e) {\n      const err = e instanceof Error ? e : new Error(String(e));\n      setError(err);\n      setPhase(isUserRejection(err) ? \"cancelled\" : \"error\");\n    }\n  };\n\n  const reset = () => {\n    setPhase(\"idle\");\n    setSignature(undefined);\n    setError(undefined);\n  };\n\n  return { phase, signature, error, sign, reset, isConnected: Boolean(address) };\n}\n\nexport type SignMessageProps = Omit<ComponentProps<typeof Button>, \"onClick\" | \"children\"> &\n  SignRequest & {\n    /** Check the signature against the connected address after signing. */\n    verify?: boolean;\n    /** Called with the signature. */\n    onSigned?: (signature: Hex) => void;\n    /** Show the message being signed above the button. */\n    showMessage?: boolean;\n    /** Show the signature with a copy button after signing. */\n    showSignature?: boolean;\n    children?: ReactNode;\n    /**\n     * What a browser agent must ask a person before pressing the button, set\n     * as `data-agent-confirm`. Defaults to the label plus what it does. Pass\n     * `false` to drop it.\n     */\n    agentConfirm?: string | false;\n  };\n\nconst statusText: Partial<Record<SignPhase, string>> = {\n  signing: \"Sign the message in your wallet.\",\n  verifying: \"Checking the signature…\",\n  signed: \"Signed.\",\n  cancelled: \"Cancelled in wallet.\",\n};\n\n/**\n * Button that asks the wallet to sign a message or typed data. Opens the\n * wallet picker when disconnected, labels each step, and can verify and\n * show the signature.\n */\nexport function SignMessage({\n  message,\n  typedData,\n  verify = false,\n  onSigned,\n  showMessage = false,\n  showSignature = false,\n  children = \"Sign message\",\n  agentConfirm,\n  className,\n  disabled,\n  ...buttonProps\n}: SignMessageProps) {\n  const [connectOpen, setConnectOpen] = useState(false);\n  const request = (typedData ? { typedData } : { message }) as SignRequest;\n  const flow = useSignFlow(request, { verify, onSigned });\n  const busy = flow.phase === \"signing\" || flow.phase === \"verifying\";\n\n  const label = !flow.isConnected\n    ? \"Connect wallet\"\n    : flow.phase === \"signing\"\n      ? \"Sign in wallet…\"\n      : flow.phase === \"verifying\"\n        ? \"Verifying…\"\n        : flow.phase === \"signed\"\n          ? verify\n            ? \"Signature verified\"\n            : \"Signed\"\n          : children;\n\n  const preview =\n    typeof message === \"string\"\n      ? message\n      : typedData\n        ? JSON.stringify(typedData.message, (_, v) => (typeof v === \"bigint\" ? v.toString() : v), 2)\n        : undefined;\n\n  return (\n    <div\n      data-slot=\"sign-message\"\n      data-phase={flow.phase}\n      data-error={errorCode(flow.phase, flow.error)}\n      className={cn(\"inline-flex flex-col gap-2\", className)}\n    >\n      {showMessage && preview && (\n        <pre className=\"max-h-40 overflow-auto rounded-lg border bg-muted/40 p-3 text-xs whitespace-pre-wrap\">\n          {preview}\n        </pre>\n      )}\n      <Button\n        {...buttonProps}\n        disabled={disabled || busy}\n        aria-busy={busy || undefined}\n        onClick={flow.isConnected ? flow.sign : () => setConnectOpen(true)}\n        data-agent-confirm={\n          agentConfirm === false\n            ? undefined\n            : (agentConfirm ??\n              agentConfirmText(\n                children,\n                typedData\n                  ? \"signs typed data with your wallet\"\n                  : \"signs a message with your wallet\",\n              ))\n        }\n      >\n        {busy && <Loader2Icon aria-hidden className=\"animate-spin\" />}\n        {flow.phase === \"signed\" && <CheckIcon aria-hidden />}\n        <MorphText>{label}</MorphText>\n      </Button>\n      <p role=\"status\" className=\"text-sm text-muted-foreground empty:hidden\">\n        {statusText[flow.phase] ?? \"\"}\n      </p>\n      {flow.phase === \"invalid\" && (\n        <p role=\"alert\" className=\"text-sm text-destructive\">\n          The signature doesn't match the connected address.\n        </p>\n      )}\n      {flow.phase === \"error\" && flow.error && (\n        <p role=\"alert\" className=\"text-sm text-destructive\">\n          {(flow.error as { shortMessage?: string }).shortMessage ?? flow.error.message}\n        </p>\n      )}\n      {showSignature && flow.signature && (\n        <span className=\"flex items-center gap-1 font-mono text-xs text-muted-foreground\">\n          {truncateAddress(flow.signature, { start: 10, end: 8 })}\n          <CopyButton value={flow.signature} label=\"Copy signature\" />\n        </span>\n      )}\n      <ConnectWalletDialog open={connectOpen} onOpenChange={setConnectOpen} />\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/sign-message.md",
  "categories": [
    "wallet"
  ],
  "type": "registry:component"
}