typesecure

A focused TypeScript cryptography package that provides secure encryption and hashing utilities with strong typing and runtime validation using Zod.

https://github.com/arvid-berndtsson/typesecure

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

cryptography cybersecurity encryption hashing password security typesafe typescript zod
Last synced: 6 months ago · JSON representation ·

Repository

A focused TypeScript cryptography package that provides secure encryption and hashing utilities with strong typing and runtime validation using Zod.

Basic Info
  • Host: GitHub
  • Owner: arvid-berndtsson
  • License: mit
  • Language: TypeScript
  • Default Branch: main
  • Homepage:
  • Size: 64.5 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Topics
cryptography cybersecurity encryption hashing password security typesafe typescript zod
Created 11 months ago · Last pushed 11 months ago
Metadata Files
Readme License Citation

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>): string
  • decrypt(encryptedText: string, key: string, options?: Partial<EncryptionOptions>): string
  • generateKey(length?: number): string
  • getSecurityLevel(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>): boolean
  • timingSafeEqual(a: string, b: string, options?: Partial<TimingSafeOptions>): boolean
  • generateRandomBytes(length?: number, encoding?: 'hex' | 'base64'): string

Hashing

  • hash(input: string, options?: Partial<HashOptions>): string
  • verifyHash(input: string, hashedValue: string, options?: Partial<HashOptions>): boolean
  • hmac(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:

  1. Consulting a security professional
  2. Using specialized security libraries
  3. Keeping dependencies updated
  4. Implementing proper key management
  5. Using hardware security modules (HSMs) for key storage when possible
  6. Conducting regular security audits
  7. Following the latest NIST recommendations

Development

To contribute to this project:

  1. Clone the repository
  2. Install dependencies with pnpm install
  3. Run tests with pnpm test
  4. 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

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 1
  • Total Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Arvid Berndtsson 1****n 1

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

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 7 Last month
Rankings
Dependent repos count: 25.0%
Average: 30.5%
Dependent packages count: 36.1%
Maintainers (1)
Last synced: 7 months ago