From 96ad60e00a165d7fb0b461a2c6dba5569e41a2ca Mon Sep 17 00:00:00 2001 From: Tomek Marciniak Date: Sun, 27 Oct 2024 09:20:01 +0100 Subject: [PATCH] feat(providers): improve validation --- packages/providers/src/validation.ts | 47 +++++++++++++++++----------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/packages/providers/src/validation.ts b/packages/providers/src/validation.ts index 551d37a..0190eed 100644 --- a/packages/providers/src/validation.ts +++ b/packages/providers/src/validation.ts @@ -11,14 +11,19 @@ import { } from "@mina-js/utils"; import { z } from "zod"; -export const SwitchChainRequestParams = z.object({ - chainId: z.string(), -}); +export const SwitchChainRequestParams = z + .object({ + chainId: z.string(), + }) + .strict(); -export const AddChainRequestParams = z.object({ - url: z.string().url(), - name: z.string(), -}); +export const AddChainRequestParams = z + .object({ + url: z.string().url(), + name: z.string(), + slug: z.string(), + }) + .strict(); // Params export const AccountsRequestParamsSchema = z @@ -63,10 +68,12 @@ export const CreateNullifierRequestParamsSchema = z params: z.array(z.array(FieldSchema)), }) .strict(); -export const SwitchChainRequestParamsSchema = z.object({ - method: z.literal("mina_switchChain"), - params: z.array(z.string()), -}); +export const SwitchChainRequestParamsSchema = z + .object({ + method: z.literal("mina_switchChain"), + params: z.array(z.string()), + }) + .strict(); export const AddChainRequestParamsSchema = z .object({ method: z.literal("mina_addChain"), @@ -90,13 +97,13 @@ export const ChainIdRequestReturnSchema = z export const ChainInformationRequestReturnSchema = z .object({ method: z.literal("mina_chainInformation"), - result: z.object({ url: z.string(), name: z.string() }).strict(), + result: AddChainRequestParams, }) .strict(); export const GetBalanceRequestReturnSchema = z .object({ method: z.literal("mina_getBalance"), - result: z.bigint(), + result: z.string(), }) .strict(); export const SignRequestReturnSchema = z @@ -243,9 +250,11 @@ export const ProviderRpcErrorSchema = z.discriminatedUnion("code", [ .strict(), ]); -export const MinaProviderInfoSchema = z.object({ - icon: z.string().startsWith("data:image/"), - name: z.string(), - rdns: z.string(), - slug: z.string(), -}); +export const MinaProviderInfoSchema = z + .object({ + icon: z.string().startsWith("data:image/"), + name: z.string(), + rdns: z.string(), + slug: z.string(), + }) + .strict();