Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x committed Dec 11, 2024
1 parent 4a9afb7 commit 9ef9df6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
6 changes: 6 additions & 0 deletions api/_types/exclusivity.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { boolean, Infer, object, optional } from "superstruct";
import { positiveFloatStr, positiveIntStr, validAddress } from "../_utils";
import { TypedVercelRequest } from "./generic.types";

export const RelayerFillLimitSchema = object({
originChainId: positiveIntStr(),
Expand All @@ -21,6 +22,11 @@ export type RelayerConfigUpdate = {
relayerFillLimits: RelayerFillLimit[];
};

export type TypedRelayerConfigUpdateRequest = TypedVercelRequest<
any,
RelayerConfigUpdate
>;

// // Example config.
// export const RelayerConfigUpdate: RelayerFillLimit[] = [
// {
Expand Down
8 changes: 3 additions & 5 deletions api/_types/generic.types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { VercelRequest } from "@vercel/node";

export type TypedVercelRequest<T> = VercelRequest & {
body: T;
headers: {
signature: string;
};
export type TypedVercelRequest<Query, Body = any> = VercelRequest & {
query: Partial<Query>;
body: Partial<Body>;
};
16 changes: 12 additions & 4 deletions api/relayer-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@ import {
getWhiteListedRelayers,
MAX_MESSAGE_AGE_SECONDS,
} from "./_exclusivity/utils";
import { RelayerConfigUpdate, TypedVercelRequest } from "./_types";
import {
RelayerConfigUpdate,
TypedRelayerConfigUpdateRequest,
TypedVercelRequest,
} from "./_types";

const handlePostRequest = async (
request: TypedVercelRequest<RelayerConfigUpdate>,
request: TypedRelayerConfigUpdateRequest,
response: VercelResponse
) => {
const body = request.body as RelayerConfigUpdate;
const { signature } = request.headers;
const { authorization } = request.headers;
const { timestamp, relayerFillLimits } = body;

Check warning on line 20 in api/relayer-config.ts

View workflow job for this annotation

GitHub Actions / format-and-lint

'relayerFillLimits' is assigned a value but never used
if (!isTimestampValid(timestamp, MAX_MESSAGE_AGE_SECONDS)) {
return response.status(400).json({ message: "Message too old" });
}

const relayer = getRelayerFromSignature(signature, JSON.stringify(body));
if (!authorization) {
return response.status(401).json({ message: "Unauthorized" });
}

const relayer = getRelayerFromSignature(authorization, JSON.stringify(body));

if (!getWhiteListedRelayers().includes(relayer)) {
return response.status(401).json({ message: "Unauthorized" });
Expand Down
20 changes: 8 additions & 12 deletions test/api/relayer-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import handler from "../../api/relayer-config";
import {
RelayerConfigUpdate,
RelayerFillLimit,
TypedVercelRequest,
} from "../../api/_types";
import { VercelResponse } from "@vercel/node";
import { ethers } from "ethers";
import * as utils from "../../api/_exclusivity/utils";
import { TypedRelayerConfigUpdateRequest } from "../../api/_types";
import handler from "../../api/relayer-config";
const { MAX_MESSAGE_AGE_SECONDS } = utils;

const getMockedResponse = () => {
Expand Down Expand Up @@ -39,10 +35,10 @@ describe("Relayer Config API", () => {
const request = {
method: "POST",
headers: {
signature: signature,
authorization: signature,
},
body: message,
} as TypedVercelRequest<RelayerConfigUpdate>;
} as TypedRelayerConfigUpdateRequest;

await handler(request, response);

Expand All @@ -60,10 +56,10 @@ describe("Relayer Config API", () => {
const request = {
method: "POST",
headers: {
signature: signature,
authorization: signature,
},
body: message,
} as TypedVercelRequest<RelayerConfigUpdate>;
} as TypedRelayerConfigUpdateRequest;

await handler(request, response);

Expand All @@ -82,10 +78,10 @@ describe("Relayer Config API", () => {
const request = {
method: "POST",
headers: {
signature: signature,
authorization: signature,
},
body: message,
} as TypedVercelRequest<RelayerConfigUpdate>;
} as TypedRelayerConfigUpdateRequest;

await handler(request, response);

Expand Down

0 comments on commit 9ef9df6

Please sign in to comment.