Consistency
This commit is contained in:
@@ -169,7 +169,7 @@ const beginPasskeyRegistration = async (token: string) => {
|
||||
// binary data.
|
||||
//
|
||||
// Binary data in the returned `PublicKeyCredentialCreationOptions` are
|
||||
// serialized as a "URLEncodedBase64", which is a URL-encoded Base64 string
|
||||
// serialized as a "URLEncodedBase64", which is a URL-encoded base64 string
|
||||
// without any padding. The library is following the WebAuthn recommendation
|
||||
// when it does this:
|
||||
//
|
||||
|
||||
@@ -29,11 +29,11 @@ import * as libsodium from "@ente/shared/crypto/internal/libsodium";
|
||||
*
|
||||
* @param data A {@link Uint8Array} containing the bytes to encrypt.
|
||||
*
|
||||
* @param keyB64 Base64 string containing the encryption key. This is expected
|
||||
* @param keyB64 base64 string containing the encryption key. This is expected
|
||||
* to the key of the object with which {@link data} is associated. For example,
|
||||
* if this is data associated with a file, then this will be the file's key.
|
||||
*
|
||||
* @returns The encrypted data and the (Base64 encoded) decryption header.
|
||||
* @returns The encrypted data and the (base64 encoded) decryption header.
|
||||
*/
|
||||
export const encryptAssociatedData = libsodium.encryptChaChaOneShot;
|
||||
|
||||
@@ -47,7 +47,7 @@ export const encryptAssociatedData = libsodium.encryptChaChaOneShot;
|
||||
* @param keyB64 The key associated with the file whose thumbnail this is.
|
||||
*
|
||||
* @returns The encrypted thumbnail, and the associated decryption header
|
||||
* (Base64 encoded).
|
||||
* (base64 encoded).
|
||||
*/
|
||||
export const encryptThumbnail = encryptAssociatedData;
|
||||
|
||||
@@ -56,7 +56,7 @@ export const encryptThumbnail = encryptAssociatedData;
|
||||
*
|
||||
* This as a variant of {@link encryptAssociatedData} tailored for
|
||||
* encrypting the embeddings (a.k.a. derived data) associated with a file. In
|
||||
* particular, it returns the encrypted data in the result as a Base64 string
|
||||
* particular, it returns the encrypted data in the result as a base64 string
|
||||
* instead of its bytes.
|
||||
*
|
||||
* Use {@link decryptFileEmbedding} to decrypt the result.
|
||||
@@ -86,7 +86,7 @@ export const encryptFileEmbedding = async (
|
||||
*
|
||||
* Instead of raw bytes, it takes as input an arbitrary JSON object which it
|
||||
* encodes into a string, and encrypts that. And instead of returning the raw
|
||||
* encrypted bytes, it returns their Base64 string representation.
|
||||
* encrypted bytes, it returns their base64 string representation.
|
||||
*
|
||||
* Use {@link decryptMetadata} to decrypt the result.
|
||||
*
|
||||
@@ -94,7 +94,7 @@ export const encryptFileEmbedding = async (
|
||||
* but since TypeScript currently doesn't have a native JSON type, it is typed
|
||||
* as an unknown.
|
||||
*
|
||||
* @returns The encrypted data and decryption header, both as Base64 strings.
|
||||
* @returns The encrypted data and decryption header, both as base64 strings.
|
||||
*/
|
||||
export const encryptMetadata = async (metadata: unknown, keyB64: string) => {
|
||||
const encodedMetadata = new TextEncoder().encode(JSON.stringify(metadata));
|
||||
@@ -119,12 +119,11 @@ export const encryptMetadata = async (metadata: unknown, keyB64: string) => {
|
||||
*
|
||||
* @param encryptedData A {@link Uint8Array} containing the bytes to decrypt.
|
||||
*
|
||||
* @param headerB64 A Base64 string containing the decryption header that was
|
||||
* @param headerB64 A base64 string containing the decryption header that was
|
||||
* produced during encryption.
|
||||
*
|
||||
* @param keyB64 A Base64 encoded string containing the encryption key. This is
|
||||
* expected to be the key of the file with which {@link encryptedDataB64} is
|
||||
* associated.
|
||||
* @param keyB64 A base64 string containing the encryption key. This is expected
|
||||
* to be the key of the object to which {@link encryptedDataB64} is associated.
|
||||
*
|
||||
* @returns The decrypted bytes.
|
||||
*/
|
||||
@@ -135,12 +134,12 @@ export const decryptAssociatedData = libsodium.decryptChaChaOneShot2;
|
||||
*
|
||||
* This is the sibling of {@link encryptFileEmbedding}.
|
||||
*
|
||||
* @param encryptedDataB64 A Base64 string containing the encrypted embedding.
|
||||
* @param encryptedDataB64 A base64 string containing the encrypted embedding.
|
||||
*
|
||||
* @param headerB64 A Base64 string containing the decryption header produced
|
||||
* @param headerB64 A base64 string containing the decryption header produced
|
||||
* during encryption.
|
||||
*
|
||||
* @param keyB64 A Base64 string containing the encryption key. This is expected
|
||||
* @param keyB64 A base64 string containing the encryption key. This is expected
|
||||
* to be the key of the file with which {@link encryptedDataB64} is associated.
|
||||
*
|
||||
* @returns The decrypted metadata JSON object.
|
||||
@@ -162,12 +161,12 @@ export const decryptFileEmbedding = async (
|
||||
*
|
||||
* This is the sibling of {@link decryptMetadata}.
|
||||
*
|
||||
* @param encryptedDataB64 Base64 encoded string containing the encrypted data.
|
||||
* @param encryptedDataB64 base64 encoded string containing the encrypted data.
|
||||
*
|
||||
* @param headerB64 Base64 encoded string containing the decryption header
|
||||
* @param headerB64 base64 encoded string containing the decryption header
|
||||
* produced during encryption.
|
||||
*
|
||||
* @param keyB64 Base64 encoded string containing the encryption key. This is
|
||||
* @param keyB64 base64 encoded string containing the encryption key. This is
|
||||
* expected to be the key of the object with which {@link encryptedDataB64} is
|
||||
* associated.
|
||||
*
|
||||
|
||||
@@ -11,7 +11,7 @@ import { CustomError } from "@ente/shared/error";
|
||||
import sodium, { type StateAddress } from "libsodium-wrappers";
|
||||
|
||||
/**
|
||||
* Convert a {@link Uint8Array} to a Base64 encoded string.
|
||||
* Convert bytes ({@link Uint8Array}) to a base64 string.
|
||||
*
|
||||
* See also {@link toB64URLSafe} and {@link toB64URLSafeNoPadding}.
|
||||
*/
|
||||
@@ -21,7 +21,7 @@ export const toB64 = async (input: Uint8Array) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a Base64 encoded string to a {@link Uint8Array}.
|
||||
* Convert a base64 string to bytes ({@link Uint8Array}).
|
||||
*
|
||||
* This is the converse of {@link toBase64}.
|
||||
*/
|
||||
@@ -31,7 +31,7 @@ export const fromB64 = async (input: string) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a {@link Uint8Array} to a URL-safe Base64 encoded string.
|
||||
* Convert bytes ({@link Uint8Array}) to a URL-safe base64 string.
|
||||
*
|
||||
* See also {@link toB64URLSafe} and {@link toB64URLSafeNoPadding}.
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ export const toB64URLSafe = async (input: Uint8Array) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a {@link Uint8Array} to a unpadded URL-safe Base64 encoded string.
|
||||
* Convert bytes ({@link Uint8Array}) to a unpadded URL-safe base64 string.
|
||||
*
|
||||
* This differs from {@link toB64URLSafe} in that it does not append any
|
||||
* trailing padding character(s) "=" to make the resultant string's length be an
|
||||
@@ -62,7 +62,7 @@ export const toB64URLSafeNoPadding = async (input: Uint8Array) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a unpadded URL-safe Base64 encoded string to a {@link Uint8Array}.
|
||||
* Convert a unpadded URL-safe base64 string to bytes ({@link Uint8Array}).
|
||||
*
|
||||
* This is the converse of {@link toB64URLSafeNoPadding}, and does not expect
|
||||
* its input string's length to be a an integer multiple of 4.
|
||||
@@ -111,7 +111,7 @@ export async function fromHex(input: string) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt the given {@link data} using the given (Base64 encoded) key.
|
||||
* Encrypt the given {@link data} using the given (base64 encoded) key.
|
||||
*
|
||||
* Use {@link decryptChaChaOneShot} to decrypt the result.
|
||||
*
|
||||
@@ -137,18 +137,19 @@ export async function fromHex(input: string) {
|
||||
* See: https://doc.libsodium.org/secret-key_cryptography/secretbox
|
||||
*
|
||||
* The difference here is that this function is meant to used for data
|
||||
* associated with a file. There is no technical reason to do it that way, just
|
||||
* that all data associated with a file, including its actual contents, use the
|
||||
* same underlying (streaming) libsodium APIs. While other independent free
|
||||
* standing encryption needs are covered using the secretbox APIs.
|
||||
* associated with a file (or some other Ente object, like a collection or an
|
||||
* entity). There is no technical reason to do it that way, just this way all
|
||||
* data associated with a file, including its actual contents, use the same
|
||||
* underlying (streaming) libsodium APIs. In other cases, where we have free
|
||||
* standing independent data, we continue using the secretbox APIs for one shot
|
||||
* encryption and decryption.
|
||||
*
|
||||
* @param data A {@link Uint8Array} containing the bytes that we want to
|
||||
* encrypt.
|
||||
*
|
||||
* @param keyB64 Base64 encoded string containing the encryption key. This is
|
||||
* usually be the key associated with a file to which {@link data} relates to.
|
||||
* @param keyB64 A base64 string containing the encryption key.
|
||||
*
|
||||
* @returns The encrypted data (bytes) and decryption header pair (Base64
|
||||
* @returns The encrypted data (bytes) and decryption header pair (base64
|
||||
* encoded string). Both these values are needed to decrypt the data. The header
|
||||
* does not need to be secret.
|
||||
*/
|
||||
@@ -254,10 +255,10 @@ export async function encryptFileChunk(
|
||||
*
|
||||
* @param encryptedData A {@link Uint8Array} containing the bytes to decrypt.
|
||||
*
|
||||
* @param header A Base64 string containing the bytes of the decryption header
|
||||
* @param header A base64 string containing the bytes of the decryption header
|
||||
* that was produced during encryption.
|
||||
*
|
||||
* @param keyB64 The Base64 string containing the key that was used to encrypt
|
||||
* @param keyB64 The base64 string containing the key that was used to encrypt
|
||||
* the data.
|
||||
*
|
||||
* @returns The decrypted bytes.
|
||||
@@ -528,7 +529,7 @@ export async function generateSaltToDeriveKey() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new public/private keypair, and return their Base64
|
||||
* Generate a new public/private keypair, and return their base64
|
||||
* representations.
|
||||
*/
|
||||
export const generateKeyPair = async () => {
|
||||
|
||||
Reference in New Issue
Block a user