Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/src/queue/document.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ export class DocumentProcessor implements OnModuleDestroy {
const { txHash, ledger } = await this.stellarService.anchorHash(
document.fileHash,
);

const isAnchored = await this.stellarService.verifyHash(document.fileHash);
if (!isAnchored) {
this.logger.error(
`Document ${documentId} hash not found on Stellar after anchoring`,
);
await this.verificationService.create({
documentId,
stellarTxHash: txHash,
stellarLedger: ledger,
anchoredAt: new Date(),
status: VerificationStatus.FAILED,
});
return;
}

await this.verificationService.create({
documentId,
stellarTxHash: txHash,
Expand Down
34 changes: 25 additions & 9 deletions backend/src/verification/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Throttle } from '@nestjs/throttler';

import { DocumentsService } from '../documents/documents.service';
import { VerificationService } from './verification.service';
import { VerificationCacheService } from './verification-cache.service';

// Stricter rate limiting for public endpoint (10 requests per minute)
@Throttle({ default: { ttl: 60000, limit: 10 } })
Expand All @@ -11,6 +12,7 @@ export class VerificationController {
constructor(
private readonly documentsService: DocumentsService,
private readonly verificationService: VerificationService,
private readonly verificationCache: VerificationCacheService,
) {}

@Get(':hash')
Expand All @@ -22,33 +24,47 @@ export class VerificationController {
);
}

// Check cache first
const cached = this.verificationCache.get(hash);
if (cached !== undefined) {
return cached;
}

// Look up document by file hash
const document = await this.documentsService.findByFileHash(hash);
if (!document) {
return {
const response = {
verified: false,
message: 'Document not found',
documentStatus: null,
};
this.verificationCache.set(hash, response);
return response;
}

// Get the latest verification record
const record = await this.verificationService.findLatestByDocument(
document.id,
);

let response;
if (!record) {
return {
response = {
verified: false,
message: 'Document has not been verified on Stellar',
documentStatus: document.status,
};
} else {
response = {
verified: true,
stellarTxHash: record.stellarTxHash,
stellarLedger: record.stellarLedger,
anchoredAt: record.anchoredAt,
documentStatus: document.status,
};
}

// Return only verification status - no document metadata
return {
verified: true,
stellarTxHash: record.stellarTxHash,
stellarLedger: record.stellarLedger,
anchoredAt: record.anchoredAt,
};
this.verificationCache.set(hash, response);
return response;
}
}
Loading