diff --git a/src/service/data-service.js b/src/service/data-service.js index 652ea5d61..9b6412be0 100644 --- a/src/service/data-service.js +++ b/src/service/data-service.js @@ -1,3 +1,4 @@ +import { ethers } from 'ethers'; import { kcTools } from 'assertion-tools'; import { XML_DATA_TYPES } from '../constants/constants.js'; @@ -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('`; + let currentKA = [publicTriples[0]]; + + for (let i = 1; i < publicTriples.length; i += 1) { + const subject = publicTriples[i].split(' ')[0]; + const subjectHash = subject.startsWith('`; + + 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;