1 import { VERIFICATION_STATUS } from '@proton/crypto'
2 import type { UseCaseInterface } from '../Domain/UseCase/UseCaseInterface'
3 import { Result } from '@proton/docs-shared'
4 import type { EncryptionService } from '../Services/Encryption/EncryptionService'
5 import type { EncryptionContext } from '../Services/Encryption/EncryptionContext'
6 import type { DecryptedMessage } from '@proton/docs-shared'
7 import type { VerificationUsecaseResult, SingleMessageVerificationResult } from './VerifyUpdatesResult'
9 export class VerifyMessages implements UseCaseInterface<VerificationUsecaseResult> {
10 constructor(private encryption: EncryptionService<EncryptionContext.RealtimeMessage>) {}
12 async execute(dto: { messages: DecryptedMessage[] }): Promise<Result<VerificationUsecaseResult>> {
13 const results: SingleMessageVerificationResult[] = []
14 let hasFailure = false
16 for (const message of dto.messages) {
17 const verificationKey = await this.encryption.getVerificationKey(message.authorAddress)
19 if (verificationKey.isFailed()) {
27 const verifyResult = await this.encryption.verifyData(
31 verificationKey.getValue(),
34 if (verifyResult.isFailed()) {
42 const verifyValue = verifyResult.getValue()
43 if (verifyValue !== VERIFICATION_STATUS.SIGNED_AND_VALID) {
58 allVerified: !hasFailure,