Skip to content

Commit

Permalink
Updated publish validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic committed Dec 16, 2024
1 parent 5f84fa7 commit ec30d04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ValidateAssetCommand from '../../../common/validate-asset-command.js';
import Command from '../../../command.js';
import { OPERATION_ID_STATUS, ZERO_BYTES32 } from '../../../../constants/constants.js';
import { OPERATION_ID_STATUS } from '../../../../constants/constants.js';

class PublishValidateAssetBlockchainCommand extends ValidateAssetCommand {
constructor(ctx) {
super(ctx);
this.operationService = ctx.publishService;
this.validationService = ctx.validationService;
}

async handleError(operationId, blockchain, errorMessage, errorType) {
Expand All @@ -29,37 +29,17 @@ class PublishValidateAssetBlockchainCommand extends ValidateAssetCommand {
blockchain,
OPERATION_ID_STATUS.VALIDATE_ASSET_BLOCKCHAIN_START,
);

const blockchainAssertionId =
await this.blockchainModuleManager.getKnowledgeCollectionMerkleRoot(
blockchain,
contract,
tokenId,
);
if (!blockchainAssertionId || blockchainAssertionId === ZERO_BYTES32) {
return Command.retry();
}

const { dataset: cachedData } = await this.operationIdService.getCachedOperationIdData(
operationId,
);
const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);
this.logger.debug(
`Validating asset's public assertion with id: ${datasetRoot} ual: ${ual}`,
);

if (blockchainAssertionId !== datasetRoot) {
await this.handleError(
operationId,
blockchain,
`Invalid assertion id for asset ${ual}. Received value from blockchain: ${blockchainAssertionId}, received value from request: ${datasetRoot}`,
this.errorType,
true,
);
return Command.empty();
}

await this.validationService.validateDatasetRoot(cachedData, datasetRoot);
await this.validationService.validateDatasetRootOnBlockchain(
datasetRoot,
blockchain,
contract,
tokenId,
);

await this.operationIdService.updateOperationIdStatus(
operationId,
Expand Down
10 changes: 4 additions & 6 deletions src/service/validation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ class ValidationService {
if (privateAssertionTriple) {
const privateAssertionRoot = privateAssertionTriple.split(' ')[2].slice(1, -1);

await this.validationService.validateDatasetRoot(
privateAssertion,
privateAssertionRoot,
await this.validateDatasetRoot(privateAssertion, privateAssertionRoot);
} else {
throw new Error(
`Merkle Root validation failed. Private Merkle Root not present in public assertion.`,
);
}
throw new Error(
`Merkle Root validation failed. Private Merkle Root not present in public assertion.`,
);
}
}

Expand Down

0 comments on commit ec30d04

Please sign in to comment.