mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-03 22:15:13 +01:00
- Use async verifier stream instead of sync jws.verify to make the slow verification less blocking.
27 lines
795 B
TypeScript
27 lines
795 B
TypeScript
/* eslint-disable no-console */
|
|
import Ajv from 'ajv';
|
|
import * as fs from 'fs';
|
|
import { join } from 'path';
|
|
|
|
import { TokenStructure } from '../../src/tokenDefinitionsTypes';
|
|
import { SCHEMA_FILENAME_SUFFIX, SCHEMA_PATH } from '../constants';
|
|
|
|
// checks that a config meets the criteria specified by the schema
|
|
export const validateStructure = (nftData: TokenStructure, structure: string) => {
|
|
const ajv = new Ajv();
|
|
|
|
const schema = fs.readFileSync(
|
|
join(SCHEMA_PATH, `${structure}.${SCHEMA_FILENAME_SUFFIX}`),
|
|
'utf-8',
|
|
);
|
|
|
|
const validate = ajv.compile(JSON.parse(schema));
|
|
const isValid = validate(nftData);
|
|
|
|
if (!isValid) {
|
|
throw Error(`Config is invalid: ${JSON.stringify(validate.errors)}`);
|
|
}
|
|
|
|
console.log('Structure is valid');
|
|
};
|