diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.ts index 26b4802a00..203ed45ee6 100644 --- a/web/apps/accounts/src/services/passkey.ts +++ b/web/apps/accounts/src/services/passkey.ts @@ -1,9 +1,6 @@ import { TwoFactorAuthorizationResponse } from "ente-accounts/services/user"; import { clientPackageName } from "ente-base/app"; -import { - fromB64URLSafeNoPadding, - toB64URLSafeNoPadding, -} from "ente-base/crypto/libsodium"; +import { toB64URLSafeNoPadding, fromB64URLSafeNoPadding } from "ente-base/crypto"; import { isDevBuild } from "ente-base/env"; import { ensureOk, HTTPError, publicRequestHeaders } from "ente-base/http"; import { apiURL } from "ente-base/origins"; diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts index ad56a0c599..708ddf344b 100644 --- a/web/packages/base/crypto/ente-impl.ts +++ b/web/packages/base/crypto/ente-impl.ts @@ -6,8 +6,10 @@ import * as libsodium from "./libsodium"; // See: [Note: Using libsodium in worker thread] export const _toB64 = libsodium.toB64; -export const _toB64URLSafe = libsodium.toB64URLSafe; export const _fromB64 = libsodium.fromB64; +export const _toB64URLSafe = libsodium.toB64URLSafe; +export const _toB64URLSafeNoPadding = libsodium.toB64URLSafeNoPadding; +export const _fromB64URLSafeNoPadding = libsodium.fromB64URLSafeNoPadding; export const _toHex = libsodium.toHex; export const _fromHex = libsodium.fromHex; export const _generateKey = libsodium.generateKey; diff --git a/web/packages/base/crypto/index.ts b/web/packages/base/crypto/index.ts index e035ac1e52..4eb8b4ec82 100644 --- a/web/packages/base/crypto/index.ts +++ b/web/packages/base/crypto/index.ts @@ -150,6 +150,25 @@ export const toB64URLSafe = (bytes: Uint8Array): Promise => ? ei._toB64URLSafe(bytes) : sharedWorker().then((w) => w.toB64URLSafe(bytes)); +/** + * URL safe variant of {@link toB64} that does not add any padding ("=" + * characters). + */ +export const toB64URLSafeNoPadding = (bytes: Uint8Array): Promise => + inWorker() + ? ei._toB64URLSafeNoPadding(bytes) + : sharedWorker().then((w) => w.toB64URLSafeNoPadding(bytes)); + +/** + * URL safe unpadded variant of {@link fromB64}. + */ +export const fromB64URLSafeNoPadding = ( + b64String: string, +): Promise => + inWorker() + ? ei._fromB64URLSafeNoPadding(b64String) + : sharedWorker().then((w) => w.fromB64URLSafeNoPadding(b64String)); + /** * Convert a base64 string to the hex representation of the underlying bytes. */ diff --git a/web/packages/base/crypto/worker.ts b/web/packages/base/crypto/worker.ts index 982b66b1ee..dcd6dd88d4 100644 --- a/web/packages/base/crypto/worker.ts +++ b/web/packages/base/crypto/worker.ts @@ -13,8 +13,10 @@ import * as ei from "./ente-impl"; */ export class CryptoWorker { toB64 = ei._toB64; - toB64URLSafe = ei._toB64URLSafe; fromB64 = ei._fromB64; + toB64URLSafe = ei._toB64URLSafe; + toB64URLSafeNoPadding = ei._toB64URLSafeNoPadding; + fromB64URLSafeNoPadding = ei._fromB64URLSafeNoPadding; toHex = ei._toHex; fromHex = ei._fromHex; generateKey = ei._generateKey;