UNPKG

@waku/rln

Version:

RLN (Rate Limiting Nullifier) implementation for Waku

31 lines (28 loc) 796 B
import { ValidationError } from './errors.js'; function integer(value) { const int = parseInt(value); if (int.toString() !== value) { throw new ValidationError('Value must be an integer'); } } function positive(value) { if (value < 0) { throw new ValidationError('Value must be a positive integer, or zero'); } } function maxValue(max) { return (value) => { if (value > max) { throw new ValidationError(`Value must be smaller than or equal to ${max}`); } }; } function validate(...funcs) { return (value) => { for (const fn of funcs) { fn(value); } }; } const validatePort = validate(integer, positive, maxValue(65_535)); export { integer, maxValue, positive, validate, validatePort };