import { LiskValidationError , validator } from '@liskhq/lisk-validator' ; import { baseTransactionSchema } from './schema' ; export const validateTransaction = ( assetSchema , transactionObject ) : LiskValidationError | Error | undefined => { const transactionObjectWithEmptyAsset = { ... transactionObject , asset : Buffer . alloc ( 0 ) , } ; const schemaErrors = validator . validate ( baseTransactionSchema , transactionObjectWithEmptyAsset ) ; if ( schemaErrors . length ) { return new LiskValidationError ( [ ... schemaErrors ] ) ; } if ( typeof transactionObject . asset !== 'object' || transactionObject . asset === null ) { return new Error ( 'Transaction object asset must be of type object and not null' ) ; } const assetSchemaErrors = validator . validate ( assetSchema , transactionObject . asset ) ; if ( assetSchemaErrors . length ) { return new LiskValidationError ( [ ... assetSchemaErrors ] ) ; } return undefined ; } ;