Skip to content

feat(hkdf): implement HKDF with WebCrypto support and native C++ backend#848

Merged
boorad merged 9 commits into
margelo:mainfrom
athexweb3:main
Dec 7, 2025
Merged

feat(hkdf): implement HKDF with WebCrypto support and native C++ backend#848
boorad merged 9 commits into
margelo:mainfrom
athexweb3:main

Conversation

@athexweb3

@athexweb3 athexweb3 commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

PR: HKDF Implementation & Runtime Stability Fixes

Summary

This PR implements full HKDF support (WebCrypto & Native) and resolves critical runtime crashes in the example app. It also restores the original UI appearance by replacing incompatible dependencies.

✨ Features

  • Native HKDF Implementation: Added C++ backend for HKDF using OpenSSL, exposed via Nitro Modules.
  • WebCrypto Support: Integrated HKDF into subtle.crypto.deriveKey and subtle.crypto.deriveBits.
  • TypeScript & JSI: Added strict TypeScript definitions (HkdfAlgorithm, CryptoKeyInternal) and JSI bindings.

📊 Implementation Results

  • Tests: 4 of 4 tests pass.
  • 🚀 Performance: 86.86x benchmark result

🐛 Bugs Fixed & Solutions

1. Runtime Crash: TypeError: property is not writable

  • Issue: The global polyfill for process.version and process.nextTick was attempting to overwrite read-only properties in strict mode or specific environments.
  • Fix: Implemented safe property definition using Object.defineProperty with checks to prevent overwriting existing read-only properties in src/index.ts.

2. UI Crash: TypeError: Cannot read property 'default' of undefined

  • Issue: react-native-bouncy-checkbox causing immediate crashes on render.
  • Fix: Removed the dependency and implemented a lightweight, custom Checkbox component (example/src/components/Checkbox.tsx) using react-native-vector-icons. This restores the original look and feel without the stability issues.

🧪 Verification

  • HKDF Tests: All unit tests for HKDF pass.
  • Example App: Runs crash-free on iOS/Android.
  • UI: Checkboxes toggle correctly and match the previous design.
  • Lint: bun lint passes with no errors.

Includes:
- Native HKDF implementation (C++, Nitro, Android/iOS)
- WebCrypto HKDF integration in subtle.ts
- UI Fix: Custom Checkbox component replacing Switch
- iOS Fix: Update REACT_NATIVE_PATH in project.pbxproj
@athexweb3

Copy link
Copy Markdown
Contributor Author

@boorad need a quick review. Also noticed something weird — every time I run the iOS app, Xcode auto-changes the pod path from ../../ to ../

@boorad boorad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few comments

Comment thread example/src/components/BenchmarkItem.tsx Outdated
Comment thread example/index.ts
Comment thread packages/react-native-quick-crypto/src/hkdf.ts Outdated
Comment thread packages/react-native-quick-crypto/src/index.ts

@boorad boorad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple more, pretty close 🚀

Comment thread example/package.json
Comment thread packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.cpp Outdated
@athexweb3 athexweb3 requested a review from boorad December 7, 2025 03:55

@boorad boorad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot one, about your XCode issue.

Also, why are the tests failing? You can look in the actions and download build logs for the e2e tests.

Comment thread example/ios/QuickCryptoExample.xcodeproj/project.pbxproj Outdated
Comment thread example/ios/QuickCryptoExample.xcodeproj/project.pbxproj
@athexweb3 athexweb3 requested a review from boorad December 7, 2025 05:35

@boorad boorad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LFG!!

@boorad boorad merged commit 120d9ca into margelo:main Dec 7, 2025
7 checks passed
@boorad boorad mentioned this pull request Dec 7, 2025
2 tasks
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