@liskhq/lisk-validator
Advanced tools
Comparing version 0.7.0-beta.5 to 0.7.0-rc.0
@@ -49,7 +49,8 @@ "use strict"; | ||
super(); | ||
this.errors = (0, exports.convertErrorsToLegacyFormat)(errors); | ||
this.errors = exports.convertErrorsToLegacyFormat(errors); | ||
this.message = `Lisk validator found ${this.errors.length} error[s]:\n${this._compileErrors().join('\n')}`; | ||
} | ||
_compileErrors() { | ||
return this.errors.map(errorFormatter); | ||
const errorMsgs = this.errors.map(errorFormatter); | ||
return errorMsgs; | ||
} | ||
@@ -56,0 +57,0 @@ } |
export declare const hex: (data: unknown) => boolean; | ||
export declare const bytes: (data: unknown) => boolean; | ||
export declare const uint64: { | ||
type: string; | ||
validate: (value: number) => boolean; | ||
}; | ||
export declare const uint32: { | ||
type: string; | ||
validate: (value: number) => boolean; | ||
}; | ||
export declare const int64: (data: string) => boolean; | ||
export declare const uint64: (data: string) => boolean; | ||
export declare const uint32: (data: string) => boolean; | ||
export declare const int32: (data: string) => boolean; | ||
export declare const camelCase: (data: string) => boolean; | ||
@@ -19,2 +15,1 @@ export declare const version: (version: string) => boolean; | ||
export declare const oddInteger: (data: string | number) => boolean; | ||
export declare const lisk32: (data: string) => boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.lisk32 = exports.oddInteger = exports.ipOrFQDN = exports.ip = exports.encryptedPassphrase = exports.path = exports.networkVersion = exports.version = exports.camelCase = exports.uint32 = exports.uint64 = exports.bytes = exports.hex = void 0; | ||
const lisk_cryptography_1 = require("@liskhq/lisk-cryptography"); | ||
exports.oddInteger = exports.ipOrFQDN = exports.ip = exports.encryptedPassphrase = exports.path = exports.networkVersion = exports.version = exports.camelCase = exports.int32 = exports.uint32 = exports.uint64 = exports.int64 = exports.bytes = exports.hex = void 0; | ||
const validation_1 = require("./validation"); | ||
const constants_1 = require("./constants"); | ||
exports.hex = validation_1.isHexString; | ||
exports.bytes = validation_1.isBytes; | ||
exports.uint64 = { | ||
type: 'number', | ||
validate: (value) => Number.isInteger(value) && value >= 0 && value <= constants_1.MAX_UINT64, | ||
}; | ||
exports.uint32 = { | ||
type: 'number', | ||
validate: (value) => Number.isInteger(value) && value >= 0 && value <= constants_1.MAX_UINT32, | ||
}; | ||
const camelCaseRegex = /^[a-z][0-9]*([A-Z][a-z]*[a-zA-Z0-9]*|[a-z][a-z]*[a-zA-Z0-9]*)?$/; | ||
const int64 = (data) => validation_1.isNumberString(data) && validation_1.isSInt64(BigInt(data)); | ||
exports.int64 = int64; | ||
const uint64 = (data) => validation_1.isNumberString(data) && validation_1.isUInt64(BigInt(data)); | ||
exports.uint64 = uint64; | ||
const uint32 = (data) => validation_1.isNumberString(data) && validation_1.isUInt32(Number(data)); | ||
exports.uint32 = uint32; | ||
const int32 = (data) => validation_1.isNumberString(data) && validation_1.isSInt32(Number(data)); | ||
exports.int32 = int32; | ||
const camelCaseRegex = /^[a-z]+((\d)|([A-Z0-9][a-zA-Z0-9]+))*([a-z0-9A-Z])?$/; | ||
const camelCase = (data) => camelCaseRegex.exec(data) !== null; | ||
@@ -29,3 +27,3 @@ exports.camelCase = camelCase; | ||
const hostnameRegex = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/; | ||
return (0, validation_1.isIPV4)(data) || hostnameRegex.test(data); | ||
return validation_1.isIPV4(data) || hostnameRegex.test(data); | ||
}; | ||
@@ -40,12 +38,2 @@ exports.ipOrFQDN = ipOrFQDN; | ||
exports.oddInteger = oddInteger; | ||
const lisk32 = (data) => { | ||
try { | ||
lisk_cryptography_1.address.validateLisk32Address(data); | ||
return true; | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
}; | ||
exports.lisk32 = lisk32; | ||
//# sourceMappingURL=formats.js.map |
@@ -1,2 +0,2 @@ | ||
import { validator, liskSchemaIdentifier, LiskValidator } from './lisk_validator'; | ||
import { validator, liskSchemaIdentifier } from './lisk_validator'; | ||
import { LiskErrorObject as ErrorObject } from './types'; | ||
@@ -6,2 +6,2 @@ export * from './validation'; | ||
export * from './constants'; | ||
export { validator, liskSchemaIdentifier, ErrorObject, LiskValidator }; | ||
export { validator, liskSchemaIdentifier, ErrorObject }; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -17,7 +13,6 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LiskValidator = exports.liskSchemaIdentifier = exports.validator = void 0; | ||
exports.liskSchemaIdentifier = exports.validator = void 0; | ||
const lisk_validator_1 = require("./lisk_validator"); | ||
Object.defineProperty(exports, "validator", { enumerable: true, get: function () { return lisk_validator_1.validator; } }); | ||
Object.defineProperty(exports, "liskSchemaIdentifier", { enumerable: true, get: function () { return lisk_validator_1.liskSchemaIdentifier; } }); | ||
Object.defineProperty(exports, "LiskValidator", { enumerable: true, get: function () { return lisk_validator_1.LiskValidator; } }); | ||
__exportStar(require("./validation"), exports); | ||
@@ -24,0 +19,0 @@ __exportStar(require("./errors"), exports); |
@@ -31,6 +31,6 @@ "use strict"; | ||
if (value === 'boolean') { | ||
return (0, validation_1.isBoolean)(data); | ||
return validation_1.isBoolean(data); | ||
} | ||
if (value === 'bytes') { | ||
if (!(0, validation_1.isBytes)(data)) { | ||
if (!validation_1.isBytes(data)) { | ||
return false; | ||
@@ -65,30 +65,17 @@ } | ||
} | ||
if (typeof parent.format === 'string') { | ||
const { length } = data; | ||
if (parent.format === 'lisk32' && length !== 20) { | ||
validate.errors = [ | ||
{ | ||
keyword: 'dataType', | ||
message: 'address length invalid', | ||
params: { dataType: value, format: parent.format, length }, | ||
}, | ||
]; | ||
return false; | ||
} | ||
} | ||
} | ||
if (value === 'string') { | ||
return (0, validation_1.isString)(data); | ||
return validation_1.isString(data); | ||
} | ||
if (value === 'uint32') { | ||
return (0, validation_1.isUInt32)(data); | ||
return validation_1.isUInt32(data); | ||
} | ||
if (value === 'uint64') { | ||
return (0, validation_1.isUInt64)(data); | ||
return validation_1.isUInt64(data); | ||
} | ||
if (value === 'sint32') { | ||
return (0, validation_1.isSInt32)(data); | ||
return validation_1.isSInt32(data); | ||
} | ||
if (value === 'sint64') { | ||
return (0, validation_1.isSInt64)(data); | ||
return validation_1.isSInt64(data); | ||
} | ||
@@ -95,0 +82,0 @@ return true; |
@@ -45,2 +45,3 @@ export declare const liskMetaSchema: { | ||
}; | ||
minProperties: number; | ||
}; | ||
@@ -47,0 +48,0 @@ required: { |
@@ -6,3 +6,3 @@ "use strict"; | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
$id: 'http://lisk.com/lisk-schema/schema#', | ||
$id: 'http://lisk.io/lisk-schema/schema#', | ||
title: 'Lisk Schema', | ||
@@ -13,3 +13,3 @@ type: 'object', | ||
type: 'string', | ||
const: 'http://lisk.com/lisk-schema/schema#', | ||
const: 'http://lisk.io/lisk-schema/schema#', | ||
format: 'uri', | ||
@@ -50,2 +50,3 @@ }, | ||
}, | ||
minProperties: 1, | ||
}, | ||
@@ -52,0 +53,0 @@ required: { |
@@ -1,8 +0,9 @@ | ||
import Ajv, { SchemaObject, ValidateFunction } from 'ajv'; | ||
import Ajv, { AnySchema, ValidateFunction } from 'ajv'; | ||
import { LiskErrorObject } from './types'; | ||
export declare const liskSchemaIdentifier: string; | ||
export declare class LiskValidator { | ||
declare class LiskValidator { | ||
private readonly _validator; | ||
constructor(); | ||
validate<T = Record<string, unknown>>(schema: object, data: unknown): asserts data is T; | ||
validateSchema(schema: object): asserts schema is SchemaObject; | ||
validate(schema: object, data: object): LiskErrorObject[]; | ||
validateSchema(schema: AnySchema | boolean): ReadonlyArray<LiskErrorObject>; | ||
compile(schema: object | boolean): ValidateFunction; | ||
@@ -12,1 +13,2 @@ removeSchema(schemaKeyRef?: object | string | RegExp | boolean): Ajv; | ||
export declare const validator: LiskValidator; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validator = exports.LiskValidator = exports.liskSchemaIdentifier = void 0; | ||
exports.validator = exports.liskSchemaIdentifier = void 0; | ||
const ajv_1 = require("ajv"); | ||
@@ -18,8 +18,9 @@ const ajv_formats_1 = require("ajv-formats"); | ||
allErrors: true, | ||
useDefaults: false, | ||
addUsedSchema: false, | ||
strictTypes: false, | ||
}); | ||
(0, ajv_formats_1.default)(this._validator); | ||
for (const [formatName, format] of Object.entries(formats)) { | ||
this._validator.addFormat(formatName, format); | ||
ajv_formats_1.default(this._validator); | ||
for (const formatName of Object.keys(formats)) { | ||
this._validator.addFormat(formatName, formats[formatName]); | ||
} | ||
@@ -39,9 +40,11 @@ this._validator.addKeyword({ | ||
if (!this._validator.validate(schema, data)) { | ||
throw new errors_1.LiskValidationError((0, errors_1.convertErrorsToLegacyFormat)(this._validator.errors)); | ||
return errors_1.convertErrorsToLegacyFormat(this._validator.errors); | ||
} | ||
return []; | ||
} | ||
validateSchema(schema) { | ||
if (!this._validator.validateSchema(schema)) { | ||
throw new errors_1.LiskValidationError((0, errors_1.convertErrorsToLegacyFormat)(this._validator.errors)); | ||
return errors_1.convertErrorsToLegacyFormat(this._validator.errors); | ||
} | ||
return []; | ||
} | ||
@@ -71,4 +74,3 @@ compile(schema) { | ||
} | ||
exports.LiskValidator = LiskValidator; | ||
exports.validator = new LiskValidator(); | ||
//# sourceMappingURL=lisk_validator.js.map |
@@ -44,3 +44,3 @@ "use strict"; | ||
} | ||
return data === '' || /^([0-9a-f]{2})+$/i.test(data); | ||
return data === '' || /^[a-f0-9]+$/i.test(data); | ||
}; | ||
@@ -50,3 +50,3 @@ exports.isHexString = isHexString; | ||
const keyRegExp = /[a-zA-Z0-9]{2,15}/; | ||
const valueRegExp = /[a-z0-9+-]{1,512}/; | ||
const valueRegExp = /[a-f0-9]{1,512}/; | ||
const keyValueRegExp = new RegExp(`${keyRegExp.source}=${valueRegExp.source}`); | ||
@@ -57,5 +57,5 @@ const encryptedPassphraseRegExp = new RegExp(`^(${keyValueRegExp.source})(?:&(${keyValueRegExp.source})){0,10}$`); | ||
exports.isEncryptedPassphrase = isEncryptedPassphrase; | ||
const isSemVer = (version) => !!(0, semver_1.valid)(version); | ||
const isSemVer = (version) => !!semver_1.valid(version); | ||
exports.isSemVer = isSemVer; | ||
const isRangedSemVer = (version) => !!(0, semver_1.validRange)(version); | ||
const isRangedSemVer = (version) => !!semver_1.validRange(version); | ||
exports.isRangedSemVer = isRangedSemVer; | ||
@@ -72,3 +72,3 @@ exports.isLessThanRangedVersion = semver_1.ltr; | ||
exports.isIPV6 = isIPV6; | ||
const isIP = (data) => (0, exports.isIPV4)(data) || (0, exports.isIPV6)(data); | ||
const isIP = (data) => exports.isIPV4(data) || exports.isIPV6(data); | ||
exports.isIP = isIP; | ||
@@ -75,0 +75,0 @@ const isPort = (port) => validator_1.default.isPort(port); |
{ | ||
"name": "@liskhq/lisk-validator", | ||
"version": "0.7.0-beta.5", | ||
"version": "0.7.0-rc.0", | ||
"description": "Validation library according to the Lisk protocol", | ||
"author": "Lisk Foundation <admin@lisk.com>, lightcurve GmbH <admin@lightcurve.io>", | ||
"author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>", | ||
"license": "Apache-2.0", | ||
@@ -28,43 +28,44 @@ "keywords": [ | ||
"format": "prettier --write '**/*'", | ||
"lint": "eslint --ext .ts .", | ||
"lint": "eslint --ext .js,.ts .", | ||
"lint:fix": "eslint --fix --ext .js,.ts .", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage=true --coverage-reporters=text", | ||
"test:ci": "jest --coverage=true --coverage-reporters=json", | ||
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose", | ||
"test:watch": "npm test -- --watch", | ||
"prebuild": "rm -r dist-node/* || mkdir dist-node || true", | ||
"build": "tsc", | ||
"build:check": "node -e \"require('./dist-node')\"" | ||
"build:check": "node -e \"require('./dist-node')\"", | ||
"prepublishOnly": "npm run lint && npm test && npm run build && npm run build:check" | ||
}, | ||
"dependencies": { | ||
"@liskhq/lisk-cryptography": "^4.0.0-beta.4", | ||
"@liskhq/lisk-cryptography": "^3.3.0-rc.0", | ||
"ajv": "8.1.0", | ||
"ajv-formats": "2.1.1", | ||
"ajv-formats": "2.0.2", | ||
"debug": "4.3.4", | ||
"semver": "7.5.2", | ||
"semver": "7.3.5", | ||
"validator": "13.7.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "29.2.3", | ||
"@types/jest-when": "3.5.2", | ||
"@types/jest": "26.0.21", | ||
"@types/jest-when": "2.7.2", | ||
"@types/node": "18.15.3", | ||
"@types/semver": "7.3.13", | ||
"@types/validator": "13.7.10", | ||
"@typescript-eslint/eslint-plugin": "5.44.0", | ||
"@typescript-eslint/parser": "5.44.0", | ||
"eslint": "8.28.0", | ||
"@types/semver": "7.3.4", | ||
"@types/validator": "13.1.3", | ||
"@typescript-eslint/eslint-plugin": "4.19.0", | ||
"@typescript-eslint/parser": "4.19.0", | ||
"eslint": "7.22.0", | ||
"eslint-config-lisk-base": "2.0.1", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-jest": "27.1.6", | ||
"jest": "29.3.1", | ||
"jest-extended": "3.2.0", | ||
"jest-when": "3.5.2", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-jest": "24.3.2", | ||
"jest": "26.6.3", | ||
"jest-extended": "0.11.5", | ||
"jest-when": "3.2.1", | ||
"lodash.clonedeep": "4.5.0", | ||
"prettier": "2.8.0", | ||
"source-map-support": "0.5.21", | ||
"ts-jest": "29.0.3", | ||
"ts-node": "10.9.1", | ||
"tsconfig-paths": "4.1.0", | ||
"typescript": "5.0.2" | ||
"prettier": "2.2.1", | ||
"source-map-support": "0.5.19", | ||
"ts-jest": "26.5.4", | ||
"ts-node": "9.1.1", | ||
"tsconfig-paths": "3.9.0", | ||
"typescript": "4.2.3" | ||
} | ||
} |
@@ -28,2 +28,2 @@ # @liskhq/lisk-validator | ||
[lisk core github]: https://github.com/LiskHQ/lisk | ||
[lisk documentation site]: https://lisk.com/documentation/lisk-sdk/references/lisk-elements/validator.html | ||
[lisk documentation site]: https://lisk.io/documentation/lisk-elements |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44846
32
644
+ Added@liskhq/lisk-cryptography@3.3.0(transitive)
+ Addedajv-formats@2.0.2(transitive)
+ Addeded2curve@0.3.0(transitive)
+ Addedini@1.3.8(transitive)
+ Addednode-gyp-build@4.8.4(transitive)
+ Addedsemver@7.3.5(transitive)
+ Addedsodium-native@3.2.1(transitive)
+ Addedvaruint-bitcoin@1.1.2(transitive)
- Removed@liskhq/lisk-cryptography@4.1.0(transitive)
- Removed@liskhq/lisk-passphrase@4.1.0(transitive)
- Removed@types/node@11.11.6(transitive)
- Removedajv-formats@2.1.1(transitive)
- Removedbip39@3.0.3(transitive)
- Removedcipher-base@1.0.6(transitive)
- Removedcreate-hash@1.2.0(transitive)
- Removedcreate-hmac@1.1.7(transitive)
- Removedhash-base@3.1.0(transitive)
- Removedhash-wasm@4.9.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmd5.js@1.3.5(transitive)
- Removedpbkdf2@3.1.2(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedripemd160@2.0.2(transitive)
- Removedsemver@7.5.2(transitive)
- Removedsha.js@2.4.11(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedajv-formats@2.0.2
Updatedsemver@7.3.5