π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fin
Manav Rathi5002cf1d6242
diff --git a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsxindex 322ca395bb..e503e956ea 100644--- a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx+++ b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx@@ -1,10 +1,11 @@import { TitledMiniDialog } from "@/base/components/MiniDialog";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { boxSeal } from "@/base/crypto";+import { newID } from "@/base/id";import log from "@/base/log";import type { Collection } from "@/media/collection";import { photosDialogZIndex } from "@/new/photos/components/utils/z-index";-import castGateway, {+import {publicKeyForPairingCode,revokeAllCastTokens,} from "@/new/photos/services/cast";@@ -16,7 +17,6 @@ import { Button, Link, Stack, Typography } from "@mui/material";import { t } from "i18next";import { useEffect, useState } from "react";import { Trans } from "react-i18next";-import { v4 as uuidv4 } from "uuid";interface AlbumCastDialogProps {/** If `true`, the dialog is shown. */@@ -66,14 +66,14 @@ export const AlbumCastDialog: React.FC<AlbumCastDialogProps> = ({}};- const doCast = async (pin: string) => {+ const doCast = async (code: string) => {// Find out the public key associated with the given pairing code (if// indeed a device has published one).- const publicKey = await publicKeyForPairingCode(pin);+ const publicKey = await publicKeyForPairingCode(code);if (!publicKey) return false;// Generate random id.- const castToken = uuidv4();+ const castToken = newID("cast_");// Publish the payload so that the other end can use it.const payload = JSON.stringify({@@ -84,7 +84,7 @@ export const AlbumCastDialog: React.FC<AlbumCastDialogProps> = ({const encryptedPayload = await boxSeal(btoa(payload), publicKey);await castGateway.publishCastPayload(- pin,+ code,encryptedPayload,collection.id,castToken,diff --git a/web/packages/new/photos/services/cast.ts b/web/packages/new/photos/services/cast.tsindex 3de997539e..1c4cb74287 100644--- a/web/packages/new/photos/services/cast.ts+++ b/web/packages/new/photos/services/cast.ts@@ -1,7 +1,5 @@import { authenticatedRequestHeaders, ensureOk } from "@/base/http";import { apiURL } from "@/base/origins";-import HTTPService from "@ente/shared/network/HTTPService";-import { getToken } from "@ente/shared/storage/localStorage/helpers";import { z } from "zod";/**@@ -28,27 +26,23 @@ export const publicKeyForPairingCode = async (code: string) => {.publicKey;};-class CastGateway {- public async publishCastPayload(- code: string,- castPayload: string,- collectionID: number,- castToken: string,- ) {- const token = getToken();- await HTTPService.post(- await apiURL("/cast/cast-data"),- {- // eslint-disable-next-line @typescript-eslint/no-unnecessary-template-expression- deviceCode: `${code}`,- encPayload: castPayload,- collectionID: collectionID,- castToken: castToken,- },- undefined,- { "X-Auth-Token": token },- );- }-}--export default new CastGateway();+/**+ * Publish encrypted payload for a cast session so that the paired device can+ * obtain the information it needs to cast a collection.+ */+export const publishCastPayload = async (+ code: string,+ castPayload: string,+ collectionID: number,+ castToken: string,+) =>+ fetch(await apiURL("/cast/cast-data"), {+ method: "POST",+ headers: await authenticatedRequestHeaders(),+ body: JSON.stringify({+ deviceCode: code,+ encPayload: castPayload,+ collectionID: collectionID,+ castToken: castToken,+ }),+ });