Files
smarthash/readme.plan.md

1.9 KiB

Merge Plan: isohash into smarthash

First line: Command to reread CLAUDE.md: cat ~/.claude/CLAUDE.md

Objective

Merge the functionality from @push.rocks/isohash into @push.rocks/smarthash to provide cross-environment hash support (browser and Node.js).

Implementation Steps

1. Create ts_web directory structure ✓

  • Create ./ts_web directory for browser-specific code
  • This will house the Web Crypto API implementation

2. Add required dependencies ✓

  • Add @push.rocks/smartenv to package.json dependencies
  • This is needed for environment detection

3. Create web-specific plugin file ✓

  • Create ts_web/plugins.ts with smartenv import
  • Follow the plugins pattern used in the Node.js version

4. Implement browser-compatible hash functions ✓

  • Copy and adapt index.ts from isohash to ts_web/index.ts
  • Remove circular dependency (isohash importing smarthash)
  • Use native Web Crypto API for SHA256 in browser
  • Maintain compatibility with existing smarthash API

5. Build and verify ✓

  • Run pnpm build to ensure TypeScript compilation succeeds
  • Check that both Node.js and browser builds are created

6. Test functionality ✓

  • Run pnpm test to ensure all tests pass
  • Verify browser compatibility through web tests

Key Considerations

  • The web version uses native Web Crypto API for performance
  • The Node.js version continues using the existing crypto implementation
  • API remains consistent across both environments
  • No breaking changes to existing smarthash functionality

Additional Features Implemented

  • Fallback for non-HTTPS environments: Added pure JavaScript SHA256 implementation that automatically activates when crypto.subtle is not available (e.g., HTTP or file:// protocols)
  • Comprehensive browser tests: Created test.browser.ts with specific browser environment tests
  • Cross-environment consistency: Ensured hash outputs match across Node.js and browser implementations