diff --git a/common/src/hedera-modules/message/vc-message.ts b/common/src/hedera-modules/message/vc-message.ts index a4e7e22e5f..5db00eac88 100644 --- a/common/src/hedera-modules/message/vc-message.ts +++ b/common/src/hedera-modules/message/vc-message.ts @@ -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]); diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts index 9cce887a18..99fbb8014f 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts @@ -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); } @@ -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 { diff --git a/policy-service/src/policy-engine/blocks/messages-report-block.ts b/policy-service/src/policy-engine/blocks/messages-report-block.ts index 5ee6f16930..7f6ef14bb9 100644 --- a/policy-service/src/policy-engine/blocks/messages-report-block.ts +++ b/policy-service/src/policy-engine/blocks/messages-report-block.ts @@ -65,8 +65,15 @@ export class MessagesReportBlock { private async createReport(user: PolicyUser, messageId: string): Promise { const ref = PolicyComponentsUtils.GetBlockRef(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(this.USER_REPORT, report.toJson(), user); await ref.setShortCache(this.USER_REPORT_STATUS, 'FINISHED', user); this.updateStatus(ref, 'FINISHED', user); diff --git a/policy-service/src/policy-engine/helpers/messages-report.ts b/policy-service/src/policy-engine/helpers/messages-report.ts index cae9e2c8d8..d212c6533f 100644 --- a/policy-service/src/policy-engine/helpers/messages-report.ts +++ b/policy-service/src/policy-engine/helpers/messages-report.ts @@ -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 @@ -64,7 +66,7 @@ export class MessagesReport { */ private readonly users: Map; - constructor() { + constructor(private _ref: IPolicyReportBlock) { this.topics = new Map(); this.messages = new Map(); this.schemas = new Map(); @@ -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(); } @@ -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 @@ -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; } @@ -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); } } @@ -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; } @@ -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);