Skip to content

webcrypto implementation#933

Draft
rm-hull wants to merge 18 commits into
mainfrom
feat/webcrypto
Draft

webcrypto implementation#933
rm-hull wants to merge 18 commits into
mainfrom
feat/webcrypto

Conversation

@rm-hull
Copy link
Copy Markdown
Owner

@rm-hull rm-hull commented Nov 1, 2025

No description provided.

This commit replaces the custom `useLocalStorage` implementation
with the `@rm-hull/use-local-storage` package.

This migration allows for better management of serialization logic
directly within the hook implementation.

Key changes:

*   The `useGeneralSettings` hook now returns an object
    `{ settings, updateSettings }` instead of an array.
*   The `useOtpParameters` hook utilizes the library's `Serializer`
    interface to handle password-based encryption and decryption
    of stored OTP data.
*   Components consuming these hooks have been updated to use
    object destructuring instead of array destructuring.
Ensures that if `CryptoJS.AES.decrypt` fails (e.g., due to a bad
password), we throw an explicit error message rather than relying
on subsequent JSON parsing failure.
Exposes the `isLoading` status from `useLocalStorage` via
`useOtpParameters` to allow consumer components to handle
initial data hydration states properly.

Also integrates the global `Toaster` component for displaying
notifications across the application.
Extract `Encrypter` logic into `CryptoJsSerializer` to clean up the
`useOtpParameters` hook.

This commit also introduces the `WebCryptoSerializer` utility which
provides functions to decrypt data originally encrypted by CryptoJS
using the browser's native `window.crypto` methods (AES-CBC +
EVP_BytesToKey derivation).

This prepares the codebase for potentially migrating away from
`crypto-js`.
…storage

* 'main' of github.com:rm-hull/zaup2:
  refactor: Improve alert structure and data flow (#931)
Introduces robust error handling for data retrieval and decryption:

*   Displays an error toast notification if the OTP data fails to load
    in the UI (`Group.tsx`).
*   Catches decryption/parsing failures in `CryptoJsSerializer` and
    throws an error that includes the original exception as the cause,
    improving debugging capabilities.
Refactors the `WebCryptoSerializer` to track password verification
status.

- Serialization is blocked if the password previously failed
  decryption checks.
- Decryption failures now set the internal bad password state and
  throw a richer error.

Also, removed local error handling (toasting) in `<Group />` component
to ensure data loading errors are propagated via `throw error;` for
centralized error boundary management.
* 'main' of github.com:rm-hull/zaup2:
  chore: Update chakra-error-fallback dependency
  chore: Extract ErrorFallback to external lib
  refactor: Use standard `use-local-storage` hook (#930)
  feat: Enhance error fallback with source maps (#932)
  refactor(Redirect): Condense logic and return null
@coveralls
Copy link
Copy Markdown

coveralls commented Nov 2, 2025

Pull Request Test Coverage Report for Build 19556472648

Details

  • 52 of 59 (88.14%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+20.1%) to 22.546%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/utils/serializer/webcrypto-serializer.ts 52 59 88.14%
Totals Coverage Status
Change from base Build 19555777314: 20.1%
Covered Lines: 974
Relevant Lines: 4457

💛 - Coveralls

Replaces the usage of `CryptoJsSerializer` with the
`WebCryptoSerializer` within `useOtpParameters`.

This switches serialization logic to use the browser's native
Web Crypto API instead of the external CryptoJS library.
* 'main' of github.com:rm-hull/zaup2:
  chore: update yarn
Refactors the `evpBytesToKey` function in the WebCrypto serializer
to use synchronous MD5 hashing via CryptoJS internally. This ensures
key and IV derivation is identical to the standard OpenSSL
EVP_BytesToKey derivation used by CryptoJS, guaranteeing full
compatibility between both serializer implementations.

Adds comprehensive compatibility tests to verify bidirectional
serialization and deserialization between the two serializers.

The testing workflow is updated:
*   `test` now runs tests once (`vitest run`).
*   `test:watch` is introduced for watch mode (`vitest`).
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.

2 participants