Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update Rust bindings (#2159)
Leendert de Borstc7b682eb193d
diff --git a/core/rust/Cargo.toml b/core/rust/Cargo.tomlindex 4716f8205..8d167e68b 100644--- a/core/rust/Cargo.toml+++ b/core/rust/Cargo.toml@@ -51,7 +51,7 @@ argon2 = "0.5"# AES-256-GCM (vault blobs, key wrapping) and RSA-OAEP-SHA256 (manifest key grants)aes-gcm = "0.10"rsa = "0.9"-rand_core06 = { package = "rand_core", version = "0.6" }+rand_core06 = { package = "rand_core", version = "0.6", features = ["getrandom"] }# Wipes key material from memory on dropzeroize = { version = "1.8", features = ["derive"] }diff --git a/core/rust/README.md b/core/rust/README.mdindex 41c668f3d..1e081d0cf 100644--- a/core/rust/README.md+++ b/core/rust/README.md@@ -4,43 +4,17 @@ Cross-platform core library providing shared business logic for all AliasVault c- **Browser Extensions** (Chrome, Firefox, Edge, Safari via WASM)- **Mobile Apps** (iOS via Swift bindings, Android via Kotlin bindings)-- **Server** (.NET via P/Invoke - currently only scaffolding, not actively used)+- **Server** (.NET via P/Invoke - prepared, not yet consumed by current API version)-## Architecture+## Core Modules-```-┌─────────────────────────────────────────────────────────────────────────┐-│ Rust Core Library │-│ │-│ src/ │-│ ├── lib.rs Entry point, module exports │-│ ├── error.rs VaultError type │-│ ├── vault_merge/ LWW merge algorithm │-│ ├── vault_pruner/ Trash retention cleanup │-│ └── credential_matcher/ Autofill filtering │-│ │-│ Platform Interfaces: │-│ ├── wasm.rs WASM bindings (#[wasm_bindgen]) │-│ ├── uniffi_api.rs UniFFI bindings (#[uniffi::export]) │-│ └── ffi.rs C FFI for .NET (extern "C") │-└─────────────────────────────────────────────────────────────────────────┘- │- ┌──────────────────────────┼──────────────────────────┐- │ │ │- ▼ ▼ ▼-┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐-│ WASM Module │ │ UniFFI (FFI) │ │ C FFI (.NET) │-│ wasm-bindgen │ │ Swift + Kotlin │ │ P/Invoke │-└────────┬────────┘ └────────┬────────┘ └────────┬────────┘- │ │ │- ▼ ▼ ▼-┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐-│ Browser │ │ iOS & Android │ │ Server │-│ Extensions │ │ Mobile Apps │ │ (.NET) │-└─────────────────┘ └─────────────────┘ └─────────────────┘-```+### vault_model+The client vault datamodel registry (tables, keys, scoping, bucket layout), generated from+`core/models/src/vault/VaultTableRegistry.ts`.-## Core Modules+### vault_codec+The manifest-v1 storage format: canonicalize the local SQLite tables into manifests, data buckets and+content-addressed blobs, and materialize them back.### vault_mergeLast-Write-Wins (LWW) merge of a local vault onto the server's, one manifest at a time, rows out.@@ -77,318 +51,3 @@ cargo test # All testscargo test vault_merge # Specific modulecargo test --features uniffi # With UniFFI enabled```-------# Developer Guide--This section documents the interface structure and how to add new functionality.--## Interface Overview--The Rust core exposes functions through three interface files, each targeting different platforms:--| Interface | File | Platforms | Attribute |-|-----------|------|-----------|-----------|-| WASM | `src/wasm.rs` | Browser extensions | `#[wasm_bindgen]` |-| UniFFI | `src/uniffi_api.rs` | iOS, Android | `#[uniffi::export]` |-| C FFI | `src/ffi.rs` | .NET Server | `#[no_mangle] extern "C"` |--All interfaces follow a JSON-in/JSON-out pattern for simplicity. Each platform handles its own database I/O and passes data as JSON to Rust.--## Current Exported Functions--| Function | WASM | UniFFI | C FFI | Description |-|----------|------|--------|-------|-------------|-| `getSyncableTableNames` | ✓ | ✓ | ✓ | Returns list of syncable table names |-| `mergeCanonical` / `mergeCanonicalJson` | ✓ | ✓ (JSON only) | - | LWW merge of local + server manifests |-| `pruneVault` / `pruneVaultJson` | ✓ | ✓ (JSON only) | ✓ | Remove expired trash items |-| `filterCredentials` / `filterCredentialsJson` | ✓ | ✓ (JSON only) | ✓ | Credential matching for autofill |-| `extractDomain` | ✓ | ✓ | - | Extract domain from URL |-| `extractRootDomain` | ✓ | ✓ | - | Extract root domain (handles .co.uk etc) |--## Adding a New Function--When adding a new module or function to the Rust core, you need to update multiple files. Follow this checklist:--### 1. Implement the Core Logic--Create or update a module in `src/`:--```rust-// src/my_module/mod.rs--use serde::{Deserialize, Serialize};-use crate::error::VaultResult;--#[derive(Serialize, Deserialize)]-pub struct MyInput {- pub data: String,-}--#[derive(Serialize, Deserialize)]-pub struct MyOutput {- pub result: String,-}--/// Core function with typed input/output.-pub fn my_function(input: MyInput) -> VaultResult<MyOutput> {- // Implementation- Ok(MyOutput { result: input.data })-}--/// JSON wrapper for cross-platform convenience.-pub fn my_function_json(input_json: &str) -> VaultResult<String> {- let input: MyInput = serde_json::from_str(input_json)?;- let output = my_function(input)?;- Ok(serde_json::to_string(&output)?)-}-```--### 2. Export from lib.rs--```rust-// src/lib.rs--pub mod my_module;-pub use my_module::{my_function, MyInput, MyOutput};-```--### 3. Add WASM Bindings (src/wasm.rs)--```rust-use crate::my_module::{my_function, MyInput, MyOutput};--/// Typed API - accepts/returns JsValue.-#[wasm_bindgen(js_name = myFunction)]-pub fn my_function_js(input: JsValue) -> Result<JsValue, JsValue> {- let input: MyInput = serde_wasm_bindgen::from_value(input)- .map_err(|e| JsValue::from_str(&format!("Failed to parse input: {}", e)))?;-- let output: MyOutput = my_function(input)- .map_err(|e| JsValue::from_str(&format!("Failed: {}", e)))?;-- serde_wasm_bindgen::to_value(&output)- .map_err(|e| JsValue::from_str(&format!("Failed to serialize: {}", e)))-}--/// JSON API - accepts/returns strings.-#[wasm_bindgen(js_name = myFunctionJson)]-pub fn my_function_json_js(input_json: &str) -> Result<String, JsValue> {- crate::my_module::my_function_json(input_json)- .map_err(|e| JsValue::from_str(&format!("Failed: {}", e)))-}-```--### 4. Add UniFFI Bindings (src/uniffi_api.rs)--```rust-use crate::error::VaultError;--/// JSON API only - UniFFI handles type conversion automatically.-#[uniffi::export]-pub fn my_function_json(input_json: String) -> Result<String, VaultError> {- crate::my_module::my_function_json(&input_json)-}-```--### 5. Add C FFI Bindings (src/ffi.rs) - If Needed for .NET--```rust-/// C-compatible function for .NET P/Invoke.-///-/// # Safety-/// - `input_json` must be a valid null-terminated C string-/// - Returned pointer must be freed with `free_string()`-#[no_mangle]-pub unsafe extern "C" fn my_function_ffi(input_json: *const c_char) -> *mut c_char {- if input_json.is_null() {- return ptr::null_mut();- }-- let c_str = match CStr::from_ptr(input_json).to_str() {- Ok(s) => s,- Err(_) => return ptr::null_mut(),- };-- let input: MyInput = match serde_json::from_str(c_str) {- Ok(i) => i,- Err(e) => return create_error_response(&format!("Parse failed: {}", e)),- };-- let output = match my_function(input) {- Ok(o) => o,- Err(e) => return create_error_response(&format!("Failed: {}", e)),- };-- match serde_json::to_string(&output) {- Ok(json) => string_to_c_char(json),- Err(e) => create_error_response(&format!("Serialize failed: {}", e)),- }-}-```--### 6. Update Cargo.toml Features (If Needed)--If your module requires additional dependencies, ensure they're properly feature-gated:--```toml-[features]-wasm = ["dep:wasm-bindgen", "dep:serde-wasm-bindgen"]-uniffi = ["dep:uniffi"]-ffi = []--[dependencies]-my-new-dep = { version = "1.0", optional = true }-```--### 7. Add Tests--```rust-// In src/my_module/mod.rs or src/my_module/tests.rs--#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn test_my_function() {- let input = MyInput { data: "test".to_string() };- let output = my_function(input).unwrap();- assert_eq!(output.result, "test");- }-- #[test]- fn test_my_function_json() {- let input = r#"{"data": "test"}"#;- let output = my_function_json(input).unwrap();- assert!(output.contains("test"));- }-}-```--### 8. Build and Distribute--```bash-# Build for all targets you support-./build.sh --browser --ios --android--# Or just the ones you need during development-./build.sh --browser-```--## Platform Consumption--After building, the outputs are distributed to:--| Platform | Output Location | Files |-|----------|----------------|-------|-| Browser Extension | `core/client/wasm/` | `aliasvault_core.js`, `.wasm`, `.d.ts` |-| Blazor WASM | `apps/server/AliasVault.Client/wwwroot/wasm/` | `aliasvault_core.js`, `.wasm` |-| iOS | `apps/mobile-app/ios/VaultStoreKit/RustCore/` | `.a`, `.h`, `.swift` |-| Android | `apps/mobile-app/android/app/src/main/jniLibs/` | `.so` per ABI + `.kt` |--### Browser Extension Usage--```typescript-import init, { myFunction, myFunctionJson } from '@/utils/dist/core/rust/aliasvault_core.js';--// Initialize once-await init(wasmBytes);--// Typed API-const result = myFunction({ data: "test" });--// JSON API-const jsonResult = myFunctionJson('{"data": "test"}');-```--### iOS Usage (Swift)--```swift-// Generated UniFFI bindings in aliasvault_core.swift-let result = try myFunctionJson(inputJson: jsonString)-```--### Android Usage (Kotlin)--```kotlin-// Generated UniFFI bindings-val result = uniffi.aliasvault_core.myFunctionJson(jsonString)-```--## Design Decisions--### JSON-First Communication--All interfaces use JSON strings for input/output. This simplifies:-- Cross-language type marshalling-- Debugging (human-readable)-- Consistency across platforms--For WASM, we also provide typed APIs using `serde-wasm-bindgen` for better TypeScript integration.--### Feature Flags--| Feature | Purpose | Used By |-|---------|---------|---------|-| `uniffi` | UniFFI runtime support | iOS/Android builds |-| `uniffi-cli` | UniFFI binding generator | Build script only |-| `wasm` | WASM + JS interop | Browser extension |-| `ffi` | C-compatible exports | .NET server |--Use `uniffi` (not `uniffi-cli`) for library builds to avoid pulling in heavy bindgen dependencies.--### Error Handling--Use `VaultError` from `src/error.rs` for all errors:--```rust-use crate::error::{VaultError, VaultResult};--pub fn my_function() -> VaultResult<String> {- // serde errors auto-convert via From impl- let data: MyType = serde_json::from_str(json)?;-- // Manual error creation- if data.invalid {- return Err(VaultError::General("Invalid data".to_string()));- }-- Ok("success".to_string())-}-```--## File Reference--| File | Purpose |-|------|---------|-| `src/lib.rs` | Entry point, exports all modules |-| `src/error.rs` | `VaultError` and `VaultResult` types |-| `src/vault_merge/mod.rs` | The record type, SQL statement shape and LWW primitives the merge and the pruner share |-| `src/vault_merge/canonical.rs` | LWW merge implementation (manifests in, rows out) |-| `src/vault_merge/types.rs` | Re-exports the table registry for merge call sites |-| `src/vault_model/mod.rs` | `TableConfig` type; owns the generated registry data |-| `src/vault_model/generated.rs` | Registry data generated from `core/models/src/vault/VaultTableRegistry.ts` (do not edit) |-| `src/vault_pruner/mod.rs` | Trash cleanup implementation |-| `src/credential_matcher/mod.rs` | Autofill filtering algorithm |-| `src/credential_matcher/domain.rs` | URL/domain extraction utilities |-| `src/credential_matcher/stop_words.rs` | Text filtering for service name matching |-| `src/password_generator/mod.rs` | Password/passphrase generation |-| `src/password_generator/wordlists/` | Embedded Diceware wordlists |-| `src/identity_generator/mod.rs` | Identity (alias persona) generation |-| `src/identity_generator/username_email.rs` | Username and email prefix derivation |-| `src/identity_generator/dictionaries/` | Embedded per-language name dictionaries |-| `src/crypto/mod.rs` | Crypto module root; shared CSPRNG helper |-| `src/crypto/argon2.rs` | Argon2id key derivation (master password to KEK) |-| `src/crypto/key_chain.rs` | Account key hierarchy: KEK wraps the Account Key, which wraps the vault key and private key |-| `src/crypto/aes_gcm.rs` | AES-256-GCM encryption, WebCrypto byte-compatible |-| `src/crypto/rsa_oaep.rs` | RSA-OAEP-SHA256 encryption and JWK key pair generation |-| `src/crypto/srp.rs` | SRP-6a login handshake (client and server sides) |-| `src/rng.rs` | Shared RNG helpers (seeding, unbiased sampling) |-| `src/wasm.rs` | WASM bindings (browser) |-| `src/uniffi_api.rs` | UniFFI bindings (iOS/Android) |-| `src/ffi.rs` | C FFI bindings (.NET) |-| `uniffi-bindgen.rs` | UniFFI CLI binary entry point |-| `build.sh` | Multi-platform build script |-| `Cargo.toml` | Dependencies and feature flags |\ No newline at end of filediff --git a/core/rust/src/wasm.rs b/core/rust/src/wasm.rsindex 24d9e5601..7f111e566 100644--- a/core/rust/src/wasm.rs+++ b/core/rust/src/wasm.rs@@ -10,7 +10,7 @@ use crate::password_generator::{available_languages, generate_password};use crate::vault_codec::{self, CanonicalizeInput, DataBucket, ExtractBucketsInput, Manifest, MaterializeInput,};-use crate::vault_merge::{merge_canonical, merge_vaults, CanonicalMergeInput, CanonicalMergeOutput, MergeInput, MergeOutput};+use crate::vault_merge::{merge_canonical, CanonicalMergeInput, CanonicalMergeOutput};use crate::vault_sharing::{self, ManifestAccessRequest, ManifestWriteSetRequest};use crate::vault_pruner::{prune_vault, PruneInput, PruneOutput};@@ -40,35 +40,10 @@ pub fn get_core_version_js() -> String {// Vault Merge WASM Bindings// ═══════════════════════════════════════════════════════════════════════════════-/// Get the list of syncable table names a platform must read into the merge input.+/// Get the list of table names that take part in a vault sync.#[wasm_bindgen(js_name = getSyncableTableNames)]-pub fn get_syncable_table_names() -> Vec<String> {- crate::vault_merge::merge_table_names().iter().map(|s| s.to_string()).collect()-}--/// Merge vaults using LWW strategy.-///-/// Takes a JsValue (MergeInput) and returns a JsValue (MergeOutput). Serialized via `codec_to_js`-/// so `{ __b64 }` byte params survive as plain objects (the default serializer would render them-/// as JS Maps) and null params reach sql.js as null.-#[wasm_bindgen(js_name = mergeVaults)]-pub fn merge_vaults_js(input: JsValue) -> Result<JsValue, JsValue> {- let input: MergeInput = serde_wasm_bindgen::from_value(input)- .map_err(|e| JsValue::from_str(&format!("Failed to parse input: {}", e)))?;-- let output: MergeOutput = merge_vaults(input)- .map_err(|e| JsValue::from_str(&format!("Merge failed: {}", e)))?;-- codec_to_js(&output)-}--/// Merge vaults using JSON strings (alternative API).-///-/// Takes a JSON string and returns a JSON string.-#[wasm_bindgen(js_name = mergeVaultsJson)]-pub fn merge_vaults_json_js(input_json: &str) -> Result<String, JsValue> {- crate::vault_merge::merge_vaults_json(input_json)- .map_err(|e| JsValue::from_str(&format!("Merge failed: {}", e)))+pub fn get_syncable_table_names_js() -> Vec<String> {+ crate::vault_model::SYNCABLE_TABLE_NAMES.iter().map(|s| s.to_string()).collect()}/// Merge the local canonical vault onto the server canonical vault (manifest-v1 format).@@ -113,8 +88,7 @@ pub fn prune_vault_js(input: JsValue) -> Result<JsValue, JsValue> {/// Takes a JSON string and returns a JSON string.#[wasm_bindgen(js_name = pruneVaultJson)]pub fn prune_vault_json_js(input_json: &str) -> Result<String, JsValue> {- crate::vault_pruner::prune_vault_json(input_json)- .map_err(|e| JsValue::from_str(&format!("Prune failed: {}", e)))+ crate::error::json_call(input_json, prune_vault).map_err(|e| JsValue::from_str(&format!("Prune failed: {}", e)))}/// Get the per-table SELECT queries used to build prune input.@@ -320,8 +294,7 @@ pub fn filter_credentials_js(input: JsValue) -> Result<JsValue, JsValue> {/// Takes a JSON string and returns a JSON string.#[wasm_bindgen(js_name = filterCredentialsJson)]pub fn filter_credentials_json_js(input_json: &str) -> Result<String, JsValue> {- crate::credential_matcher::filter_credentials_json(input_json)- .map_err(|e| JsValue::from_str(&e))+ crate::credential_matcher::filter_credentials_json(input_json).map_err(|e| JsValue::from_str(&e.to_string()))}/// Extract domain from URL.@@ -484,7 +457,7 @@ pub fn get_identity_age_ranges_js() -> Vec<String> {/// The derived key as 32 bytes#[wasm_bindgen(js_name = argon2DeriveKey)]pub fn argon2_derive_key_js(password: &str, salt: &str, encryption_settings: &str) -> Result<Vec<u8>, JsValue> {- crate::argon2::argon2_derive_key_from_settings(password, salt, encryption_settings)+ crate::crypto::argon2::argon2_derive_key_from_settings(password, salt, encryption_settings).map_err(|e| JsValue::from_str(&format!("Argon2 error: {}", e)))}@@ -496,7 +469,7 @@ pub fn argon2_derive_key_js(password: &str, salt: &str, encryption_settings: &st/// Returns a 32-byte random salt as an uppercase hex string.#[wasm_bindgen(js_name = srpGenerateSalt)]pub fn srp_generate_salt_js() -> String {- crate::srp::srp_generate_salt()+ crate::crypto::srp::srp_generate_salt()}/// Derive the SRP private key (x) from credentials.@@ -514,7 +487,7 @@ pub fn srp_derive_private_key_js(identity: &str,password_hash: &str,) -> Result<String, JsValue> {- crate::srp::srp_derive_private_key(salt, identity, password_hash)+ crate::crypto::srp::srp_derive_private_key(salt, identity, password_hash).map_err(|e| JsValue::from_str(&format!("SRP error: {}", e)))}@@ -527,7 +500,7 @@ pub fn srp_derive_private_key_js(/// Verifier as uppercase hex string (for registration)#[wasm_bindgen(js_name = srpDeriveVerifier)]pub fn srp_derive_verifier_js(private_key: &str) -> Result<String, JsValue> {- crate::srp::srp_derive_verifier(private_key)+ crate::crypto::srp::srp_derive_verifier(private_key).map_err(|e| JsValue::from_str(&format!("SRP error: {}", e)))}@@ -535,7 +508,7 @@ pub fn srp_derive_verifier_js(private_key: &str) -> Result<String, JsValue> {/// Returns a JsValue object with `public` and `secret` properties (uppercase hex strings).#[wasm_bindgen(js_name = srpGenerateEphemeral)]pub fn srp_generate_ephemeral_js() -> Result<JsValue, JsValue> {- let ephemeral = crate::srp::srp_generate_ephemeral();+ let ephemeral = crate::crypto::srp::srp_generate_ephemeral();serde_wasm_bindgen::to_value(&ephemeral).map_err(|e| JsValue::from_str(&format!("Failed to serialize ephemeral: {}", e)))}@@ -559,7 +532,7 @@ pub fn srp_derive_session_js(identity: &str,private_key: &str,) -> Result<JsValue, JsValue> {- let session = crate::srp::srp_derive_session(client_secret, server_public, salt, identity, private_key)+ let session = crate::crypto::srp::srp_derive_session(client_secret, server_public, salt, identity, private_key).map_err(|e| JsValue::from_str(&format!("SRP error: {}", e)))?;serde_wasm_bindgen::to_value(&session).map_err(|e| JsValue::from_str(&format!("Failed to serialize session: {}", e)))@@ -574,7 +547,7 @@ pub fn srp_derive_session_js(/// JsValue object with `public` and `secret` properties (uppercase hex strings)#[wasm_bindgen(js_name = srpGenerateEphemeralServer)]pub fn srp_generate_ephemeral_server_js(verifier: &str) -> Result<JsValue, JsValue> {- let ephemeral = crate::srp::srp_generate_ephemeral_server(verifier)+ let ephemeral = crate::crypto::srp::srp_generate_ephemeral_server(verifier).map_err(|e| JsValue::from_str(&format!("SRP error: {}", e)))?;serde_wasm_bindgen::to_value(&ephemeral).map_err(|e| JsValue::from_str(&format!("Failed to serialize ephemeral: {}", e)))@@ -601,7 +574,7 @@ pub fn srp_derive_session_server_js(verifier: &str,client_proof: &str,) -> Result<JsValue, JsValue> {- let session = crate::srp::srp_derive_session_server(+ let session = crate::crypto::srp::srp_derive_session_server(server_secret,client_public,salt,@@ -631,12 +604,79 @@ pub fn srp_derive_session_server_js(/// # Returns/// True if verification succeeds, false otherwise#[wasm_bindgen(js_name = srpVerifySession)]-pub fn srp_verify_session_wasm(+pub fn srp_verify_session_js(client_public: &str,client_proof: &str,session_key: &str,server_proof: &str,) -> Result<bool, JsValue> {- crate::srp::srp_verify_session(client_public, client_proof, session_key, server_proof)+ crate::crypto::srp::srp_verify_session(client_public, client_proof, session_key, server_proof).map_err(|e| JsValue::from_str(&format!("SRP error: {}", e)))}++// ═══════════════════════════════════════════════════════════════════════════════+// Crypto WASM Bindings+// ═══════════════════════════════════════════════════════════════════════════════++/// AES-256-GCM encrypt bytes with a base64 key. Returns base64 of `IV | ciphertext | tag`.+#[wasm_bindgen(js_name = aesGcmEncrypt)]+pub fn aes_gcm_encrypt_js(plaintext: &[u8], key_base64: &str) -> Result<String, JsValue> {+ crate::crypto::symmetric_encrypt_bytes(plaintext, key_base64).map_err(|e| JsValue::from_str(&e.to_string()))+}++/// AES-256-GCM decrypt base64 `IV | ciphertext | tag` with a base64 key.+#[wasm_bindgen(js_name = aesGcmDecrypt)]+pub fn aes_gcm_decrypt_js(base64_ciphertext: &str, key_base64: &str) -> Result<Vec<u8>, JsValue> {+ let bytes = crate::encoding::base64_decode(base64_ciphertext).map_err(|e| JsValue::from_str(&e.to_string()))?;+ crate::crypto::symmetric_decrypt_bytes(&bytes, key_base64).map_err(|e| JsValue::from_str(&e.to_string()))+}++/// Generate an RSA-OAEP-256 key pair as `{ publicKey, privateKey }` JWK strings.+#[wasm_bindgen(js_name = rsaGenerateKeyPair)]+pub fn rsa_generate_key_pair_js() -> Result<JsValue, JsValue> {+ let pair = crate::crypto::generate_rsa_key_pair().map_err(|e| JsValue::from_str(&e.to_string()))?;+ serde_wasm_bindgen::to_value(&pair).map_err(|e| JsValue::from_str(&e.to_string()))+}++/// RSA-OAEP-256 encrypt bytes for a JWK public key. Returns base64 ciphertext.+#[wasm_bindgen(js_name = rsaEncrypt)]+pub fn rsa_encrypt_js(plaintext: &[u8], public_key_jwk: &str) -> Result<String, JsValue> {+ crate::crypto::encrypt_with_public_key(plaintext, public_key_jwk).map_err(|e| JsValue::from_str(&e.to_string()))+}++/// RSA-OAEP-256 decrypt base64 ciphertext with a JWK private key.+#[wasm_bindgen(js_name = rsaDecrypt)]+pub fn rsa_decrypt_js(base64_ciphertext: &str, private_key_jwk: &str) -> Result<Vec<u8>, JsValue> {+ crate::crypto::decrypt_with_private_key(base64_ciphertext, private_key_jwk).map_err(|e| JsValue::from_str(&e.to_string()))+}++// ═══════════════════════════════════════════════════════════════════════════════+// Vault sync engine WASM Bindings+// ═══════════════════════════════════════════════════════════════════════════════++/// One engine operation. The host loops on `nextCommand` / `resume` until the command is `done`; see the+/// `vault_sync` module docs for the command and response shapes.+#[wasm_bindgen(js_name = VaultSyncSession)]+pub struct VaultSyncSessionJs {+ inner: crate::vault_sync::SyncSession,+}++#[wasm_bindgen(js_class = VaultSyncSession)]+impl VaultSyncSessionJs {+ /// Start an operation from its `SyncRequest` JSON.+ #[wasm_bindgen(constructor)]+ pub fn new(request_json: &str) -> Result<VaultSyncSessionJs, JsValue> {+ Ok(Self { inner: crate::vault_sync::SyncSession::new(request_json).map_err(|e| JsValue::from_str(&e.to_string()))? })+ }++ /// The next command for the host, as JSON.+ #[wasm_bindgen(js_name = nextCommand)]+ pub fn next_command(&self) -> Result<String, JsValue> {+ self.inner.next_command().map_err(|e| JsValue::from_str(&e.to_string()))+ }++ /// Hand the host's response to the last command back, as JSON.+ pub fn resume(&self, response_json: &str) -> Result<(), JsValue> {+ self.inner.resume(response_json).map_err(|e| JsValue::from_str(&e.to_string()))+ }+}