<%* // 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 function normalizeText(block) { // Strip markdown prefixes (e.g., headers, bold, italic) block = block.replace(/^#+\s+/gm, ”); // Headers block = block.replace(/[_]{1,3}([^]+)[*]{1,3}/g, ‘$1’); // Bold and Italics

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

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

return block.trim();

}

// Function to verify digest function verifyDigest(content, digestHash) { const normalizedContent = normalizeText(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); }

// Check for Digest Link const digestLinkMatch = selection.match(/[^ds/([a-f0-9]{12})/(\d{4}-\d{2}-\d{2})^]/); let digestVerificationResult = “No Digest Link found.”; if (digestLinkMatch) { const [fullDigestLink, digestHash, digestDate] = digestLinkMatch; console.log([${new Date().toISOString()}] Digest Link found: ${fullDigestLink});

if (verifyDigest(selection, digestHash)) {
    digestVerificationResult = `Digest verified successfully. Date: ${digestDate}`;
    console.log(`[${new Date().toISOString()}] ${digestVerificationResult}`);
} else {
    digestVerificationResult = "Digest verification failed. Content may have been modified.";
    console.warn(`[${new Date().toISOString()}] ${digestVerificationResult}`);
}

}

// Check for Seal Link const sealLinkMatch = selection.match(/\s(^ds-(\d{4}-\d{2}-\d{2})-([a-f0-9]{12}))/); let sealVerificationResult = "No Seal Link found."; if (sealLinkMatch) { const [fullSealLink, _, sealDate, sealHash] = sealLinkMatch; console.log(`[{new Date().toISOString()}] Seal Link found: ${fullSealLink}`);

const contentWithoutSeal = selection.replace(fullSealLink, '').trim();
if (verifySeal(contentWithoutSeal, sealHash)) {
    sealVerificationResult = `Seal verified successfully. Date: ${sealDate}`;
    console.log(`[${new Date().toISOString()}] ${sealVerificationResult}`);
} else {
    sealVerificationResult = "Seal verification failed. Content may have been modified.";
    console.warn(`[${new Date().toISOString()}] ${sealVerificationResult}`);
}

}

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

// Create the verification report const verificationReport = Date Seal Verification Report: ${digestVerificationResult} ${sealVerificationResult} Verification Time: ${verificationTime} seconds;

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

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

%>