updated validation routines
This commit is contained in:
2
.continueignore
Normal file
2
.continueignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/data
|
||||||
|
docker-compose.*.yml
|
||||||
@@ -34,6 +34,7 @@ export async function loadConfig() {
|
|||||||
}
|
}
|
||||||
if (process.env.PDP_TYPE) config.pdpType = process.env.PDP_TYPE;
|
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.PDP_URL) config.pdpUrl = process.env.PDP_URL;
|
||||||
|
if (process.env.INSTANT_QUEUE) config.instantQueue = process.env.INSTANT_QUEUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConfig() {
|
export function getConfig() {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getConfig } from "../common/config.js";
|
||||||
import { getPool } from "../db/index.js";
|
import { getPool } from "../db/index.js";
|
||||||
import { sleep } from "./sleep.js";
|
import { sleep } from "./sleep.js";
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
@@ -67,6 +68,10 @@ export async function putQueue(client, type, url, headers, data) {
|
|||||||
headers,
|
headers,
|
||||||
data
|
data
|
||||||
]);
|
]);
|
||||||
|
const config = getConfig();
|
||||||
|
if (config.instantQueue) {
|
||||||
|
await processBatch(client, type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateQueue(client, item, lastFail) {
|
async function updateQueue(client, item, lastFail) {
|
||||||
@@ -165,18 +170,28 @@ async function processBatch(client, type) {
|
|||||||
return queueList.length;
|
return queueList.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function watchQueue(client, type) {
|
async function processQueue(client, type) {
|
||||||
const repeat = 30 * 1000; // seconds
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const count = await processBatch(client, type);
|
const count = await processBatch(client, type);
|
||||||
if (count === 0) {
|
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() {
|
export async function watchAudits() {
|
||||||
const client = await getPool();
|
const client = await getPool();
|
||||||
await watchQueue(client, 'audit');
|
const config = getConfig();
|
||||||
await client.release();
|
if (!config.instantQueue) {
|
||||||
|
await watchQueue(client, 'audit');
|
||||||
|
await client.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,23 @@ function validateSignatures(item, signatures, didDocs) {
|
|||||||
return res;
|
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) {
|
function generateDigest(content, length) {
|
||||||
if (typeof content === 'object') {
|
if (typeof content === 'object') {
|
||||||
content = stringify(content);
|
content = stringify(content);
|
||||||
@@ -128,7 +145,7 @@ async function verify(input, userId) {
|
|||||||
const existingSignatures = item.eventId
|
const existingSignatures = item.eventId
|
||||||
? await event.getSignatures(client, userId, item.eventId)
|
? await event.getSignatures(client, userId, item.eventId)
|
||||||
: await agreement.getSignatures(client, userId, item.agreementId)
|
: await agreement.getSignatures(client, userId, item.agreementId)
|
||||||
// Does the agreement signature verify?
|
// Does the agreement/event signature verify?
|
||||||
let validSignature = false;
|
let validSignature = false;
|
||||||
if (validateSignatures(existingItem, existingSignatures, input.didDocs)) {
|
if (validateSignatures(existingItem, existingSignatures, input.didDocs)) {
|
||||||
validSignature = true;
|
validSignature = true;
|
||||||
@@ -143,12 +160,14 @@ async function verify(input, userId) {
|
|||||||
validAuditSignature: false,
|
validAuditSignature: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do the agreement IDs match?
|
// Do the agreement/event IDs match?
|
||||||
if (
|
if (
|
||||||
(item.agreementId !== null && auditRecord.audit.agreementId === item.agreementId) ||
|
(item.agreementId !== null && auditRecord.audit.agreementId === item.agreementId) ||
|
||||||
(item.eventId !== null && auditRecord.audit.eventId === item.eventId)
|
(item.eventId !== null && auditRecord.audit.eventId === item.eventId)
|
||||||
)
|
)
|
||||||
res.results.validId = true;
|
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?
|
// Does the audit hash match?
|
||||||
// The digest was created from whichever signatures this audit record has
|
// The digest was created from whichever signatures this audit record has
|
||||||
const signatures = [];
|
const signatures = [];
|
||||||
@@ -184,6 +203,19 @@ async function verify(input, userId) {
|
|||||||
} else {
|
} else {
|
||||||
data.invalid.push(res);
|
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 = {
|
response = {
|
||||||
|
|||||||
Reference in New Issue
Block a user