π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add focused Legacy WASM bindings
Manav Rathiac5c1650439c
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex d262e99f1b..5cd5953e4b 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2586,6 +2586,20 @@ dependencies = ["tiff 0.10.3",]+[[package]]+name = "ente-legacy-wasm"+version = "0.0.0"+dependencies = [+ "ente-contacts",+ "ente-core",+ "ente-wasm-log",+ "js-sys",+ "serde",+ "serde-wasm-bindgen",+ "wasm-bindgen",+ "wasm-bindgen-futures",+]+[[package]]name = "ente-locker-frb"version = "0.0.0"diff --git a/rust/Cargo.toml b/rust/Cargo.tomlindex 6dc2e4545c..f4dcbf5265 100644--- a/rust/Cargo.toml+++ b/rust/Cargo.toml@@ -14,6 +14,7 @@ members = ["bindings/wasm/cast","bindings/wasm/core","bindings/wasm/ensu",+ "bindings/wasm/legacy","bindings/wasm/log","bindings/wasm/paste","bindings/wasm/space",diff --git a/rust/bindings/wasm/core/src/legacy_kit.rs b/rust/bindings/wasm/core/src/legacy_kit.rsdeleted file mode 100644index 088f0e7204..0000000000--- a/rust/bindings/wasm/core/src/legacy_kit.rs+++ /dev/null@@ -1,58 +0,0 @@-use ente_contacts::{LegacyKitRecoveryClient, LegacyKitShare};-use serde::Deserialize;-use serde_wasm_bindgen as swb;-use wasm_bindgen::prelude::*;--use crate::contacts::ContactsError;--#[derive(Deserialize)]-#[serde(rename_all = "camelCase")]-struct OpenLegacyKitRecoveryInput {- base_url: String,- shares: Vec<LegacyKitShare>,- email: Option<String>,- client_package: Option<String>,- client_version: Option<String>,- user_agent: Option<String>,-}--#[wasm_bindgen]-pub async fn legacy_kit_open_recovery(- input: JsValue,-) -> Result<LegacyKitRecoveryHandle, ContactsError> {- let input: OpenLegacyKitRecoveryInput = swb::from_value(input)?;- let client = LegacyKitRecoveryClient::new_with_headers(- input.base_url,- input.client_package,- input.client_version,- input.user_agent,- )?;- let handle = client- .open_from_shares(&input.shares, input.email.as_deref())- .await?;- Ok(LegacyKitRecoveryHandle { inner: handle })-}--#[wasm_bindgen]-pub struct LegacyKitRecoveryHandle {- inner: ente_contacts::LegacyKitRecoveryHandle,-}--#[wasm_bindgen]-impl LegacyKitRecoveryHandle {- pub fn session(&self) -> Result<JsValue, ContactsError> {- swb::to_value(self.inner.session()).map_err(Into::into)- }-- pub async fn refresh_session(&self) -> Result<JsValue, ContactsError> {- let session = self.inner.refresh_session().await?;- swb::to_value(&session).map_err(Into::into)- }-- pub async fn change_password(&self, new_password: String) -> Result<(), ContactsError> {- self.inner- .change_password(&new_password)- .await- .map_err(Into::into)- }-}diff --git a/rust/bindings/wasm/core/src/lib.rs b/rust/bindings/wasm/core/src/lib.rsindex 431c8ff239..a8a0d8c99a 100644--- a/rust/bindings/wasm/core/src/lib.rs+++ b/rust/bindings/wasm/core/src/lib.rs@@ -3,4 +3,3 @@ use ente_wasm_log as _;mod auth;mod contacts;mod crypto;-mod legacy_kit;diff --git a/rust/bindings/wasm/legacy/Cargo.toml b/rust/bindings/wasm/legacy/Cargo.tomlnew file mode 100644index 0000000000..559d6939cc--- /dev/null+++ b/rust/bindings/wasm/legacy/Cargo.toml@@ -0,0 +1,16 @@+[package]+name = "ente-legacy-wasm"+edition = "2024"++[lib]+crate-type = ["cdylib"]++[dependencies]+ente-contacts.workspace = true+ente-core.workspace = true+ente-wasm-log.workspace = true+js-sys.workspace = true+serde.workspace = true+serde-wasm-bindgen.workspace = true+wasm-bindgen.workspace = true+wasm-bindgen-futures.workspace = truediff --git a/rust/bindings/wasm/legacy/src/lib.rs b/rust/bindings/wasm/legacy/src/lib.rsnew file mode 100644index 0000000000..5df24b5388--- /dev/null+++ b/rust/bindings/wasm/legacy/src/lib.rs@@ -0,0 +1,108 @@+use ente_contacts::{LegacyKitRecoveryClient, LegacyKitShare};+use js_sys::Reflect;+use serde::Deserialize;+use serde_wasm_bindgen as swb;+use wasm_bindgen::prelude::*;++use ente_wasm_log as _;++pub struct LegacyError {+ kind: &'static str,+ message: String,+}++impl From<LegacyError> for JsValue {+ fn from(error: LegacyError) -> Self {+ let js_error = js_sys::Error::new(&error.message);+ Reflect::set(+ js_error.as_ref(),+ &JsValue::from_str("kind"),+ &JsValue::from_str(error.kind),+ )+ .expect("setting error kind should not fail");+ js_error.into()+ }+}++impl From<ente_contacts::Error> for LegacyError {+ fn from(error: ente_contacts::Error) -> Self {+ use ente_contacts::ErrorKind as K;+ let kind = match error.kind() {+ K::Network => "network",+ K::Http => "http",+ K::Parse => "parse",+ K::Crypto => "crypto",+ K::Auth => "auth",+ K::InvalidInput => "invalid_input",+ K::MissingEncryptedData => "missing_encrypted_data",+ K::MissingEncryptedKey => "missing_encrypted_key",+ K::ProfilePictureNotFound => "profile_picture_not_found",+ K::ActiveRecoverySession => "active_recovery_session",+ };+ Self {+ kind,+ message: ente_core::error::chain(&error),+ }+ }+}++impl From<swb::Error> for LegacyError {+ fn from(error: swb::Error) -> Self {+ Self {+ kind: "serde",+ message: error.to_string(),+ }+ }+}++#[derive(Deserialize)]+#[serde(rename_all = "camelCase")]+struct OpenLegacyKitRecoveryInput {+ base_url: String,+ shares: Vec<LegacyKitShare>,+ email: Option<String>,+ client_package: Option<String>,+ client_version: Option<String>,+ user_agent: Option<String>,+}++#[wasm_bindgen]+pub async fn legacy_kit_open_recovery(+ input: JsValue,+) -> Result<LegacyKitRecoveryHandle, LegacyError> {+ let input: OpenLegacyKitRecoveryInput = swb::from_value(input)?;+ let client = LegacyKitRecoveryClient::new_with_headers(+ input.base_url,+ input.client_package,+ input.client_version,+ input.user_agent,+ )?;+ let handle = client+ .open_from_shares(&input.shares, input.email.as_deref())+ .await?;+ Ok(LegacyKitRecoveryHandle { inner: handle })+}++#[wasm_bindgen]+pub struct LegacyKitRecoveryHandle {+ inner: ente_contacts::LegacyKitRecoveryHandle,+}++#[wasm_bindgen]+impl LegacyKitRecoveryHandle {+ pub fn session(&self) -> Result<JsValue, LegacyError> {+ swb::to_value(self.inner.session()).map_err(Into::into)+ }++ pub async fn refresh_session(&self) -> Result<JsValue, LegacyError> {+ let session = self.inner.refresh_session().await?;+ swb::to_value(&session).map_err(Into::into)+ }++ pub async fn change_password(&self, new_password: String) -> Result<(), LegacyError> {+ self.inner+ .change_password(&new_password)+ .await+ .map_err(Into::into)+ }+}diff --git a/web/apps/legacy/package.json b/web/apps/legacy/package.jsonindex aca7df02db..6a9e84c847 100644--- a/web/apps/legacy/package.json+++ b/web/apps/legacy/package.json@@ -6,7 +6,7 @@"@mui/icons-material": "9.3.1","ente-accounts": "*","ente-base": "*",- "ente-core-wasm": "*",+ "ente-legacy-wasm": "*","pdfjs-dist": "6.2.108","qr": "0.6.0","zod": "4.4.3"diff --git a/web/apps/legacy/src/features/legacy-kit/recovery.ts b/web/apps/legacy/src/features/legacy-kit/recovery.tsindex 0e17e4d89a..52544a3f57 100644--- a/web/apps/legacy/src/features/legacy-kit/recovery.ts+++ b/web/apps/legacy/src/features/legacy-kit/recovery.ts@@ -1,6 +1,6 @@import { clientPackageName, desktopAppVersion, isDesktop } from "ente-base/app";import { apiOrigin } from "ente-base/origins";-import type { LegacyKitRecoveryHandle } from "ente-core-wasm";+import type { LegacyKitRecoveryHandle } from "ente-legacy-wasm";import { z } from "zod";import type { LegacyKitShare } from "./share";@@ -27,7 +27,7 @@ export const openLegacyKitRecovery = async (shares: LegacyKitShare[],email?: string,): Promise<OpenedLegacyKitRecovery> => {- const wasm = await import("ente-core-wasm");+ const wasm = await import("ente-legacy-wasm");const handle = await wasm.legacy_kit_open_recovery({baseUrl: await apiOrigin(),shares,diff --git a/web/apps/legacy/src/pages/index.tsx b/web/apps/legacy/src/pages/index.tsxindex a44b4eaccf..ce76bd3424 100644--- a/web/apps/legacy/src/pages/index.tsx+++ b/web/apps/legacy/src/pages/index.tsx@@ -20,7 +20,7 @@ import { LoadingButton } from "ente-base/components/mui/LoadingButton";import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";import { isDevBuild } from "ente-base/env";import log from "ente-base/log";-import type { LegacyKitRecoveryHandle } from "ente-core-wasm";+import type { LegacyKitRecoveryHandle } from "ente-legacy-wasm";import React, { useCallback, useEffect, useMemo, useState } from "react";import {changeLegacyKitPassword,diff --git a/web/package-lock.json b/web/package-lock.jsonindex 7b6c304e4e..87178978b2 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -215,7 +215,7 @@"@mui/icons-material": "9.3.1","ente-accounts": "*","ente-base": "*",- "ente-core-wasm": "*",+ "ente-legacy-wasm": "*","pdfjs-dist": "6.2.108","qr": "0.6.0","zod": "4.4.3"@@ -4753,6 +4753,10 @@"resolved": "packages/gallery","link": true},+ "node_modules/ente-legacy-wasm": {+ "resolved": "packages/wasm/legacy",+ "link": true+ },"node_modules/ente-media": {"resolved": "packages/media","link": true@@ -11352,6 +11356,14 @@"wasm-pack": "0.15.0"}},+ "packages/wasm/legacy": {+ "name": "ente-legacy-wasm",+ "version": "0.0.0",+ "devDependencies": {+ "ente-build-config": "*",+ "wasm-pack": "0.15.0"+ }+ },"packages/wasm/paste": {"name": "ente-paste-wasm","version": "0.0.0",diff --git a/web/package.json b/web/package.jsonindex f706eb5f8d..89e7d5cf5e 100644--- a/web/package.json+++ b/web/package.json@@ -18,7 +18,8 @@"build:embed": "npm run build:core-wasm && npm exec --workspace embed -- next build --webpack","build:ensu": "npm run build:ensu-wasm && npm exec --workspace ensu -- next build --webpack","build:ensu-wasm": "npm run build --workspace ente-ensu-wasm",- "build:legacy": "npm run build:core-wasm && npm exec --workspace legacy -- next build --webpack",+ "build:legacy": "npm run build:legacy-wasm && npm exec --workspace legacy -- next build --webpack",+ "build:legacy-wasm": "npm run build --workspace ente-legacy-wasm","build:locker": "npm run build:core-wasm && npm exec --workspace locker -- next build --webpack","build:memories": "npm run build:core-wasm && npm exec --workspace memories -- next build --webpack && npm run build:post --workspace memories","build:paste": "npm run build:paste-wasm && npm exec --workspace paste -- next build --webpack && npm run build:post --workspace paste",@@ -29,7 +30,7 @@"build:space": "npm run build:core-wasm && npm run build:space-wasm && npm exec --workspace space -- next build --webpack && npm run build:post --workspace space","build:space-wasm": "npm run build --workspace ente-space-wasm","build:twoof3": "npm exec --workspace twoof3 -- next build --webpack",- "build:wasm": "npm run build:core-wasm && npm run build:cast-wasm && npm run build:ensu-wasm && npm run build:paste-wasm && npm run build:space-wasm",+ "build:wasm": "npm run build:core-wasm && npm run build:cast-wasm && npm run build:ensu-wasm && npm run build:legacy-wasm && npm run build:paste-wasm && npm run build:space-wasm","dev": "npm run dev:photos","dev:accounts": "npm run build:core-wasm && npm exec --workspace accounts -- next dev --webpack -p 3001","dev:albums": "npm run build:core-wasm && npm exec --workspace albums -- next dev --webpack -p 3002",@@ -37,7 +38,7 @@"dev:cast": "npm run build:core-wasm && npm run build:cast-wasm && npm exec --workspace cast -- next dev --webpack -p 3004","dev:embed": "npm run build:core-wasm && npm exec --workspace embed -- next dev --webpack -p 3006","dev:ensu": "npm run build:ensu-wasm && npm exec --workspace ensu -- next dev --webpack -p 3007",- "dev:legacy": "npm run build:core-wasm && npm exec --workspace legacy -- next dev --webpack -p 3011",+ "dev:legacy": "npm run build:legacy-wasm && npm exec --workspace legacy -- next dev --webpack -p 3011","dev:locker": "npm run build:core-wasm && npm exec --workspace locker -- next dev --webpack -p 3009","dev:memories": "npm run build:core-wasm && npm exec --workspace memories -- next dev --webpack -p 3010","dev:paste": "npm run build:paste-wasm && npm exec --workspace paste -- next dev --webpack -p 3008",diff --git a/web/packages/wasm/legacy/eslint.config.mjs b/web/packages/wasm/legacy/eslint.config.mjsnew file mode 100644index 0000000000..e6c7d4d3b0--- /dev/null+++ b/web/packages/wasm/legacy/eslint.config.mjs@@ -0,0 +1,3 @@+import config from "ente-build-config/eslintrc-base.mjs";++export default [...config, { ignores: ["pkg/"] }];diff --git a/web/packages/wasm/legacy/index.ts b/web/packages/wasm/legacy/index.tsnew file mode 100644index 0000000000..d7cf9a1c1a--- /dev/null+++ b/web/packages/wasm/legacy/index.ts@@ -0,0 +1 @@+export * from "./pkg/ente_legacy_wasm";diff --git a/web/packages/wasm/legacy/package.json b/web/packages/wasm/legacy/package.jsonnew file mode 100644index 0000000000..14e9dac984--- /dev/null+++ b/web/packages/wasm/legacy/package.json@@ -0,0 +1,20 @@+{+ "name": "ente-legacy-wasm",+ "version": "0.0.0",+ "private": true,+ "exports": {+ ".": {+ "types": "./index.ts",+ "import": "./index.ts"+ }+ },+ "module": "./index.ts",+ "types": "./index.ts",+ "scripts": {+ "build": "wasm-pack build ../../../../rust/bindings/wasm/legacy --target bundler --out-dir ../../../../web/packages/wasm/legacy/pkg --no-pack"+ },+ "devDependencies": {+ "ente-build-config": "*",+ "wasm-pack": "0.15.0"+ }+}diff --git a/web/packages/wasm/legacy/tsconfig.json b/web/packages/wasm/legacy/tsconfig.jsonnew file mode 100644index 0000000000..3f3b6cd165--- /dev/null+++ b/web/packages/wasm/legacy/tsconfig.json@@ -0,0 +1 @@+{ "extends": "ente-build-config/tsconfig-typecheck.json", "include": ["."] }