Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
fix: temporarily disable content hash validation in DTOs (#152)
Browse files Browse the repository at this point in the history
# Description
Temporarily disable DTO validation of content hash-related fields until
we resolve questions/issues surrounding correct generation/validation
techniques.
  • Loading branch information
JoeCap08055 authored Jul 18, 2024
1 parent 1d60d76 commit 1c48c64
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions libs/common/src/utils/dsnp-validation.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,29 @@ function validateMsaIdString(msaId: string): boolean {
}

const hexRe = /^(?:0x)?(?<hexString>f[0-9a-f]+)$/i;
function validateContentHash(contentHash: string): boolean {
try {
const hexMatch = hexRe.exec(contentHash);
if (hexMatch && hexMatch?.groups) {
const { hexString } = hexMatch.groups;
const decoded = base16.decode(hexString.toLowerCase());
CID.decode(decoded);
} else {
const cid = CID.parse(contentHash);
console.log(cid.toString(base16.encoder));
}
} catch (err: any) {
console.error(`Invalid multiformat content hash: ${err.message}`);
return false;
}

function validateContentHash(contentHash: string): boolean {
// TODO: disabling this check for the moment until we figure out
// what the problem is with validating content hashes. Either we're using
// an incorrect method to generate them in content-publisher, or we're not
// validating them properly here.
return true;

// try {
// const hexMatch = hexRe.exec(contentHash);
// if (hexMatch && hexMatch?.groups) {
// const { hexString } = hexMatch.groups;
// const decoded = base16.decode(hexString.toLowerCase());
// CID.decode(decoded);
// } else {
// CID.parse(contentHash);
// }
// } catch (err: any) {
// console.error(`Invalid multiformat content hash: ${err.message}`);
// return false;
// }

// return true;
}

export function IsDsnpUserURI(validationOptions?: ValidationOptions) {
Expand Down

0 comments on commit 1c48c64

Please sign in to comment.