TailwindCrypto
Why import crypto when you can write classes?
className your way to cryptographic utilities!
React Server ComponentsUUIDs + HashingRandom GenerationEncoding
<Crypto className="crypto-uuid" />renders
6eaa093d-95b0-4b29-a617-2b8f6694e10d
Syntax Reference
<Crypto className="crypto-{operation}[-options...]" [data="..."] />crypto-uuidUUID v4/v7
crypto-nanoid-12Nano ID
crypto-hashSHA-256/512
crypto-randomRandom bytes
crypto-tokenAlphanumeric
crypto-otp-6OTP codes
UUID Generation
Hashing
Random Generation
Encoding
Checksums
Conditionals
Class Reference
| Class | Description |
|---|---|
crypto-uuid | UUID v4 (random) |
crypto-uuid-v7 | UUID v7 (timestamp-sortable) |
crypto-nanoid | Nano ID (21 chars) |
crypto-nanoid-{n} | Nano ID with custom length |
crypto-hash | SHA-256 hash (requires data prop) |
crypto-hash-{algo} | Hash with algorithm (sha256, sha512, md5) |
crypto-hash-{algo}-truncate-{n} | Truncated hash |
crypto-hmac-{algo} | HMAC (requires data + secretKey props) |
crypto-random | 32 random bytes (hex) |
crypto-random-{n} | N random bytes (hex) |
crypto-random-{n}-base64 | Random bytes as base64 |
crypto-token-{n} | Alphanumeric token |
crypto-otp-{n} | Numeric OTP code |
crypto-base64-encode | Base64 encode (requires data prop) |
crypto-base64-decode | Base64 decode (requires data prop) |
crypto-hex-encode | Hex encode (requires data prop) |
crypto-hex-decode | Hex decode (requires data prop) |
crypto-url-encode | URL encode (requires data prop) |
crypto-crc32 | CRC32 checksum (requires data prop) |
if-crypto-uuid | Conditional: valid UUID (requires value prop) |
if-not-crypto-uuid | Conditional: invalid UUID (requires value prop) |
if-crypto-hash-match | Conditional: hash matches (requires data + expected) |
How to Use
// tailwind-crypto.config.tsimport type { CryptoUserConfig } from '@tailwind-stack/crypto'export default { uuidVersion: 'v4', hashAlgorithm: 'sha256', mock: false,} satisfies CryptoUserConfig// lib/crypto-config.tsimport { setConfig } from '@tailwind-stack/crypto'import cryptoConfig from '../tailwind-crypto.config'setConfig(cryptoConfig)// In your componentimport '@/lib/crypto-config'import { Crypto } from '@tailwind-stack/crypto'<Crypto className="crypto-uuid" />Helper Functions
Use in Server Actions or server-side code:
import { uuid, hash, token, otp } from '@tailwind-stack/crypto'async function createUser(formData: FormData) { 'use server' const id = uuid() // → '550e8400-...' const id7 = uuid('v7') // → '018f3b3c-...' const hashed = hash(password, 'sha256') const apiKey = token(32) const code = otp(6) // → '847293'}