@@ -4,6 +4,7 @@ import { identity, includes } from 'lodash';
44
55import { isValidAddress } from './wallet';
66import patp2dec from './patp2dec';
7+import { patpStringLength } from './lib';
78
89// NOTE: do not use the /g modifier for these regexes
910// https://stackoverflow.com/a/21373261
@@ -136,19 +137,6 @@ export const validateShard = m =>
136137 error: 'This is not a valid shard',
137138 });
138139
139−export const validateLength = l => m =>
140− simpleValidatorWrapper({
141− prevMessage: m,
142− validator: d => {
143− try {
144− return d.length === l;
145− } catch {
146− return false;
147− }
148− },
149− error: `Must be exactly ${l} characters`,
150− });
151−
152140export const validateOneOf = (options = []) => m =>
153141 simpleValidatorWrapper({
154142 prevMessage: m,
@@ -215,3 +203,37 @@ export const validateExactly = (value, error) => m =>
215203 validator: d => d === value,
216204 error,
217205 });
206+
207+export const validateLength = l => m =>
208+ simpleValidatorWrapper({
209+ prevMessage: m,
210+ validator: d => {
211+ try {
212+ return d.length === l;
213+ } catch {
214+ return false;
215+ }
216+ },
217+ error: `Must be exactly ${l} characters`,
218+ });
219+
220+export const validateMaximumLength = l => m =>
221+ simpleValidatorWrapper({
222+ prevMessage: m,
223+ validator: d => {
224+ try {
225+ return d.length <= l;
226+ } catch {
227+ return false;
228+ }
229+ },
230+ error: `Must be ${l} characters or fewer.`,
231+ });
232+
233+export const validatePatpByteLength = byteLength => {
234+ return validateLength(patpStringLength(byteLength));
235+};
236+
237+export const validateMaximumPatpByteLength = byteLength => {
238+ return validateMaximumLength(patpStringLength(byteLength));
239+};