Skip to content

Commit

Permalink
Add spliting of public assertion for publish insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic committed Dec 10, 2024
1 parent 6b19986 commit 6405b18
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/service/data-service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ethers } from 'ethers';
import { kcTools } from 'assertion-tools';
import { XML_DATA_TYPES } from '../constants/constants.js';

Expand Down Expand Up @@ -67,6 +68,44 @@ class DataService {
return value;
}
}

generateHashFromString(string) {
return ethers.utils.sha256(ethers.util.solidityPack(['string'], [string]));
}

splitConnectedArrays(publicTriples) {
const groupedPublic = [];
let currentSubject = publicTriples[0].split(' ')[0];
let currentSubjectHash = currentSubject.startsWith('<private-hash:0x')
? currentSubject
: `<private-hash:${this.generateHashFromString(currentSubject.slice(1, -1))}>`;
let currentKA = [publicTriples[0]];

for (let i = 1; i < publicTriples.length; i += 1) {
const subject = publicTriples[i].split(' ')[0];
const subjectHash = subject.startsWith('<private-hash:0x')
? subject
: `<private-hash:${this.generateHashFromString(subject.slice(1, -1))}>`;

if (
currentSubject === subject ||
currentSubjectHash === subject ||
subjectHash === currentSubject
) {
currentKA.push(publicTriples[i]);
} else {
groupedPublic.push(currentKA);
currentSubject = subject;
currentSubjectHash = subjectHash;
currentKA = [publicTriples[i]];
}
}

// Push the last group
groupedPublic.push(currentKA);

return groupedPublic;
}
}

export default DataService;

0 comments on commit 6405b18

Please sign in to comment.