mirror of
https://github.com/tornadocash/tornado-pool-relayer
synced 2024-02-02 15:04:09 +01:00
fix: validation schema
This commit is contained in:
parent
b95848c829
commit
67455a744c
@ -31,14 +31,15 @@ export class ApiController {
|
|||||||
|
|
||||||
@Post('/transaction')
|
@Post('/transaction')
|
||||||
async transaction(@Res() res: Response, @Body() { body }: any) {
|
async transaction(@Res() res: Response, @Body() { body }: any) {
|
||||||
const inputError = validateTransactionRequest(body);
|
const params = JSON.parse(body);
|
||||||
|
const inputError = validateTransactionRequest(params);
|
||||||
|
|
||||||
if (inputError) {
|
if (inputError) {
|
||||||
console.log('Invalid input:', inputError);
|
console.log('Invalid input:', inputError);
|
||||||
return res.status(HttpStatus.BAD_REQUEST).json({ error: inputError });
|
return res.status(HttpStatus.BAD_REQUEST).json({ error: inputError });
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobId = await this.service.transaction(JSON.parse(body));
|
const jobId = await this.service.transaction(params);
|
||||||
|
|
||||||
return res.send(jobId);
|
return res.send(jobId);
|
||||||
}
|
}
|
||||||
|
@ -19,31 +19,43 @@ const addressType = {
|
|||||||
|
|
||||||
const proofType = { type: 'string', pattern: '^0x[a-fA-F0-9]{512}$' };
|
const proofType = { type: 'string', pattern: '^0x[a-fA-F0-9]{512}$' };
|
||||||
const bytes32Type = { type: 'string', pattern: '^0x[a-fA-F0-9]{64}$' };
|
const bytes32Type = { type: 'string', pattern: '^0x[a-fA-F0-9]{64}$' };
|
||||||
const arrayType = { type: 'array', pattern: '^0x[a-fA-F0-9]{64}$' };
|
const externalAmountType = { type: 'string', pattern: '^(0x[a-fA-F0-9]{64}|-0x[a-fA-F0-9]{63})$' };
|
||||||
|
const encryptedOutputType = { type: 'string', pattern: '^0x[a-fA-F0-9]{312}$' };
|
||||||
const recipientType = {
|
const arrayType = { type: 'array', items: bytes32Type };
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
recipient: addressType,
|
|
||||||
relayer: addressType,
|
|
||||||
encryptedOutput1: bytes32Type,
|
|
||||||
encryptedOutput2: bytes32Type,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const transactionSchema = {
|
const transactionSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
proof: proofType,
|
amount: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
extData: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
encryptedOutput1: encryptedOutputType,
|
||||||
|
encryptedOutput2: encryptedOutputType,
|
||||||
|
extAmount: externalAmountType,
|
||||||
|
fee: bytes32Type,
|
||||||
|
recipient: addressType,
|
||||||
|
relayer: addressType,
|
||||||
|
},
|
||||||
|
},
|
||||||
args: {
|
args: {
|
||||||
type: 'array',
|
type: 'object',
|
||||||
maxItems: 9,
|
properties: {
|
||||||
minItems: 9,
|
extDataHash: bytes32Type,
|
||||||
items: [bytes32Type, bytes32Type, arrayType, bytes32Type, bytes32Type, bytes32Type, bytes32Type, recipientType, bytes32Type],
|
inputNullifiers: arrayType,
|
||||||
|
newRoot: bytes32Type,
|
||||||
|
outPathIndices: bytes32Type,
|
||||||
|
outputCommitments: arrayType,
|
||||||
|
proof: proofType,
|
||||||
|
publicAmount: bytes32Type,
|
||||||
|
root: bytes32Type,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: ['proof', 'args'],
|
required: ['extData', 'args', 'amount'],
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateTornadoTransaction = ajv.compile(transactionSchema);
|
const validateTornadoTransaction = ajv.compile(transactionSchema);
|
||||||
|
Loading…
Reference in New Issue
Block a user