MCPcopy Create free account
hub / github.com/CommE2E/comm / validateInput

Function validateInput

keyserver/src/utils/validation-utils.js:30–61  ·  view source on GitHub ↗
(
  viewer: Viewer,
  inputValidator: TType<T>,
  input: mixed,
  source: string,
)

Source from the content-addressed store, hash-verified

28import { thisKeyserverID } from '../user/identity.js';
29
30async function validateInput<T>(
31 viewer: Viewer,
32 inputValidator: TType<T>,
33 input: mixed,
34 source: string,
35): Promise<T> {
36 if (!viewer.isSocket) {
37 await checkClientSupported(viewer, inputValidator, input);
38 }
39 const convertedInput = checkInputValidator(inputValidator, input, source);
40
41 const keyserverID = await thisKeyserverID();
42
43 if (
44 hasMinStateVersion(viewer.platformDetails, {
45 native: 43,
46 web: 3,
47 })
48 ) {
49 try {
50 return convertClientIDsToServerIDs(
51 keyserverID,
52 inputValidator,
53 convertedInput,
54 );
55 } catch (err) {
56 throw new ServerError(err.message);
57 }
58 }
59
60 return convertedInput;
61}
62
63async function validateOutput<T>(
64 platformDetails: ?PlatformDetails,

Callers 2

createJSONResponderFunction · 0.90
SocketClass · 0.90

Calls 5

thisKeyserverIDFunction · 0.90
hasMinStateVersionFunction · 0.90
checkClientSupportedFunction · 0.85
checkInputValidatorFunction · 0.85

Tested by

no test coverage detected