Add signedOrderSchema and all subschemas
This commit is contained in:
parent
603a88872d
commit
699e588d1f
50
src/schemas/signed_order_schema.ts
Normal file
50
src/schemas/signed_order_schema.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
export const addressSchema = {
|
||||||
|
id: '/addressSchema',
|
||||||
|
type: 'string',
|
||||||
|
pattern: '^0[xX][0-9A-Fa-f]{40}$',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const bigNumberSchema = {
|
||||||
|
id: '/bigNumberSchema',
|
||||||
|
type: 'string',
|
||||||
|
pattern: '^\d*$',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const orderSchema = {
|
||||||
|
id: '/orderSchema',
|
||||||
|
properties: {
|
||||||
|
maker: {$ref: '/addressSchema'},
|
||||||
|
taker: {$ref: '/addressSchema'},
|
||||||
|
|
||||||
|
makerFee: {$ref: '/bigNumberSchema'},
|
||||||
|
takerFee: {$ref: '/bigNumberSchema'},
|
||||||
|
|
||||||
|
makerTokenAmount: {$ref: '/bigNumberSchema'},
|
||||||
|
takerTokenAmount: {$ref: '/bigNumberSchema'},
|
||||||
|
|
||||||
|
makerTokenAddress: {$ref: '/addressSchema'},
|
||||||
|
takerTokenAddress: {$ref: '/addressSchema'},
|
||||||
|
|
||||||
|
salt: {$ref: '/bigNumberSchema'},
|
||||||
|
fillAmount: {$ref: '/bigNumberSchema'},
|
||||||
|
feeRecipient: {$ref: '/addressSchema'},
|
||||||
|
expirationUnixTimestampSec: {$ref: '/bigNumberSchema'},
|
||||||
|
},
|
||||||
|
required: [
|
||||||
|
'maker', /*'taker',*/ 'makerFee', 'takerFee', 'makerTokenAmount', 'takerTokenAmount',
|
||||||
|
'salt', 'fillAmount', 'feeRecipient', 'expirationUnixTimestampSec',
|
||||||
|
],
|
||||||
|
type: 'object',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const signedOrderSchema = {
|
||||||
|
allOf: [
|
||||||
|
{ $ref: '/orderSchema' },
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
ecSignature: {$ref: '/addressSchema'},
|
||||||
|
},
|
||||||
|
required: ['ecSignature'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
@ -1,12 +1,17 @@
|
|||||||
import {Validator, ValidatorResult} from 'jsonschema';
|
import {Validator, ValidatorResult} from 'jsonschema';
|
||||||
import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema';
|
import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema';
|
||||||
|
import {addressSchema, bigNumberSchema, orderSchema, signedOrderSchema} from '../schemas/signed_order_schema';
|
||||||
|
|
||||||
export class SchemaValidator {
|
export class SchemaValidator {
|
||||||
private validator: Validator;
|
private validator: Validator;
|
||||||
constructor() {
|
constructor() {
|
||||||
this.validator = new Validator();
|
this.validator = new Validator();
|
||||||
this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id);
|
this.validator.addSchema(orderSchema, orderSchema.id);
|
||||||
|
this.validator.addSchema(addressSchema, addressSchema.id);
|
||||||
|
this.validator.addSchema(bigNumberSchema, bigNumberSchema.id);
|
||||||
this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id);
|
this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id);
|
||||||
|
this.validator.addSchema(signedOrderSchema, signedOrderSchema.id);
|
||||||
|
this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id);
|
||||||
}
|
}
|
||||||
public validate(instance: object, schema: Schema): ValidatorResult {
|
public validate(instance: object, schema: Schema): ValidatorResult {
|
||||||
return this.validator.validate(instance, schema);
|
return this.validator.validate(instance, schema);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user