import { SizeOverflowError, type SizeOverflowErrorType, } from '../errors/data.js' import type { ErrorType } from '../errors/utils.js' import type { Bytes, Hex } from '../types/data.js' import { type SizeErrorType, size as size_ } from './size.js' export type AssertSizeOptions = { size: number } export type AssertSizeErrorType = | SizeOverflowErrorType | SizeErrorType | ErrorType export function assertSize( hexOrBytes: Hex | Bytes, options: AssertSizeOptions, ): void { const { size } = options if (size_(hexOrBytes) > size) throw new SizeOverflowError({ givenSize: size_(hexOrBytes), maxSize: size, }) }