From 9c23e0e529b898dc7c0ac2eabcf1472de81e3df5 Mon Sep 17 00:00:00 2001 From: Jared Snider Date: Wed, 28 May 2025 17:52:29 -0400 Subject: [PATCH] PM-20532 - SendTokenSvc - wire up hash password --- .../abstractions/send-token.service.ts | 15 ++++++++++++++- .../send-access/services/send-token.service.ts | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libs/common/src/auth/send-access/abstractions/send-token.service.ts b/libs/common/src/auth/send-access/abstractions/send-token.service.ts index de8ea161523..ba6078534fe 100644 --- a/libs/common/src/auth/send-access/abstractions/send-token.service.ts +++ b/libs/common/src/auth/send-access/abstractions/send-token.service.ts @@ -1,3 +1,4 @@ +import { SendHashedPassword } from "../../../key-management/sends/send-password.service"; import { SendAccessToken } from "../models/send-access-token"; import { SendTokenRetrievalError } from "../services/send-token.service"; @@ -5,7 +6,7 @@ export type SendAccessCredentialsType = "password" | "email-otp"; export type SendPasswordCredentials = { type: "password"; - password: string; + password: SendHashedPassword; }; export type SendEmailOtpCredentials = { type: "email-otp"; @@ -14,6 +15,7 @@ export type SendEmailOtpCredentials = { }; export type SendAccessCredentials = SendPasswordCredentials | SendEmailOtpCredentials; +// TODO: add JSdocs export abstract class SendTokenService { // SendAccessTokens need to be stored in session storage once retrieved. // All SendAccessTokens are scoped to a specific send id so all getting and setting should accept a send id. @@ -37,4 +39,15 @@ export abstract class SendTokenService { sendId: string, sendAccessCredentials: SendAccessCredentials, ) => Promise; + + /** + * Hashes a password for send access. + * @param password The raw password string to hash. + * @param keyMaterialUrlB64 The base64 URL encoded key material string. + * @returns A promise that resolves to the hashed password as a SendHashedPassword. + */ + abstract hashPassword: ( + password: string, + keyMaterialUrlB64: string, + ) => Promise; } diff --git a/libs/common/src/auth/send-access/services/send-token.service.ts b/libs/common/src/auth/send-access/services/send-token.service.ts index 66e4d71b2c3..297fc1bb0c6 100644 --- a/libs/common/src/auth/send-access/services/send-token.service.ts +++ b/libs/common/src/auth/send-access/services/send-token.service.ts @@ -1,6 +1,10 @@ import { firstValueFrom } from "rxjs"; import { Jsonify } from "type-fest"; +import { + SendHashedPassword, + SendPasswordService, +} from "../../../key-management/sends/send-password.service"; import { GlobalState, GlobalStateProvider, @@ -16,6 +20,9 @@ import { SendAccessToken } from "../models/send-access-token"; import { SendTokenApiRetrievalError, SendTokenApiService } from "./send-token-api.service"; +// TODO: add JSDocs +// TODO: add tests for this service. + export const SEND_ACCESS_TOKEN_DICT = KeyDefinition.record( SEND_ACCESS_DISK, "accessTokenDict", @@ -34,6 +41,7 @@ export class SendTokenService implements SendTokenServiceAbstraction { constructor( private globalStateProvider: GlobalStateProvider, private sendTokenApiService: SendTokenApiService, + private sendPasswordService: SendPasswordService, ) { this.initializeState(); } @@ -83,6 +91,10 @@ export class SendTokenService implements SendTokenServiceAbstraction { // const result = await this.sendTokenApiService.requestSendAccessToken(request); } + async hashPassword(password: string, keyMaterialUrlB64: string): Promise { + return this.sendPasswordService.hashPassword(password, keyMaterialUrlB64); + } + private async getSendAccessTokenFromStorage( sendId: string, ): Promise {