This commit is contained in:
2026-05-10 18:25:58 +01:00
parent 165af509ef
commit e4f4992a1b
31 changed files with 2708 additions and 495 deletions

View File

@@ -23,7 +23,11 @@
import { ethers } from "ethers";
import { createHash } from "crypto";
import type { BlockchainProof, BlockchainVerification, BlockchainStats } from "./blockchain.types";
import type {
BlockchainProof,
BlockchainVerification,
BlockchainStats,
} from "./blockchain.types";
// ─────────────────────────────────────────────────
// Smart Contract ABI (Application Binary Interface)
@@ -102,7 +106,7 @@ function getReadContract(): ethers.Contract {
_readContract = new ethers.Contract(
contractAddress,
DOCUMENT_REGISTRY_ABI,
getProvider()
getProvider(),
);
}
return _readContract;
@@ -117,7 +121,7 @@ function getWriteContract(): ethers.Contract {
_writeContract = new ethers.Contract(
contractAddress,
DOCUMENT_REGISTRY_ABI,
getWallet()
getWallet(),
);
}
return _writeContract;
@@ -214,7 +218,7 @@ export class BlockchainService {
*/
static async registerOnChain(
documentHash: string,
fileName: string
fileName: string,
): Promise<BlockchainProof> {
if (!this.isConfigured()) {
throw new Error("Blockchain not configured. Check your .env variables.");
@@ -307,7 +311,7 @@ export class BlockchainService {
* @returns Verification result with existence, timestamp, depositor
*/
static async verifyOnChain(
documentHash: string
documentHash: string,
): Promise<BlockchainVerification> {
if (!this.isReadConfigured()) {
throw new Error("Blockchain read access not configured");
@@ -331,7 +335,7 @@ export class BlockchainService {
*/
static async hashAndRegister(
fileUrl: string,
fileName: string
fileName: string,
): Promise<BlockchainProof> {
const documentHash = await this.hashDocument(fileUrl);
return await this.registerOnChain(documentHash, fileName);
@@ -368,13 +372,14 @@ export class BlockchainService {
const [blockNumber, totalDocs, networkObj] = await Promise.all([
provider.getBlockNumber(),
contract.totalDocuments(),
provider.getNetwork()
provider.getNetwork(),
]);
return {
totalVerified: Number(totalDocs),
latestBlockNumber: blockNumber,
networkName: config.network === "sepolia" ? "Ethereum Sepolia" : "Hardhat Local",
networkName:
config.network === "sepolia" ? "Ethereum Sepolia" : "Hardhat Local",
networkStatus: "connected",
walletAddress,
chainId: Number(networkObj.chainId),
@@ -384,7 +389,8 @@ export class BlockchainService {
return {
totalVerified: 0,
latestBlockNumber: null,
networkName: config.network === "sepolia" ? "Ethereum Sepolia" : "Hardhat Local",
networkName:
config.network === "sepolia" ? "Ethereum Sepolia" : "Hardhat Local",
networkStatus: "disconnected",
walletAddress: "",
};