Skip to content

feat: add encryption helper utilities and base64 module #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025

Conversation

nullcoder
Copy link
Owner

Summary

  • Add high-level encryption utilities in lib/crypto-utils.ts for simplified gist encryption/decryption
  • Create consolidated base64 module in lib/base64.ts to eliminate redundant implementations
  • Refactor existing code to use shared utilities

What's included

Encryption Helper Utilities (crypto-utils.ts)

  • encryptGist() - High-level function to encrypt files with metadata handling
  • decryptGist() - Simplified gist decryption with key handling
  • generateShareableUrl() - Create shareable URLs with encryption keys
  • extractKeyFromUrl() - Extract keys from URL fragments
  • validateGistPin() - PIN validation for gist editing
  • createGist() - Complete gist creation with shareable URLs
  • loadGistFromUrl() - Load and decrypt gists from URLs

Base64 Module (base64.ts)

  • base64Encode/Decode - Standard base64 for internal storage
  • base64UrlEncode/Decode - URL-safe base64 for keys in URLs
  • isValidBase64() - Validation utility
  • Replaces redundant implementations in crypto.ts and auth.ts

Code Improvements

  • Updated crypto.ts to use base64 module
  • Updated auth.ts to use base64 module
  • Replaced custom generateGistId with generateShortId from id.ts
  • Added comprehensive test suites (51 new tests total)

Test plan

  • Run all tests: npm test
  • Run typecheck: npm run typecheck
  • Run linting: npm run lint
  • Verify crypto-utils tests pass (28 tests)
  • Verify base64 tests pass (23 tests)
  • Verify auth tests still pass with refactored base64

Closes #40

🤖 Generated with Claude Code

- Create crypto-utils.ts with high-level encryption functions
  - encryptGist: simplified gist encryption with metadata handling
  - decryptGist: simplified gist decryption
  - generateShareableUrl: create URLs with encryption keys
  - extractKeyFromUrl: extract keys from URL fragments
  - validateGistPin: PIN validation for gist editing
  - createGist: complete gist creation with shareable URLs
  - loadGistFromUrl: load and decrypt gists from URLs

- Add base64.ts module to consolidate encoding/decoding
  - base64Encode/Decode: standard base64 for internal storage
  - base64UrlEncode/Decode: URL-safe base64 for keys in URLs
  - isValidBase64: validation utility
  - Replaces redundant implementations in crypto.ts and auth.ts

- Refactor to use common utilities
  - Update crypto.ts to use base64 module
  - Update auth.ts to use base64 module
  - Replace custom generateGistId with generateShortId from id.ts

- Add comprehensive test suites
  - 28 tests for crypto-utils covering all functions
  - 23 tests for base64 utilities
  - Tests include edge cases, Unicode, large files

Closes #40

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@nullcoder nullcoder merged commit 14aa5e8 into main Jun 6, 2025
1 check was pending
@nullcoder nullcoder deleted the feat/encryption-helpers branch June 6, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add encryption helper utilities
1 participant