From 2cca85bb4ab4cfd08f0e3d3d32f0dc1cd9679813 Mon Sep 17 00:00:00 2001 From: Canh Trinh Date: Wed, 20 Dec 2023 12:36:18 -0500 Subject: [PATCH] chore: fix zod schema validation to account for 0x string salt --- apps/maestro/src/lib/utils/validation.ts | 5 +++++ .../routers/interchainToken/getInterchainTokenDetails.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/maestro/src/lib/utils/validation.ts b/apps/maestro/src/lib/utils/validation.ts index 472cac477..4e25ea96c 100644 --- a/apps/maestro/src/lib/utils/validation.ts +++ b/apps/maestro/src/lib/utils/validation.ts @@ -81,6 +81,11 @@ export const hex40 = () => export const hex64 = () => z.string().regex(/^0x[0-9a-fA-F]{64}$/, "Invalid hash"); +/** + * Zod schema to validate a 0x hex entry + */ +export const hex0x = () => z.string().startsWith("0x").max(2); + export const hex40Literal = () => hex40().transform(asHexLiteral); export const hex64Literal = () => hex64().transform(asHexLiteral); diff --git a/apps/maestro/src/server/routers/interchainToken/getInterchainTokenDetails.ts b/apps/maestro/src/server/routers/interchainToken/getInterchainTokenDetails.ts index b0e284801..c1f3446f3 100644 --- a/apps/maestro/src/server/routers/interchainToken/getInterchainTokenDetails.ts +++ b/apps/maestro/src/server/routers/interchainToken/getInterchainTokenDetails.ts @@ -1,7 +1,7 @@ import { TRPCError } from "@trpc/server"; import { z } from "zod"; -import { hex40Literal, hex64Literal } from "~/lib/utils/validation"; +import { hex0x, hex40Literal, hex64Literal } from "~/lib/utils/validation"; import { publicProcedure } from "~/server/trpc"; const remoteTokenSchema = z.object({ @@ -30,7 +30,7 @@ const outputSchema = z.object({ kind: z.string(), createdAt: z.date().nullable(), updatedAt: z.date().nullable(), - salt: hex64Literal(), + salt: hex64Literal().or(hex0x()), remoteTokens: z.array(remoteTokenSchema), });