@etherspot/modular-sdk
Version:
Etherspot Modular SDK - build with ERC-7579 smart accounts modules
43 lines • 1.55 kB
JavaScript
import { registerDecorator } from 'class-validator';
import { isHex } from 'viem';
export function IsBytesLike(options = {}) {
return (object, propertyName) => {
registerDecorator({
propertyName,
options: {
message: `${propertyName} must be bytes like`,
...options,
},
name: 'IsBytesLike',
target: object ? object.constructor : undefined,
constraints: [],
validator: {
validate(value) {
let result = false;
try {
if (value) {
switch (typeof value) {
case 'string':
if (options.acceptText) {
result = true;
}
else {
result = isHex(value) && value.length % 2 === 0;
}
break;
case 'object':
result = isHex(value);
break;
}
}
}
catch (err) {
//
}
return result;
},
},
});
};
}
//# sourceMappingURL=is-bytes-like.validator.js.map