Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Generate types for Space context inputs

Manav Rathi937aa3eeb88b
diff --git a/rust/bindings/wasm/space/src/space.rs b/rust/bindings/wasm/space/src/space.rs
index 6c6bd40710..2c86d6a894 100644
--- a/rust/bindings/wasm/space/src/space.rs
+++ b/rust/bindings/wasm/space/src/space.rs
@@ -5,7 +5,7 @@ use ente_space::{
AccountSpaceCtx, CreatedSpace, DecryptedMessage, DecryptedPost, DecryptedSpaceProfile,
MessageConversationActivity, MessagePayload, MessageResponse, OpenAccountSpaceCtxInput,
OpenSpaceLinkCtxInput, PostPhotoAssetOptions, PostResponse, ProfileAvatarResponse,
- ProfileCoverResponse, SpaceActorResponse, SpaceKeyResponse, SpaceLinkCtx,
+ ProfileCoverResponse, SpaceActorResponse, SpaceLinkCtx,
};
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen as swb;
@@ -67,28 +67,63 @@ impl From<Error> for JsValue {
}
}
-#[derive(Deserialize)]
+#[derive(Deserialize, Tsify)]
#[serde(rename_all = "camelCase")]
-struct OpenAccountSpaceCtxJsInput {
+pub struct OpenAccountSpaceCtxJsInput {
base_url: String,
+ #[tsify(optional)]
space_session_token: Option<String>,
space_root_key_b64: String,
#[serde(default)]
+ #[tsify(optional)]
owned_spaces: Option<Vec<SpaceKeyResponse>>,
+ #[tsify(optional)]
client_package: Option<String>,
+ #[tsify(optional)]
client_version: Option<String>,
}
-#[derive(Deserialize)]
+#[derive(Deserialize, Tsify)]
#[serde(rename_all = "camelCase")]
-struct OpenSpaceLinkCtxJsInput {
+pub struct OpenSpaceLinkCtxJsInput {
base_url: String,
space_username: String,
access_key: String,
+ #[tsify(optional)]
client_package: Option<String>,
+ #[tsify(optional)]
client_version: Option<String>,
}
+#[derive(Deserialize, Tsify)]
+#[serde(rename_all = "camelCase")]
+pub struct SpaceKeyResponse {
+ space_id: String,
+ space_slug: String,
+ root_wrapped_space_key: String,
+ #[serde(default)]
+ public_key: String,
+ #[serde(default)]
+ encrypted_secret_key: String,
+ #[serde(default)]
+ encrypted_profile: String,
+ key_version: i32,
+}
+
+impl From<SpaceKeyResponse> for ente_space::SpaceKeyResponse {
+ fn from(value: SpaceKeyResponse) -> Self {
+ Self {
+ space_id: value.space_id,
+ space_slug: value.space_slug,
+ root_wrapped_space_key: value.root_wrapped_space_key,
+ public_key: value.public_key,
+ encrypted_secret_key: value.encrypted_secret_key,
+ encrypted_profile: value.encrypted_profile,
+ key_version: value.key_version,
+ }
+ }
+}
+
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct PostPhotoAssetOptionsJsInput {
@@ -658,14 +693,18 @@ async fn resilient_message_conversation_activity_to_js(
}
#[wasm_bindgen(js_name = spaceOpenAccountCtx)]
-pub fn space_open_account_ctx(input: JsValue) -> Result<SpaceAccountCtxHandle, Error> {
- let input: OpenAccountSpaceCtxJsInput = swb::from_value(input)?;
+pub fn space_open_account_ctx(
+ input: <OpenAccountSpaceCtxJsInput as Tsify>::JsType,
+) -> Result<SpaceAccountCtxHandle, Error> {
+ let input = OpenAccountSpaceCtxJsInput::from_js(input)?;
let space_root_key = decode_b64_field(&input.space_root_key_b64)?;
let ctx = AccountSpaceCtx::open(OpenAccountSpaceCtxInput {
base_url: input.base_url,
space_session_token: input.space_session_token,
space_root_key,
- initial_owned_spaces: input.owned_spaces,
+ initial_owned_spaces: input
+ .owned_spaces
+ .map(|spaces| spaces.into_iter().map(Into::into).collect()),
user_agent: None,
client_package: input.client_package,
client_version: input.client_version,
@@ -674,8 +713,10 @@ pub fn space_open_account_ctx(input: JsValue) -> Result<SpaceAccountCtxHandle, E
}
#[wasm_bindgen(js_name = spaceOpenLinkCtx)]
-pub async fn space_open_link_ctx(input: JsValue) -> Result<SpaceLinkCtxHandle, Error> {
- let input: OpenSpaceLinkCtxJsInput = swb::from_value(input)?;
+pub async fn space_open_link_ctx(
+ input: <OpenSpaceLinkCtxJsInput as Tsify>::JsType,
+) -> Result<SpaceLinkCtxHandle, Error> {
+ let input = OpenSpaceLinkCtxJsInput::from_js(input)?;
let inner = SpaceLinkCtx::open(OpenSpaceLinkCtxInput {
base_url: input.base_url,
space_slug: input.space_username,
diff --git a/web/packages/wasm/space/index.ts b/web/packages/wasm/space/index.ts
index ea09395daf..9cffecae2f 100644
--- a/web/packages/wasm/space/index.ts
+++ b/web/packages/wasm/space/index.ts
@@ -1,3 +1,8 @@
+import type {
+ OpenAccountSpaceCtxJsInput,
+ OpenSpaceLinkCtxJsInput,
+} from "./pkg/ente_space_wasm";
+
const wasm = () => import("./pkg/ente_space_wasm");
export type SpaceAccountCtxHandle =
@@ -5,23 +10,6 @@ export type SpaceAccountCtxHandle =
export type SpaceLinkCtxHandle =
import("./pkg/ente_space_wasm").SpaceLinkCtxHandle;
-interface OpenSpaceAccountContextInput {
- baseUrl: string;
- clientPackage: string;
- clientVersion?: string;
- ownedSpaces?: unknown[];
- spaceRootKeyB64: string;
- spaceSessionToken: string;
-}
-
-interface OpenSpaceLinkContextInput {
- accessKey: string;
- baseUrl: string;
- clientPackage: string;
- clientVersion?: string;
- spaceUsername: string;
-}
-
export const encryptSpaceRootEntityKey = async (
spaceRootKeyB64: string,
masterKeyB64: string,
@@ -33,9 +21,9 @@ export const decryptSpaceRootEntityKey = async (
) => (await wasm()).decryptSpaceRootEntityKey(encryptedKeyB64, masterKeyB64);
export const openSpaceAccountContext = async (
- input: OpenSpaceAccountContextInput,
+ input: OpenAccountSpaceCtxJsInput,
): Promise<SpaceAccountCtxHandle> => (await wasm()).spaceOpenAccountCtx(input);
export const openSpaceLinkContext = async (
- input: OpenSpaceLinkContextInput,
+ input: OpenSpaceLinkCtxJsInput,
): Promise<SpaceLinkCtxHandle> => (await wasm()).spaceOpenLinkCtx(input);