Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rearrange

Manav Rathicbb35a8e3c77
diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.ts
index a6d6917290..3800c85fd8 100644
--- a/web/packages/accounts/services/srp.ts
+++ b/web/packages/accounts/services/srp.ts
@@ -582,8 +582,7 @@ export const srpVerificationUnauthorizedErrorMessage =
* @param kek The user's key encryption key as a base64 string.
*
* @returns If SRP verification is successful, it returns a
- * {@link UserVerificationResponse} (both email and SRP verification resolve to
- * this same structure).
+ * {@link UserVerificationResponse}.
*
* @throws An Error with {@link srpVerificationUnauthorizedErrorMessage} in case
* there is no such account, or if the credentials (kek) are incorrect.
@@ -647,6 +646,10 @@ interface VerifySRPSessionRequest {
const SRPVerificationResponse = z.object({
...EmailOrSRPVerificationResponse.shape,
+ /**
+ * The SRP M2 (evidence message), the proof that the server has the
+ * verifier.
+ */
srpM2: z.string(),
});
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts
index edaa25f09f..2990b54ec3 100644
--- a/web/packages/accounts/services/user.ts
+++ b/web/packages/accounts/services/user.ts
@@ -477,6 +477,32 @@ export const putUserRecoveryKeyAttributes = async (
}),
);
+/**
+ * Ask remote to send a OTP / OTT to the given email to verify that the user has
+ * access to it. Subsequent the app will pass this OTT back via the
+ * {@link verifyOTT} method.
+ *
+ * @param email The email to verify.
+ *
+ * @param purpose In which context is the email being verified. Remote applies
+ * additional business rules depending on this. For example, passing the purpose
+ * "login" ensures that the OTT is only sent to an already registered email.
+ *
+ * In cases where the purpose is ambiguous (e.g. we're not sure if it is an
+ * existing login or a new signup), the purpose can be set to `undefined`.
+ */
+export const sendOTT = async (
+ email: string,
+ purpose: "change" | "signup" | "login" | undefined,
+) =>
+ ensureOk(
+ await fetch(await apiURL("/users/ott"), {
+ method: "POST",
+ headers: publicRequestHeaders(),
+ body: JSON.stringify({ email, purpose }),
+ }),
+ );
+
export interface UserVerificationResponse {
id: number;
keyAttributes?: KeyAttributes | undefined;
@@ -502,30 +528,34 @@ export interface UserVerificationResponse {
}
/**
- * Ask remote to send a OTP / OTT to the given email to verify that the user has
- * access to it. Subsequent the app will pass this OTT back via the
- * {@link verifyOTT} method.
- *
- * @param email The email to verify.
- *
- * @param purpose In which context is the email being verified. Remote applies
- * additional business rules depending on this. For example, passing the purpose
- * "login" ensures that the OTT is only sent to an already registered email.
+ * Zod schema for response from remote on a successful user verification, either
+ * via {@link verifyEmail} or {@link verifySRP}.
*
- * In cases where the purpose is ambiguous (e.g. we're not sure if it is an
- * existing login or a new signup), the purpose can be set to `undefined`.
+ * If a second factor is enabled than one of the two factor session IDs
+ * (`passkeySessionID`, `twoFactorSessionID` / `twoFactorSessionIDV2`) will be
+ * set. Otherwise `keyAttributes` and `encryptedToken` will be set.
*/
-export const sendOTT = async (
- email: string,
- purpose: "change" | "signup" | "login" | undefined,
-) =>
- ensureOk(
- await fetch(await apiURL("/users/ott"), {
- method: "POST",
- headers: publicRequestHeaders(),
- body: JSON.stringify({ email, purpose }),
- }),
- );
+export const EmailOrSRPVerificationResponse = z.object({
+ id: z.number(),
+ keyAttributes: RemoteKeyAttributes.nullish().transform(nullToUndefined),
+ encryptedToken: z.string().nullish().transform(nullToUndefined),
+ token: z.string().nullish().transform(nullToUndefined),
+ twoFactorSessionID: z.string().nullish().transform(nullToUndefined),
+ passkeySessionID: z.string().nullish().transform(nullToUndefined),
+ // Base URL for the accounts app where we should redirect to for passkey
+ // verification.
+ accountsUrl: z.string().nullish().transform(nullToUndefined),
+ // TwoFactorSessionIDV2 is only set if user has both passkey and two factor
+ // enabled. This is to ensure older clients keep using passkey flow when
+ // both are set. It is intended to be removed once all clients starts
+ // surfacing both options for performing 2FA.
+ //
+ // See `useSecondFactorChoiceIfNeeded`.
+ twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),
+ // srpM2 is sent only if the user is logging via SRP. It is is the SRP M2
+ // value aka the proof that the server has the verifier.
+ srpM2: z.string().nullish().transform(nullToUndefined),
+});
/**
* Verify user's access to the given {@link email} by comparing the OTT that
@@ -557,36 +587,6 @@ export const verifyEmail = async (
return EmailOrSRPVerificationResponse.parse(await res.json());
};
-/**
- * Zod schema for response from remote on a successful user verification, either
- * via {@link verifyEmail} or {@link verifySRP}.
- *
- * If a second factor is enabled than one of the two factor session IDs
- * (`passkeySessionID`, `twoFactorSessionID` / `twoFactorSessionIDV2`) will be
- * set. Otherwise `keyAttributes` and `encryptedToken` will be set.
- */
-export const EmailOrSRPVerificationResponse = z.object({
- id: z.number(),
- keyAttributes: RemoteKeyAttributes.nullish().transform(nullToUndefined),
- encryptedToken: z.string().nullish().transform(nullToUndefined),
- token: z.string().nullish().transform(nullToUndefined),
- twoFactorSessionID: z.string().nullish().transform(nullToUndefined),
- passkeySessionID: z.string().nullish().transform(nullToUndefined),
- // Base URL for the accounts app where we should redirect to for passkey
- // verification.
- accountsUrl: z.string().nullish().transform(nullToUndefined),
- // TwoFactorSessionIDV2 is only set if user has both passkey and two factor
- // enabled. This is to ensure older clients keep using passkey flow when
- // both are set. It is intended to be removed once all clients starts
- // surfacing both options for performing 2FA.
- //
- // See `useSecondFactorChoiceIfNeeded`.
- twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),
- // srpM2 is sent only if the user is logging via SRP. It is is the SRP M2
- // value aka the proof that the server has the verifier.
- srpM2: z.string().nullish().transform(nullToUndefined),
-});
-
/**
* Log the user out on remote, if possible and needed.
*/