feat(core): use @noble/ciphers/aes for mobile compat#152
Merged
andrascodes merged 1 commit intoMay 5, 2026
Merged
Conversation
This was referenced May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is part of a stack created with Aviator.
mainMake HPKE seal work in non-WebCrypto runtimes (React Native)
Summary
The OTP_V3 HPKE seal in
packages/core/src/utils/hpke.tsusedcrypto.subtle.importKey/crypto.subtle.encryptfor AES-256-GCM. ReactNative's Hermes runtime has no Web Crypto, so any RN consumer hits
Cannot read property 'importKey' of undefinedduringauth({ type: 'otp', mode: 'verifyOtp' }).This swaps the AES-GCM step for the pure-JS
gcmfrom@noble/ciphers, matching the rest of the file (already on@noble/curves+@noble/hashes).Changes
packages/core/package.json— add@noble/ciphers: ^2.2.0(aligned with the existing@noble/curves/@noble/hashesv2.2.0).packages/core/src/utils/hpke.tsgcmfrom@noble/ciphers/aes.js.aesGcmSeal(Web Crypto, async) with a one-liner overgcm(key, nonce, aad).encrypt(plaintext).toArrayBufferhelper (only existed to satisfyBufferSourcetyping forcrypto.subtle).hpkeSealP256keeps itsPromisereturn type for callsite stability, even though seal is now synchronous.Wire-format compatibility
@noble/ciphers'sgcmreturnsciphertext || tag(16-byte tag appended) — identical tocrypto.subtle.encryptwithtagLength: 128and toTurnkey's Go
Sealer.Seal. AAD shape (enc || pkR) and HPKEinfo("turnkey_hpke") are unchanged, so the sealed bundle is bit-identical tothe previous implementation.
Tests
All existing HPKE /
encryptOtpAttempttests pass unchanged (10 tests acrosshpke.test.tsandencryptOtpAttempt.test.ts), includinground-trip decryption via the reference impl — confirming byte-level compatibility with the prior Web Crypto path.
Compatibility