Skip to content

Commit

Permalink
check byte length in regex
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Oct 2, 2024
1 parent 177bc71 commit 77ee42e
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/types/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type Hash, type Hex, getAddress, maxUint256, size } from "viem"
import { type Hash, type Hex, getAddress, maxUint256 } from "viem"
import { z } from "zod"
import type { MempoolUserOperation } from "./mempool"

const hexDataPattern = /^0x[0-9A-Fa-f]*$/
const addressPattern = /^0x[0-9,a-f,A-F]{40}$/
export const hexData32Pattern = /^0x([0-9a-fA-F][0-9a-fA-F]){0,32}$/
export const hexData32Pattern = /^0x([0-9a-fA-F][0-9a-fA-F]){32}$/
export const commaSeperatedAddressPattern =
/^(0x[0-9a-fA-F]{40})(,\s*(0x[0-9a-fA-F]{40}))*$/

Expand Down Expand Up @@ -266,9 +266,6 @@ const getUserOperationByHashRequestSchema = z.object({
.string()
.regex(hexData32Pattern, { message: "Missing/invalid userOpHash" })
.transform((val) => val as Hex)
.refine((val) => size(val) === 32, {
message: "Invalid UserOperation Hash length: expected 32 bytes."
})
])
})

Expand All @@ -279,9 +276,6 @@ const getUserOperationReceiptRequestSchema = z.object({
.string()
.regex(hexData32Pattern, { message: "Missing/invalid userOpHash" })
.transform((val) => val as Hex)
.refine((val) => size(val) === 32, {
message: "Invalid UserOperation Hash length: expected 32 bytes."
})
])
})

Expand Down

0 comments on commit 77ee42e

Please sign in to comment.