π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use our layer in cast
Manav Rathi19e1bd51c8b7
diff --git a/web/apps/cast/src/services/pair.ts b/web/apps/cast/src/services/pair.tsindex 36b54cf759..9edea9ca4f 100644--- a/web/apps/cast/src/services/pair.ts+++ b/web/apps/cast/src/services/pair.ts@@ -1,8 +1,10 @@import log from "@/next/log";import { wait } from "@/utils/promise";-import { boxSealOpen, toB64 } from "@ente/shared/crypto/internal/libsodium";+import {+ boxSealOpen,+ generateKeyPair,+} from "@ente/shared/crypto/internal/libsodium";import castGateway from "@ente/shared/network/cast";-import _sodium from "libsodium-wrappers";export interface Registration {/** A pairing code shown on the screen. A client can use this to connect. */@@ -75,9 +77,8 @@ export interface Registration {*/export const register = async (): Promise<Registration> => {// Generate keypair.- const keypair = await generateKeyPair();- const publicKeyB64 = await toB64(keypair.publicKey);- const privateKeyB64 = await toB64(keypair.privateKey);+ const { publicKey: publicKeyB64, privateKey: privateKeyB64 } =+ await generateKeyPair();// Register keypair with museum to get a pairing code.let pairingCode: string;@@ -127,8 +128,3 @@ export const getCastData = async (registration: Registration) => {return JSON.parse(atob(decryptedCastData));};--const generateKeyPair = async () => {- await _sodium.ready;- return _sodium.crypto_box_keypair();-};diff --git a/web/packages/shared/crypto/internal/libsodium.ts b/web/packages/shared/crypto/internal/libsodium.tsindex 1c18052e56..f23cabbc70 100644--- a/web/packages/shared/crypto/internal/libsodium.ts+++ b/web/packages/shared/crypto/internal/libsodium.ts@@ -340,14 +340,18 @@ export async function generateSaltToDeriveKey() {return await toB64(sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES));}-export async function generateKeyPair() {+/**+ * Generate a new public/private keypair, and return their Base64+ * representations.+ */+export const generateKeyPair = async () => {await sodium.ready;- const keyPair: sodium.KeyPair = sodium.crypto_box_keypair();+ const keyPair = sodium.crypto_box_keypair();return {- privateKey: await toB64(keyPair.privateKey),publicKey: await toB64(keyPair.publicKey),+ privateKey: await toB64(keyPair.privateKey),};-}+};export async function boxSealOpen(input: string,