Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #368 from ente-io/base58
Browse files Browse the repository at this point in the history
Shared-url: switch to bs58 encoding for ck
  • Loading branch information
ua741 committed Feb 14, 2022
2 parents 5244428 + 94adaaf commit b1b1650
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -23,6 +23,7 @@
"axios": "^0.21.3",
"bip39": "^3.0.4",
"bootstrap": "^4.5.2",
"bs58" : "^4.0.1",
"chrono-node": "^2.2.6",
"comlink": "^4.3.0",
"debounce-promise": "^3.1.2",
Expand Down
8 changes: 6 additions & 2 deletions src/pages/shared-albums/index.tsx
Expand Up @@ -36,6 +36,7 @@ const Loader = () => (
</EnteSpinner>
</Container>
);
const bs58 = require('bs58');
export default function PublicCollectionGallery() {
const token = useRef<string>(null);
const collectionKey = useRef<string>(null);
Expand Down Expand Up @@ -92,10 +93,13 @@ export default function PublicCollectionGallery() {
const currentURL = new URL(url.current);
const t = currentURL.searchParams.get('t');
const ck = currentURL.hash.slice(1);
const dck = await worker.fromHex(ck);
if (!t || !dck) {
if (!t || !ck) {
return;
}
const dck =
ck.length < 50
? await worker.toB64(bs58.decode(ck))
: await worker.fromHex(ck);
token.current = t;
collectionKey.current = dck;
url.current = window.location.href;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/collection/index.ts
Expand Up @@ -16,7 +16,6 @@ import { logError } from 'utils/sentry';
import constants from 'utils/strings/constants';
import { Collection } from 'types/collection';
import { CollectionType } from 'constants/collection';
import CryptoWorker from 'utils/crypto';
import { getAlbumSiteHost } from 'constants/pages';

export enum COLLECTION_OPS_TYPE {
Expand Down Expand Up @@ -114,15 +113,16 @@ export async function appendCollectionKeyToShareURL(
url: string,
collectionKey: string
) {
const worker = await new CryptoWorker();
if (!url) {
return null;
}
const bs58 = require('bs58');
const sharableURL = new URL(url);
if (process.env.NODE_ENV === 'development') {
sharableURL.host = getAlbumSiteHost();
sharableURL.protocol = 'http';
}
sharableURL.hash = await worker.toHex(collectionKey);
const bytes = Buffer.from(collectionKey, 'base64');
sharableURL.hash = bs58.encode(bytes);
return sharableURL.href;
}
16 changes: 15 additions & 1 deletion yarn.lock
Expand Up @@ -2079,6 +2079,13 @@ balanced-match@^1.0.0:
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

base-x@^3.0.2:
version "3.0.9"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.9.tgz#6349aaabb58526332de9f60995e548a53fe21320"
integrity sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==
dependencies:
safe-buffer "^5.0.1"

base64-js@^1.0.2:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
Expand Down Expand Up @@ -2269,6 +2276,13 @@ browserslist@^4.16.6, browserslist@^4.17.0:
escalade "^3.1.1"
node-releases "^1.1.75"

bs58@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a"
integrity sha1-vhYedsNU9veIrkBx9j806MTwpCo=
dependencies:
base-x "^3.0.2"

buffer-from@^1.0.0:
version "1.1.2"
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz"
Expand Down Expand Up @@ -5086,7 +5100,7 @@ peek-readable@^4.0.1:
integrity sha512-7qmhptnR0WMSpxT5rMHG9bW/mYSR1uqaPFj2MHvT+y/aOUu6msJijpKt5SkTDKySwg65OWG2JwTMBlgcbwMHrQ==

"photoswipe@file:./thirdparty/photoswipe":
version "4.1.4"
version "4.1.3"

picomatch@^2.0.4, picomatch@^2.2.1:
version "2.3.1"
Expand Down

0 comments on commit b1b1650

Please sign in to comment.