init
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");
|
||||
|
||||
:root {
|
||||
--font: "Inter", system-ui, -apple-system, sans-serif;
|
||||
--bg: #0a0a0f;
|
||||
--bg-card: rgba(18, 18, 26, 0.75);
|
||||
--accent-1: #6366f1;
|
||||
--accent-2: #8b5cf6;
|
||||
--gradient: linear-gradient(135deg, var(--accent-1), var(--accent-2));
|
||||
--text: #f0f0f5;
|
||||
--text-muted: #6b7280;
|
||||
--border: rgba(255, 255, 255, 0.06);
|
||||
--error: #ef4444;
|
||||
--success: #34d399;
|
||||
--radius: 16px;
|
||||
--radius-sm: 10px;
|
||||
--ease: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font);
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100dvh;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100dvh;
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
.app {
|
||||
min-height: 100dvh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.app::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, rgba(99, 102, 241, 0.12), transparent 70%);
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
pointer-events: none;
|
||||
animation: glow 6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes glow {
|
||||
0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
|
||||
50% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
|
||||
}
|
||||
|
||||
.app__container {
|
||||
width: 100%;
|
||||
max-width: 440px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* CryptoLocker form overrides */
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 40px 32px;
|
||||
box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(24px);
|
||||
animation: enter 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
|
||||
}
|
||||
|
||||
@keyframes enter {
|
||||
from { opacity: 0; transform: translateY(16px) scale(0.97); }
|
||||
to { opacity: 1; transform: translateY(0) scale(1); }
|
||||
}
|
||||
|
||||
form input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 14px 18px;
|
||||
font-family: var(--font);
|
||||
font-size: 0.95rem;
|
||||
color: var(--text);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
outline: none;
|
||||
transition: background var(--ease), border-color var(--ease), box-shadow var(--ease);
|
||||
}
|
||||
|
||||
form input[type="password"]::placeholder { color: var(--text-muted); }
|
||||
|
||||
form input[type="password"]:focus {
|
||||
background: rgba(255, 255, 255, 0.07);
|
||||
border-color: rgba(99, 102, 241, 0.5);
|
||||
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
|
||||
}
|
||||
|
||||
form p { color: var(--error); font-size: 0.85rem; text-align: center; }
|
||||
|
||||
form button {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
font-family: var(--font);
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
background: var(--gradient);
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
transition: transform var(--ease), box-shadow var(--ease);
|
||||
box-shadow: 0 4px 16px rgba(99, 102, 241, 0.25);
|
||||
}
|
||||
|
||||
form button:hover:not(:disabled) {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
|
||||
}
|
||||
|
||||
form button:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
/* Secret content */
|
||||
.secret-content {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 40px 32px;
|
||||
text-align: center;
|
||||
box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(24px);
|
||||
animation: enter 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
|
||||
}
|
||||
|
||||
.secret-content__badge {
|
||||
display: inline-block;
|
||||
padding: 5px 14px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
color: var(--success);
|
||||
background: rgba(52, 211, 153, 0.1);
|
||||
border: 1px solid rgba(52, 211, 153, 0.15);
|
||||
border-radius: 999px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.secret-content__message {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
background: var(--gradient);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import React, { useState } from "react";
|
||||
import { useCryptoLocker } from "@crypto-locker/core";
|
||||
import "./App.css";
|
||||
|
||||
// The decrypted data will be a React component type
|
||||
type SecretComponentType = React.ComponentType;
|
||||
|
||||
export default function App() {
|
||||
const { unlock, status, decryptedData: SecretComponent, error } = useCryptoLocker<SecretComponentType>();
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!password.trim()) return;
|
||||
|
||||
try {
|
||||
await unlock(() => import("./secret-content.secret"), password);
|
||||
} catch {
|
||||
// The error is already caught and managed by useCryptoLocker's state.
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<div className="app__container">
|
||||
{status === "success" && SecretComponent ? (
|
||||
<SecretComponent />
|
||||
) : (
|
||||
<form onSubmit={handleSubmit} style={{ display: "flex", flexDirection: "column", gap: "1rem", maxWidth: "300px", margin: "0 auto" }}>
|
||||
<h2>Enter Password</h2>
|
||||
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Enter password…"
|
||||
disabled={status === "loading"}
|
||||
style={{ padding: "0.5rem", fontSize: "1rem" }}
|
||||
/>
|
||||
|
||||
{error && <p style={{ color: "red", margin: 0 }}>{error}</p>}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={status === "loading" || !password.trim()}
|
||||
style={{ padding: "0.5rem 1rem", fontSize: "1rem", cursor: "pointer" }}
|
||||
>
|
||||
{status === "loading" ? "Loading…" : "Unlock"}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import App from "./App";
|
||||
|
||||
createRoot(document.getElementById("root")!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
import React from "react";
|
||||
|
||||
/**
|
||||
* Secret content — plain React Component.
|
||||
*
|
||||
* The Vite plugin 'cryptoLockerPlugin' automatically encrypts
|
||||
* this module's source code during build/dev. In the build artifacts,
|
||||
* there will be only an AES-encrypted string.
|
||||
*
|
||||
* Test password (in .env): my-super-secret-password
|
||||
*/
|
||||
export default function SecretComponent() {
|
||||
return (
|
||||
<div className="secret-content" style={{ marginTop: "1rem" }}>
|
||||
<div className="secret-content__badge" style={{ color: "green", fontWeight: "bold" }}>
|
||||
Decrypted ✓
|
||||
</div>
|
||||
<p className="secret-content__message" style={{ fontSize: "1.2rem", marginTop: "0.5rem" }}>
|
||||
Success from a React Component!
|
||||
</p>
|
||||
<ul style={{ marginTop: "1rem", textAlign: "left", display: "inline-block", color: "#555" }}>
|
||||
<li>🔐 Encrypted at build time</li>
|
||||
<li>🛡️ Decrypted and evaluated at runtime</li>
|
||||
<li>🚀 Fully functional React component</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user