diff options
Diffstat (limited to 'packages/website/ts/schemas')
-rw-r--r-- | packages/website/ts/schemas/metadata_schema.ts | 9 | ||||
-rw-r--r-- | packages/website/ts/schemas/order_schema.ts | 15 | ||||
-rw-r--r-- | packages/website/ts/schemas/order_taker_schema.ts | 11 | ||||
-rw-r--r-- | packages/website/ts/schemas/portal_order_schema.ts | 9 | ||||
-rw-r--r-- | packages/website/ts/schemas/portal_token_metadata.ts (renamed from packages/website/ts/schemas/token_schema.ts) | 7 | ||||
-rw-r--r-- | packages/website/ts/schemas/signature_data_schema.ts | 11 | ||||
-rw-r--r-- | packages/website/ts/schemas/validator.ts | 27 |
7 files changed, 31 insertions, 58 deletions
diff --git a/packages/website/ts/schemas/metadata_schema.ts b/packages/website/ts/schemas/metadata_schema.ts new file mode 100644 index 000000000..cd4045d10 --- /dev/null +++ b/packages/website/ts/schemas/metadata_schema.ts @@ -0,0 +1,9 @@ +export const orderMetadataSchema = { + id: '/OrderMetadata', + properties: { + makerToken: { $ref: '/PortalTokenMetadata' }, + takerToken: { $ref: '/PortalTokenMetadata' }, + }, + required: ['makerToken', 'takerToken'], + type: 'object', +}; diff --git a/packages/website/ts/schemas/order_schema.ts b/packages/website/ts/schemas/order_schema.ts deleted file mode 100644 index bfbf9eb8b..000000000 --- a/packages/website/ts/schemas/order_schema.ts +++ /dev/null @@ -1,15 +0,0 @@ -export const orderSchema = { - id: '/Order', - properties: { - maker: { $ref: '/OrderTaker' }, - taker: { $ref: '/OrderTaker' }, - salt: { type: 'string' }, - signature: { $ref: '/SignatureData' }, - expiration: { type: 'string' }, - feeRecipient: { type: 'string' }, - exchangeContract: { type: 'string' }, - networkId: { type: 'number' }, - }, - required: ['maker', 'taker', 'salt', 'signature', 'expiration', 'feeRecipient', 'exchangeContract', 'networkId'], - type: 'object', -}; diff --git a/packages/website/ts/schemas/order_taker_schema.ts b/packages/website/ts/schemas/order_taker_schema.ts deleted file mode 100644 index c784c29c5..000000000 --- a/packages/website/ts/schemas/order_taker_schema.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const orderTakerSchema = { - id: '/OrderTaker', - properties: { - address: { type: 'string' }, - token: { $ref: '/Token' }, - amount: { type: 'string' }, - feeAmount: { type: 'string' }, - }, - required: ['address', 'token', 'amount', 'feeAmount'], - type: 'object', -}; diff --git a/packages/website/ts/schemas/portal_order_schema.ts b/packages/website/ts/schemas/portal_order_schema.ts new file mode 100644 index 000000000..ea8aeabc6 --- /dev/null +++ b/packages/website/ts/schemas/portal_order_schema.ts @@ -0,0 +1,9 @@ +export const portalOrderSchema = { + id: '/PortalOrder', + properties: { + signedOrder: { $ref: '/SignedOrder' }, + metadata: { $ref: '/OrderMetadata' }, + }, + required: ['signedOrder', 'metadata'], + type: 'object', +}; diff --git a/packages/website/ts/schemas/token_schema.ts b/packages/website/ts/schemas/portal_token_metadata.ts index 92b53a463..0455c2ac1 100644 --- a/packages/website/ts/schemas/token_schema.ts +++ b/packages/website/ts/schemas/portal_token_metadata.ts @@ -1,11 +1,10 @@ -export const tokenSchema = { - id: '/Token', +export const portalTokenMetadataSchema = { + id: '/PortalTokenMetadata', properties: { name: { type: 'string' }, symbol: { type: 'string' }, decimals: { type: 'number' }, - address: { type: 'string' }, }, - required: ['name', 'symbol', 'decimals', 'address'], + required: ['name', 'symbol', 'decimals'], type: 'object', }; diff --git a/packages/website/ts/schemas/signature_data_schema.ts b/packages/website/ts/schemas/signature_data_schema.ts deleted file mode 100644 index 8d3f15926..000000000 --- a/packages/website/ts/schemas/signature_data_schema.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const signatureDataSchema = { - id: '/SignatureData', - properties: { - hash: { type: 'string' }, - r: { type: 'string' }, - s: { type: 'string' }, - v: { type: 'number' }, - }, - required: ['hash', 'r', 's', 'v'], - type: 'object', -}; diff --git a/packages/website/ts/schemas/validator.ts b/packages/website/ts/schemas/validator.ts index 5177501c6..dac0f0098 100644 --- a/packages/website/ts/schemas/validator.ts +++ b/packages/website/ts/schemas/validator.ts @@ -1,19 +1,12 @@ +import { SchemaValidator } from '@0xproject/json-schemas'; import { Schema as JSONSchema, Validator } from 'jsonschema'; -import { orderSchema } from 'ts/schemas/order_schema'; -import { orderTakerSchema } from 'ts/schemas/order_taker_schema'; -import { signatureDataSchema } from 'ts/schemas/signature_data_schema'; -import { tokenSchema } from 'ts/schemas/token_schema'; +import { orderMetadataSchema } from 'ts/schemas/metadata_schema'; +import { portalOrderSchema } from 'ts/schemas/portal_order_schema'; +import { portalTokenMetadataSchema } from 'ts/schemas/portal_token_metadata'; -export class SchemaValidator { - private _validator: Validator; - constructor() { - this._validator = new Validator(); - this._validator.addSchema(signatureDataSchema as JSONSchema, signatureDataSchema.id); - this._validator.addSchema(tokenSchema as JSONSchema, tokenSchema.id); - this._validator.addSchema(orderTakerSchema as JSONSchema, orderTakerSchema.id); - this._validator.addSchema(orderSchema as JSONSchema, orderSchema.id); - } - public validate(instance: object, schema: Schema) { - return this._validator.validate(instance, schema); - } -} +const validator = new SchemaValidator(); +validator.addSchema(portalTokenMetadataSchema); +validator.addSchema(orderMetadataSchema); +validator.addSchema(portalOrderSchema); + +export { validator }; |