Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added evc to message report #4021

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/src/hedera-modules/message/vc-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class VCMessage extends Message {
serialized: documents[0],
passphrase: key,
});
this.document = bytesToUtf8(decrypted);
this.document = JSON.parse(bytesToUtf8(decrypted));
return this;
}
this.document = JSON.parse(documents[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class MessagesReportBlockComponent implements OnInit {
message.__issuer = this.getIssuer(message);
message.__documents = this.getVPDocuments(message);
}
if (message.type === 'VC-Document') {
if (['EVC-Document', 'VC-Document'].includes(message.type)) {
message.__schema = this.searchSchema(message);
message.__issuer = this.getIssuer(message);
}
Expand Down Expand Up @@ -831,7 +831,10 @@ export class MessagesReportBlockComponent implements OnInit {
}

private ifVCMessage(message: any): boolean {
return message.type === 'VC-Document' && message.__schemaName !== 'MintToken';
return (
['EVC-Document', 'VC-Document'].includes(message.type) &&
message.__schemaName !== 'MintToken'
);
}

private ifMintMessage(message: any): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ export class MessagesReportBlock {
private async createReport(user: PolicyUser, messageId: string): Promise<void> {
const ref = PolicyComponentsUtils.GetBlockRef<IPolicyReportBlock>(this);
try {
const report = new MessagesReport();
await report.start(messageId);
const report = new MessagesReport(ref);
const userWithCredentials = await PolicyUtils.getUserCredentials(
ref,
user.did
);
const account = await userWithCredentials.loadHederaCredentials(
ref
);
await report.start(messageId, account.hederaAccountKey);
await ref.setLongCache<IReport>(this.USER_REPORT, report.toJson(), user);
await ref.setShortCache<string>(this.USER_REPORT_STATUS, 'FINISHED', user);
this.updateStatus(ref, 'FINISHED', user);
Expand Down
31 changes: 21 additions & 10 deletions policy-service/src/policy-engine/helpers/messages-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
Workers
} from '@guardian/common';
import { TopicType, WorkerTaskType } from '@guardian/interfaces';
import { IPolicyReportBlock } from '../policy-engine.interface.js';
import { PolicyUtils } from './utils.js';

/**
* Trust Chain interface
Expand Down Expand Up @@ -64,7 +66,7 @@ export class MessagesReport {
*/
private readonly users: Map<string, any>;

constructor() {
constructor(private _ref: IPolicyReportBlock) {
this.topics = new Map<string, any>();
this.messages = new Map<string, any>();
this.schemas = new Map<string, any>();
Expand All @@ -76,8 +78,8 @@ export class MessagesReport {
* Build report
* @param messageId
*/
public async start(messageId: string) {
await this.checkMessage(messageId);
public async start(messageId: string, userKey: string) {
await this.checkMessage(messageId, userKey);
await this.checkUsers();
}

Expand All @@ -87,6 +89,7 @@ export class MessagesReport {
*/
private needDocument(message: Message): boolean {
return (
message.type === MessageType.EVCDocument ||
message.type === MessageType.VCDocument ||
message.type === MessageType.VPDocument ||
message.type === MessageType.RoleDocument
Expand All @@ -97,7 +100,7 @@ export class MessagesReport {
* Search messages
* @param timestamp
*/
private async checkMessage(timestamp: string) {
private async checkMessage(timestamp: string, userKey: string) {
if (this.messages.has(timestamp)) {
return;
}
Expand All @@ -109,17 +112,25 @@ export class MessagesReport {
}

if (this.needDocument(message)) {
await MessageServer.loadDocument(message);
try {
await MessageServer.loadDocument(message, userKey)
} catch (error) {
this._ref.error(
`Message report - load document: ${PolicyUtils.getErrorMessage(
error
)}`
);
}
}

this.messages.set(timestamp, message.toJson());
this.users.set(message.getOwner(), null);

await this.checkToken(message);
await this.checkTopic(message.getTopicId());
await this.checkTopic(message.getTopicId(), userKey);

for (const id of message.getRelationships()) {
await this.checkMessage(id);
await this.checkMessage(id, userKey);
}
}

Expand Down Expand Up @@ -157,7 +168,7 @@ export class MessagesReport {
* Search topics
* @param topicId
*/
private async checkTopic(topicId: string) {
private async checkTopic(topicId: string, userKey: string) {
if (this.topics.has(topicId)) {
return;
}
Expand All @@ -171,10 +182,10 @@ export class MessagesReport {
this.topics.set(topicId, message.toJson());

if (message.parentId) {
await this.checkTopic(message.parentId);
await this.checkTopic(message.parentId, userKey);
}
if (message.rationale) {
await this.checkMessage(message.rationale);
await this.checkMessage(message.rationale, userKey);
}

await this.checkSchemas(message);
Expand Down
Loading