typesecure
A focused TypeScript cryptography package that provides secure encryption and hashing utilities with strong typing and runtime validation using Zod.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.8%) to scientific vocabulary
Keywords
Repository
A focused TypeScript cryptography package that provides secure encryption and hashing utilities with strong typing and runtime validation using Zod.
Basic Info
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 1
Topics
Metadata Files
README.md
typesecure
A focused TypeScript cryptography package that provides secure encryption and hashing utilities with strong typing and runtime validation using Zod.
Features
- 🔐 Strong Typing: Built with TypeScript for complete type safety.
- ✅ Runtime Validation: Uses Zod to validate inputs and ensure security.
- 🔍 Advanced Encryption: AES encryption with multiple modes (CBC, CTR, GCM, ECB).
- 🛡️ Authenticated Encryption: GCM mode for authenticated encryption with additional data (AAD).
- 🔏 Cryptographic Hashing: SHA-256, SHA-512, SHA-3, and more.
- 📝 HMAC Signatures: Create and verify message authentication codes.
- ⏱️ Timing-Safe Comparison: Prevent timing attacks with constant-time string comparison.
- 🚦 Security Level Assessment: Analyze and report the security level of encryption configurations.
- 🔑 Password Hashing: PBKDF2 for secure password hashing with salt and configurable iterations.
Installation
```bash
Using npm
npm install typesecure
Using yarn
yarn add typesecure
Using pnpm
pnpm add typesecure ```
Usage
Encryption with Security Assessment
```typescript import { encrypt, decrypt, generateKey, getSecurityLevel, SecurityLevel } from 'typesecure';
// Generate a secure key const key = generateKey();
// Encrypt data with GCM (authenticated encryption) const encrypted = encrypt('Sensitive information', key, { mode: 'aes-gcm', aad: 'Additional authenticated data' // Optional });
// Decrypt data const decrypted = decrypt(encrypted, key, { mode: 'aes-gcm', aad: 'Additional authenticated data' // Must match encryption });
// Assess security level of encryption options const securityLevel = getSecurityLevel({ mode: 'aes-cbc', padding: 'Pkcs7' }); if (securityLevel === SecurityLevel.HIGH) { console.log('Using high security encryption configuration'); } ```
Secure Password Storage
```typescript import { hashPassword, verifyPassword } from 'typesecure';
// Hash a password with PBKDF2 const { hash, salt, params } = hashPassword('userPassword123', { algorithm: 'pbkdf2', iterations: 10000, saltLength: 32, keyLength: 64 });
// Store hash, salt, and params in your database
// Later, verify the password const isValid = verifyPassword('userPassword123', hash, salt, params); ```
Timing-Safe Comparison and Random Bytes Generation
```typescript import { timingSafeEqual, generateRandomBytes } from 'typesecure';
// Compare strings in constant time to prevent timing attacks const isEqual = timingSafeEqual(userProvidedToken, storedToken);
// Generate cryptographically secure random bytes const randomBytes = generateRandomBytes(32, 'hex'); ```
Hashing and HMAC
```typescript import { hash, verifyHash, hmac } from 'typesecure';
// Create a hash const hashedValue = hash('data to hash', { algorithm: 'sha256', encoding: 'hex' });
// Verify a hash const isMatch = verifyHash('data to hash', hashedValue, { algorithm: 'sha256', encoding: 'hex' });
// Create an HMAC const signature = hmac('message', 'secret key', { algorithm: 'sha256', encoding: 'base64' }); ```
API Reference
Encryption
encrypt(text: string, key: string, options?: Partial<EncryptionOptions>): stringdecrypt(encryptedText: string, key: string, options?: Partial<EncryptionOptions>): stringgenerateKey(length?: number): stringgetSecurityLevel(options: EncryptionOptions): SecurityLevel
Secure Password Storage
hashPassword(password: string, options?: Partial<PasswordHashOptions>): { hash: string; salt: string; params: PasswordHashOptions }verifyPassword(password: string, hash: string, salt: string, options?: Partial<PasswordHashOptions>): booleantimingSafeEqual(a: string, b: string, options?: Partial<TimingSafeOptions>): booleangenerateRandomBytes(length?: number, encoding?: 'hex' | 'base64'): string
Hashing
hash(input: string, options?: Partial<HashOptions>): stringverifyHash(input: string, hashedValue: string, options?: Partial<HashOptions>): booleanhmac(input: string, key: string, options?: Partial<HashOptions>): string
Security Considerations
This package implements best practices for cryptographic operations, but remember that cryptography is complex. For production applications with high security requirements, consider:
- Consulting a security professional
- Using specialized security libraries
- Keeping dependencies updated
- Implementing proper key management
- Using hardware security modules (HSMs) for key storage when possible
- Conducting regular security audits
- Following the latest NIST recommendations
Development
To contribute to this project:
- Clone the repository
- Install dependencies with
pnpm install - Run tests with
pnpm test - Build the package with
pnpm build
This project uses TypeScript for type safety, Jest for testing, and ESLint for code quality.
License
MIT © Arvid Berndtsson
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
title: "typesecure"
abstract: "A comprehensive collection of essential cybersecurity utilities for Node.js applications with strong typing and runtime validation using TypeScript and Zod."
type: software
authors:
- family-names: "Berndtsson"
given-names: "Arvid"
repository-code: "https://github.com/arvid-berndtsson/typesecure"
url: "https://github.com/arvid-berndtsson/typesecure"
license: MIT
version: 0.1.0
date-released: 2025-04-22
keywords:
- cybersecurity
- encryption
- hashing
- password-security
- typescript
- zod
- crypto
- authentication
- aes
- sha
- pbkdf2
- hmac
- timing-attack-prevention
GitHub Events
Total
- Release event: 1
- Push event: 4
- Create event: 3
Last Year
- Release event: 1
- Push event: 4
- Create event: 3
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- npm 7 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
- Total maintainers: 1
npmjs.org: typesecure
A comprehensive collection of essential cybersecurity utilities with strong typing and runtime validation
- Homepage: https://github.com/arvid-berndtsson/typesecure#readme
- License: MIT
-
Latest release: 0.1.0
published 11 months ago