π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Preserve SRP auth response schema fields
Manav Rathief2d729087b9
diff --git a/web/packages/accounts-rs/services/user.ts b/web/packages/accounts-rs/services/user.tsindex 361400cd2b..334d6e607a 100644--- a/web/packages/accounts-rs/services/user.ts+++ b/web/packages/accounts-rs/services/user.ts@@ -559,21 +559,33 @@ export interface EmailOrSRPVerificationResponse {** See: [Note: Duplicated Zod schema and TypeScript type]*/-const RemoteEmailOrSRPVerificationResponse = 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),- accountsUrl: z.string().nullish().transform(nullToUndefined),- twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),- })- .refine((r) => (r.passkeySessionID ? !!r.accountsUrl : true), {- path: ["accountsUrl"],- message: "accountsUrl is required when passkeySessionID is present",- });+const RemoteEmailOrSRPVerificationResponseBase = 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),+ accountsUrl: z.string().nullish().transform(nullToUndefined),+ twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),+});++const requireAccountsUrlForPasskey = <+ T extends { passkeySessionID?: string; accountsUrl?: string },+>(+ response: T,+) => (response.passkeySessionID ? !!response.accountsUrl : true);++const accountsUrlForPasskeyRefinement = {+ path: ["accountsUrl"],+ message: "accountsUrl is required when passkeySessionID is present",+};++const RemoteEmailOrSRPVerificationResponse =+ RemoteEmailOrSRPVerificationResponseBase.refine(+ requireAccountsUrlForPasskey,+ accountsUrlForPasskeyRefinement,+ );/*** A specialization of {@link RemoteEmailOrSRPVerificationResponse} for SRP@@ -583,14 +595,17 @@ const RemoteEmailOrSRPVerificationResponse = z* The declaration conceptually belongs to `srp.ts`, but is here to avoid cyclic* dependencies.*/-export const RemoteSRPVerificationResponse = z.object({- ...RemoteEmailOrSRPVerificationResponse.shape,- /**- * The SRP M2 (evidence message), the proof that the server has the- * verifier.- */- srpM2: z.string(),-});+export const RemoteSRPVerificationResponse =+ RemoteEmailOrSRPVerificationResponseBase.extend({+ /**+ * The SRP M2 (evidence message), the proof that the server has the+ * verifier.+ */+ srpM2: z.string(),+ }).refine(+ requireAccountsUrlForPasskey,+ accountsUrlForPasskeyRefinement,+ );/*** Verify user's access to the given {@link email} by comparing the OTT thatdiff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.tsindex f13f620001..7987c50446 100644--- a/web/packages/accounts/services/user.ts+++ b/web/packages/accounts/services/user.ts@@ -524,21 +524,33 @@ export interface EmailOrSRPVerificationResponse {** See: [Note: Duplicated Zod schema and TypeScript type]*/-const RemoteEmailOrSRPVerificationResponse = 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),- accountsUrl: z.string().nullish().transform(nullToUndefined),- twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),- })- .refine((r) => (r.passkeySessionID ? !!r.accountsUrl : true), {- path: ["accountsUrl"],- message: "accountsUrl is required when passkeySessionID is present",- });+const RemoteEmailOrSRPVerificationResponseBase = 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),+ accountsUrl: z.string().nullish().transform(nullToUndefined),+ twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),+});++const requireAccountsUrlForPasskey = <+ T extends { passkeySessionID?: string; accountsUrl?: string },+>(+ response: T,+) => (response.passkeySessionID ? !!response.accountsUrl : true);++const accountsUrlForPasskeyRefinement = {+ path: ["accountsUrl"],+ message: "accountsUrl is required when passkeySessionID is present",+};++const RemoteEmailOrSRPVerificationResponse =+ RemoteEmailOrSRPVerificationResponseBase.refine(+ requireAccountsUrlForPasskey,+ accountsUrlForPasskeyRefinement,+ );/*** A specialization of {@link RemoteEmailOrSRPVerificationResponse} for SRP@@ -548,14 +560,17 @@ const RemoteEmailOrSRPVerificationResponse = z* The declaration conceptually belongs to `srp.ts`, but is here to avoid cyclic* dependencies.*/-export const RemoteSRPVerificationResponse = z.object({- ...RemoteEmailOrSRPVerificationResponse.shape,- /**- * The SRP M2 (evidence message), the proof that the server has the- * verifier.- */- srpM2: z.string(),-});+export const RemoteSRPVerificationResponse =+ RemoteEmailOrSRPVerificationResponseBase.extend({+ /**+ * The SRP M2 (evidence message), the proof that the server has the+ * verifier.+ */+ srpM2: z.string(),+ }).refine(+ requireAccountsUrlForPasskey,+ accountsUrlForPasskeyRefinement,+ );/*** Verify user's access to the given {@link email} by comparing the OTT that