<%* // Record start time for entire script runtime const startTime = performance.now();

// Import necessary modules const crypto = require(‘crypto’);

// Function to compute a 12-character SHA-256 hash function computeHash(text) { const fullHash = crypto.createHash(‘sha256’).update(text).digest(‘hex’); return fullHash.slice(0, 12); }

// Function to normalize the text block without modifying the original text function getNormalizedText(block) { // Create a copy of the block to normalize let normalizedBlock = block;

// Strip markdown prefixes (e.g., headers, bold, italic)
normalizedBlock = normalizedBlock.replace(/^#+\s+/gm, ''); // Headers
normalizedBlock = normalizedBlock.replace(/[*_]{1,3}([^*_]+)[*_]{1,3}/g, '$1'); // Bold and Italics

// Remove ordered lists, lists, and todos
normalizedBlock = normalizedBlock.replace(/^\s*[-*+]\s+/gm, ''); // Unordered lists
normalizedBlock = normalizedBlock.replace(/^\s*\d+\.\s+/gm, ''); // Ordered lists
normalizedBlock = normalizedBlock.replace(/^\s*[-*+]\s+\[.\]\s+/gm, ''); // Todos

// Remove Digest Link and Seal Link
normalizedBlock = normalizedBlock.replace(/\[\^ds\/[a-f0-9]{12}\/\d{4}-\d{2}-\d{2}\^\]/g, '');
normalizedBlock = normalizedBlock.replace(/\s\^ds-\d{4}-\d{2}-\d{2}-[a-f0-9]{12}/g, '');

return normalizedBlock.trim();

}

// Function to verify digest function verifyDigest(content, digestHash) { const normalizedContent = getNormalizedText(content); const computedDigest = computeHash(normalizedContent); return computedDigest === digestHash; }

// Function to verify seal function verifySeal(content, sealHash) { const computedSealHash = computeHash(content); return computedSealHash === sealHash; }

// Get the currently selected text in Obsidian console.log([${new Date().toISOString()}] Getting selected text); let selection = app.workspace.activeEditor.getSelection();

// Check if no text is selected if (!selection || selection.trim() === ”) { const noSelectionError = “No text selected. Please select the text you want to verify and copy.”; new Notice(noSelectionError); console.error([${new Date().toISOString()}] ${noSelectionError}); throw new Error(noSelectionError); }

// Calculate text statistics const wordCount = selection.trim().split(/\s+/).length; const charCount = selection.length; const lineCount = selection.split(‘\n’).length;

// Get normalized content const normalizedContent = getNormalizedText(selection);

// Log normalized content console.log([${new Date().toISOString()}] Normalized Content:\n${normalizedContent});

// Check for Digest Links const digestLinkMatches = […selection.matchAll(/[^ds/([a-f0-9]{12})/(\d{4}-\d{2}-\d{2})^]/g)]; let digestVerificationResult = “No Digest Link found.”; if (digestLinkMatches.length > 0) { if (digestLinkMatches.length > 1) { const warningMessage = Warning: Multiple Digest Links found (${digestLinkMatches.length}).; console.warn([${new Date().toISOString()}] ${warningMessage}); new Notice(warningMessage); }

digestVerificationResult = digestLinkMatches.map((match, index) => {
    const [fullDigestLink, digestHash, digestDate] = match;
    console.log(`[${new Date().toISOString()}] Digest Link ${index + 1} found: ${fullDigestLink}`);
    
    if (verifyDigest(selection, digestHash)) {
        return `Digest ${index + 1} verified successfully. Date: ${digestDate}`;
    } else {
        return `Digest ${index + 1} verification failed. Content may have been modified.`;
    }
}).join('\n');

}

// Check for Seal Links const sealLinkMatches = […selection.matchAll(/\s(^ds-(\d{4}-\d{2}-\d{2})-([a-f0-9]{12}))/g)]; let sealVerificationResult = “No Seal Link found.”; if (sealLinkMatches.length > 0) { if (sealLinkMatches.length > 1) { const warningMessage = Warning: Multiple Seal Links found (${sealLinkMatches.length}).; console.warn([${new Date().toISOString()}] ${warningMessage}); new Notice(warningMessage); }

sealVerificationResult = sealLinkMatches.map((match, index) => {
    const [fullSealLink, _, sealDate, sealHash] = match;
    console.log(`[${new Date().toISOString()}] Seal Link ${index + 1} found: ${fullSealLink}`);
    
    const contentWithoutSeal = selection.slice(0, selection.lastIndexOf(fullSealLink)).trim();
    if (verifySeal(contentWithoutSeal, sealHash)) {
        return `Seal ${index + 1} verified successfully. Date: ${sealDate}`;
    } else {
        return `Seal ${index + 1} verification failed. Content may have been modified.`;
    }
}).join('\n');

}

// Calculate verification time const endTime = performance.now(); const verificationTime = ((endTime - startTime) / 1000).toFixed(6);

// Create the verification report const verificationReport = Date Seal 1.5 Verification Report: ${digestVerificationResult} ${sealVerificationResult} Word Count: ${wordCount} Character Count: ${charCount} Line Count: ${lineCount} Verification Time: ${verificationTime} seconds;

// Display the verification report new Notice(verificationReport, 7000); console.log([${new Date().toISOString()}] ${verificationReport});

// Copy the selected text to clipboard without modification await navigator.clipboard.writeText(selection); console.log([${new Date().toISOString()}] Selected text copied to clipboard without modification); new Notice(“Selected text copied to clipboard without modification”);

%>