Skip to content

Commit

Permalink
Merge pull request #58 from torusresearch/feat/increase-timeout
Browse files Browse the repository at this point in the history
Increases signing timeout
  • Loading branch information
chaitanyapotti authored May 10, 2024
2 parents d94c1a4 + c40ca56 commit 20924c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const validateDataTimeStamp = async (req: Request, res: Response, next: N
const { set_data: setData }: SetDataInput = req.body;
const { timestamp } = setData;
const timeParsed = parseInt(timestamp, 16);
if (~~(Date.now() / 1000) - timeParsed > 90) {
log.error("[validateDataTimeStamp] Message has been signed more than 60s ago", { currentTime: ~~(Date.now() / 1000), timeParsed });
return res.status(403).json({ error: { timestamp: "Message has been signed more than 90s ago" }, success: false });
if (~~(Date.now() / 1000) - timeParsed > 600) {
log.error("[validateDataTimeStamp] Message has been signed more than 600s ago", { currentTime: ~~(Date.now() / 1000), timeParsed });
return res.status(403).json({ error: { timestamp: "Message has been signed more than 600s ago" }, success: false });
}
return next();
};
Expand All @@ -24,8 +24,8 @@ export const validateMetadataLoopInput = (key: string) => (req: Request, res: Re
const { set_data: setData } = param;
const { timestamp } = setData;
const timeParsed = parseInt(timestamp, 16);
if (~~(Date.now() / 1000) - timeParsed > 90) {
const errors = { index, timestamp: "Message has been signed more than 90s ago" };
if (~~(Date.now() / 1000) - timeParsed > 600) {
const errors = { index, timestamp: "Message has been signed more than 600s ago" };
log.error("[validateMetadataLoopInput]", { currentTime: ~~(Date.now() / 1000), timeParsed, errors });
return res.status(403).json({ error: errors, success: false });
}
Expand Down Expand Up @@ -101,9 +101,9 @@ export const validateLockData = (req: Request, res: Response, next: NextFunction
}
const { timestamp } = val.data;
const timeParsed = parseInt(timestamp, 16);
if (~~(Date.now() / 1000) - timeParsed > 90) {
log.error("[validateLockData] Message has been signed more than 90s ago", { currentTime: ~~(Date.now() / 1000), timeParsed });
return res.status(403).json({ error: { message: "Message has been signed more than 90s ago" }, success: false });
if (~~(Date.now() / 1000) - timeParsed > 600) {
log.error("[validateLockData] Message has been signed more than 600s ago", { currentTime: ~~(Date.now() / 1000), timeParsed });
return res.status(403).json({ error: { message: "Message has been signed more than 600s ago" }, success: false });
}
return next();
} catch (error) {
Expand Down Expand Up @@ -140,9 +140,9 @@ export const validateGetOrSetNonceSetInput = async (req: Request, res: Response,
return res.status(403).json({ error: { data: "Should be equal to 'getOrSetNonce' or 'getNonce'" }, success: false });
}
const timeParsed = parseInt(timestamp, 16);
if (~~(Date.now() / 1000) - timeParsed > 90) {
log.error("[validateGetOrSetNonceSetInput] Message has been signed more than 90s ago", { currentTime: ~~(Date.now() / 1000), timeParsed });
return res.status(403).json({ error: { timestamp: "Message has been signed more than 90s ago" }, success: false });
if (~~(Date.now() / 1000) - timeParsed > 600) {
log.error("[validateGetOrSetNonceSetInput] Message has been signed more than 600s ago", { currentTime: ~~(Date.now() / 1000), timeParsed });
return res.status(403).json({ error: { timestamp: "Message has been signed more than 600s ago" }, success: false });
}
return next();
};
Expand Down
8 changes: 4 additions & 4 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ describe("API-calls", function () {
const serializedEncryptedDetails = globalThis.btoa(stringify(encryptedDetails));

const metadataParams = storageLayer.generateMetadataParams(serializedEncryptedDetails, undefined, PRIVATE_KEY);
metadataParams.set_data.timestamp = new BN(~~(Date.now() / 1000) - 95).toString(16);
metadataParams.set_data.timestamp = new BN(~~(Date.now() / 1000) - 605).toString(16);
try {
await post(`${server}/set`, metadataParams);
} catch (err) {
const val = await err.json();
assert.deepStrictEqual(val.error.timestamp, "Message has been signed more than 90s ago"); // same goes for pubkeyY
assert.deepStrictEqual(val.error.timestamp, "Message has been signed more than 600s ago"); // same goes for pubkeyY
}
});

Expand Down Expand Up @@ -227,7 +227,7 @@ describe("API-calls", function () {
});

it("#it should reject if one of the shares has an old timestamp", async function () {
finalMetadataParams[0].set_data.timestamp = new BN(~~(Date.now() / 1000) - 95).toString(16);
finalMetadataParams[0].set_data.timestamp = new BN(~~(Date.now() / 1000) - 605).toString(16);
const FD = new FormData();
finalMetadataParams.forEach((el, index) => {
FD.append(index.toString(), JSON.stringify(el));
Expand All @@ -237,7 +237,7 @@ describe("API-calls", function () {
await post(`${server}/bulk_set_stream`, FD, options, customOptions);
} catch (err) {
const { error } = await err.json();
assert.deepStrictEqual(error.timestamp, "Message has been signed more than 90s ago"); // same goes for pubkeyY
assert.deepStrictEqual(error.timestamp, "Message has been signed more than 600s ago"); // same goes for pubkeyY
}
});

Expand Down

0 comments on commit 20924c1

Please sign in to comment.