diff --git a/packages/sdk-viem/src/utils/helpers.ts b/packages/sdk-viem/src/utils/helpers.ts index 240b2492..30c855cb 100644 --- a/packages/sdk-viem/src/utils/helpers.ts +++ b/packages/sdk-viem/src/utils/helpers.ts @@ -1,8 +1,9 @@ -import keccak256 from 'keccak256' import { isHex, type Hex } from 'viem' +import { InvalidHexError } from '../errors' +import keccak256 from 'keccak256' -export function isHexList(list: string[]): list is Hex[] { - return list.every((value) => isHex(value)) +export function assertIsHex(value: string): asserts value is Hex { + if (!isHex(value, { strict: false })) throw new InvalidHexError({ value }) } export function getSaltAsBytes32(salt: string | number) { @@ -67,6 +68,16 @@ export async function retry( return fn() } +export function isHexList(list: string[]): list is Hex[] { + return list.every((value) => isHex(value, { strict: false })) +} + +export function assertIsHexList(list: string[]): asserts list is Hex[] { + for (const value of list) { + assertIsHex(value) + } +} + type NonEmptyArray = [T, ...T[]] export function BigIntMin(...[firstValue, ...values]: NonEmptyArray): bigint {