Add support for encryption in WASM database bindings#7419
Open
hosseind88 wants to merge 1 commit into
Open
Conversation
Contributor
Fossier: Manual Review Requested
Score BreakdownTotal Score: 51.9/100 | Confidence: 100% | Outcome: REVIEW
|
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.
NOTICE:
Description
Fixes #5361 — improves Wasm encryption usability for browser SDK users.
Changes:
Clearer opt-in error (
core/storage/pager.rs)When encryption PRAGMAs are used without opting in at open time, the error now mentions both the CLI flag (
--experimental-encryption) and the SDK path (encryptionoption orexperimental: ['encryption']onconnect()).Wasm cipher conversion (
bindings/javascript/packages/wasm/promise-vite-dev-hack.ts,index-vite-dev-hack.ts)The Node bindings already convert string cipher names (e.g.
"aegis256") to the native enum before calling Rust. The Wasm Vite entry point did not, causing:Failed to convert napi value String into rust type i32 on EncryptionOpts.cipher.This mirrors the existing
getCipherValue()logic frompackages/native/promise.ts.Wasm crypto build (
core/Cargo.toml)Use pure-rust
aegisonwasm32(same as Android/macOS) so encryption compiles and runs in browser builds without C cross-compilation issues.Example (
examples/javascript/database-wasm-encryption-vite/)New Vite browser example showing the correct way to open an encrypted database:
Motivation and context
Reported in #5361 / Discord: a user got encryption working in the browser except when using PRAGMAs alone. The error pointed to
--experimental-encryption, which does not apply in Wasm/JS.Root causes:
encryption.cipherstrings to the Rust enum (Node already did)aegisNote: The cipher conversion is applied to the Vite dev entry point (
@tursodatabase/database-wasm/vite), which is what the new example andnpm run devuse. Other Wasm entry points (promise-default,promise-bundle,promise-turbopack-hack) could get the same treatment in a follow-up.Test plan
database-common→database-wasm-common→database-wasmexamples/javascript/database-wasm-encryption-vitewithnpm run dev— encrypted guestbook works withcipher: "aegis256"PRAGMA cipher/hexkey→ improved error messagecargo fmt/ clippy on changed Rust filesDescription of AI Usage
AI (Cursor) was used to explore the codebase, trace the issue from #5361 through the Rust pager, JS bindings, and Wasm build, and to implement the changes above. The author reproduced the bugs locally (import resolution, string→enum conversion, decryption on stale OPFS files) and validated the fix by building bindings and running the encryption example. All changes were reviewed before opening this PR.