From ce6631359b73fdebf906b896759c97ea058f2e90 Mon Sep 17 00:00:00 2001 From: JlincFM Date: Wed, 6 May 2026 12:05:03 +0000 Subject: [PATCH] updated validation routines --- .continueignore | 2 ++ src/common/config.js | 1 + src/common/queue.js | 25 +++++++++++++++++----- src/modules/core/data/audit.js | 38 +++++++++++++++++++++++++++++++--- 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 .continueignore diff --git a/.continueignore b/.continueignore new file mode 100644 index 0000000..6b26f0a --- /dev/null +++ b/.continueignore @@ -0,0 +1,2 @@ +/data +docker-compose.*.yml \ No newline at end of file diff --git a/src/common/config.js b/src/common/config.js index 2853398..5b1bb93 100644 --- a/src/common/config.js +++ b/src/common/config.js @@ -34,6 +34,7 @@ export async function loadConfig() { } if (process.env.PDP_TYPE) config.pdpType = process.env.PDP_TYPE; if (process.env.PDP_URL) config.pdpUrl = process.env.PDP_URL; + if (process.env.INSTANT_QUEUE) config.instantQueue = process.env.INSTANT_QUEUE; } export function getConfig() { diff --git a/src/common/queue.js b/src/common/queue.js index 2cd2e1b..479e9fc 100644 --- a/src/common/queue.js +++ b/src/common/queue.js @@ -1,3 +1,4 @@ +import { getConfig } from "../common/config.js"; import { getPool } from "../db/index.js"; import { sleep } from "./sleep.js"; import axios from 'axios'; @@ -67,6 +68,10 @@ export async function putQueue(client, type, url, headers, data) { headers, data ]); + const config = getConfig(); + if (config.instantQueue) { + await processBatch(client, type); + } } async function updateQueue(client, item, lastFail) { @@ -165,18 +170,28 @@ async function processBatch(client, type) { return queueList.length; } -async function watchQueue(client, type) { - const repeat = 30 * 1000; // seconds +async function processQueue(client, type) { while (true) { const count = await processBatch(client, type); if (count === 0) { - await sleep(repeat); + break; } } } +async function watchQueue(client, type) { + const repeat = 30 * 1000; // seconds + while (true) { + await processQueue(client, type); + await sleep(repeat); + } +} + export async function watchAudits() { const client = await getPool(); - await watchQueue(client, 'audit'); - await client.release(); + const config = getConfig(); + if (!config.instantQueue) { + await watchQueue(client, 'audit'); + await client.release(); + } } diff --git a/src/modules/core/data/audit.js b/src/modules/core/data/audit.js index ea131d0..97d1b3c 100644 --- a/src/modules/core/data/audit.js +++ b/src/modules/core/data/audit.js @@ -73,6 +73,23 @@ function validateSignatures(item, signatures, didDocs) { return res; } +function validateDidsMatch(auditSigs, targetSigs) { + let match = true; + for (const asig of auditSigs) { + let found = false; + for (const tsig of targetSigs) { + if (tsig.id === asig.id) { + found = true; + break; + } + } + if (!found) { + match = false; + } + } + return match; +} + function generateDigest(content, length) { if (typeof content === 'object') { content = stringify(content); @@ -128,7 +145,7 @@ async function verify(input, userId) { const existingSignatures = item.eventId ? await event.getSignatures(client, userId, item.eventId) : await agreement.getSignatures(client, userId, item.agreementId) - // Does the agreement signature verify? + // Does the agreement/event signature verify? let validSignature = false; if (validateSignatures(existingItem, existingSignatures, input.didDocs)) { validSignature = true; @@ -143,12 +160,14 @@ async function verify(input, userId) { validAuditSignature: false, } } - // Do the agreement IDs match? + // Do the agreement/event IDs match? if ( (item.agreementId !== null && auditRecord.audit.agreementId === item.agreementId) || (item.eventId !== null && auditRecord.audit.eventId === item.eventId) - ) + ) res.results.validId = true; + // Do DID IDs match between audit and target object? + res.results.validMatchingDids = validateDidsMatch(auditRecord.signatures, existingSignatures); // Does the audit hash match? // The digest was created from whichever signatures this audit record has const signatures = []; @@ -184,6 +203,19 @@ async function verify(input, userId) { } else { data.invalid.push(res); } + // If an event, has the DID signed the agreement and is that signature valid? + if (existingItem.eventId !== null && existingItem.agreementId !== '00000000-0000-0000-0000-000000000000') { + const existingAgreement = await agreement.getAgreement(client, userId, existingItem.agreementId); + const existingAgreementSignatures = await agreement.getSignatures(client, userId, existingItem.agreementId); + res.results.validAgreement = validateDidsMatch(auditRecord.signatures, existingAgreementSignatures); + res.results.validAgreementSignature = false; + if (validateSignatures(existingAgreement, existingAgreementSignatures, input.didDocs)) { + res.results.validAgreementSignature = true; + } + } else { + res.results.validAgreement = true; + res.results.validAgreementSignature = true; + } } } response = {