π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
both
Manav Rathid167da02d550
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsxindex e4ea59f925..8a347eec00 100644--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx@@ -10,6 +10,7 @@ import { Titlebar } from "@/base/components/Titlebar";import { useModalVisibility } from "@/base/components/utils/modal";import { sharedCryptoWorker } from "@/base/crypto";import log from "@/base/log";+import { appendCollectionKeyToShareURL } from "@/gallery/services/share";import type {Collection,PublicURL,@@ -65,10 +66,7 @@ import {unshareCollection,updateShareableURL,} from "services/collectionService";-import {- appendCollectionKeyToShareURL,- getDeviceLimitOptions,-} from "utils/collection";+import { getDeviceLimitOptions } from "utils/collection";import * as Yup from "yup";interface CollectionShareProps {@@ -1224,7 +1222,7 @@ const PublicShare: React.FC<PublicShareProps> = ({}, [collection]);useEffect(() => {- if (publicShareProp) {+ if (publicShareProp?.url) {const url = appendCollectionKeyToShareURL(publicShareProp.url,collection.key,diff --git a/web/packages/gallery/services/share.ts b/web/packages/gallery/services/share.tsnew file mode 100644index 0000000000..4742524a24--- /dev/null+++ b/web/packages/gallery/services/share.ts@@ -0,0 +1,50 @@+import { sharedCryptoWorker } from "@/base/crypto";+import bs58 from "bs58";++/**+ * Add the collection key as the hash to the given URL.+ *+ * The hash fragment is a client side component and is not accessible to remote+ * servers. The collection key is base-58 encoded and set as the hash in public+ * URLs of shared albums.+ *+ * Use {@link extractCollectionKeyFromShareURL} to get back the collection key.++ * @param url The base URL for the public album.++ * @param collectionKey The base-64 encoded string representation of the+ * collection key for the public album.+ *+ * @returns A URL that includes the base-58 encoded collection key as the hash+ * fragment.+ */+export const appendCollectionKeyToShareURL = (+ url: string,+ collectionKey: string,+) => {+ const sharableURL = new URL(url);++ const bytes = Buffer.from(collectionKey, "base64");+ sharableURL.hash = bs58.encode(bytes);+ return sharableURL.href;+};++/**+ * Extract the collection key from a public URL.+ *+ * This is the inverse of {@link appendCollectionKeyToShareURL}, returning the+ * base 64 string representation of the collection key.+ *+ * collection key (bytes)+ * => appendCollectionKeytoShareURL (base 64 => base 58)+ * => URL hash => extractCollectionKeyBytesFromShareURL (base 58 => base 64)+ * => collection key (bytes).+ */+export const extractCollectionKeyFromShareURL = async (url: URL) => {+ const ck = url.hash.slice(1);+ const cryptoWorker = await sharedCryptoWorker();++ return ck.length < 50+ ? await cryptoWorker.toB64(bs58.decode(ck))+ : await cryptoWorker.fromHex(ck);+};