Skip to content

Commit

Permalink
Fix validation of timestamp bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
orhoj committed Sep 5, 2023
1 parent bae4f9a commit 84c4f36
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/browser-wallet/src/background/web3Id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ function timestampToDate(attribute: TimestampAttribute): Date {
}

function validateTimestampAttribute(attributeTag: string, attributeValue: AttributeType) {
if (
isTimestampAttribute(attributeValue) &&
(timestampToDate(attributeValue).getTime() < MIN_DATE_TIMESTAMP ||
timestampToDate(attributeValue).getTime() > MAX_DATE_TIMESTAMP)
) {
return `The attribute [${attributeValue}] for key [${attributeTag}] is out of bounds for a Date. The Date must be between ${MIN_DATE_ISO} and ${MAX_DATE_ISO}`;
if (isTimestampAttribute(attributeValue)) {
const timestamp = timestampToDate(attributeValue).getTime();
if (Number.isNaN(timestamp)) {
return `The attribute [${attributeValue.timestamp}] for key [${attributeTag}] cannot be parsed as a Date.`;
}

if (timestamp < MIN_DATE_TIMESTAMP || timestamp > MAX_DATE_TIMESTAMP) {
return `The attribute [${attributeValue.timestamp}] for key [${attributeTag}] is out of bounds for a Date. The Date must be between ${MIN_DATE_ISO} and ${MAX_DATE_ISO}`;
}
}
return undefined;
}
Expand Down

0 comments on commit 84c4f36

Please sign in to comment.