From fa559377c80a75ba4169cab0825e5808154ae72b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 25 May 2017 12:06:38 +0200 Subject: Improve ECSignature schema to check signature parameters and that v is 27 or 28 --- src/ts/schemas/ec_signature_schema.ts | 16 +++++++++++++--- src/ts/utils/schema_validator.ts | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ts/schemas/ec_signature_schema.ts b/src/ts/schemas/ec_signature_schema.ts index e4249afc2..94e58e53c 100644 --- a/src/ts/schemas/ec_signature_schema.ts +++ b/src/ts/schemas/ec_signature_schema.ts @@ -1,9 +1,19 @@ +export const ECSignatureParameter = { + id: '/ECSignatureParameter', + type: 'string', + pattern: '^0[xX][0-9A-Fa-f]{64}$', +}; + export const ECSignatureSchema = { id: '/ECSignature', properties: { - v: {type: 'number'}, - r: {type: 'string'}, - s: {type: 'string'}, + v: { + type: 'number', + minimum: 27, + maximum: 28, + }, + r: {$ref: '/ECSignatureParameter'}, + s: {$ref: '/ECSignatureParameter'}, }, required: ['v', 'r', 's'], type: 'object', diff --git a/src/ts/utils/schema_validator.ts b/src/ts/utils/schema_validator.ts index a0d6f1bee..1cbffee58 100644 --- a/src/ts/utils/schema_validator.ts +++ b/src/ts/utils/schema_validator.ts @@ -1,10 +1,11 @@ import {Validator as V, ValidatorResult} from 'jsonschema'; -import {ECSignatureSchema} from '../schemas/ec_signature_schema'; +import {ECSignatureSchema, ECSignatureParameter} from '../schemas/ec_signature_schema'; export class SchemaValidator { private v: V; constructor() { this.v = new V(); + this.v.addSchema(ECSignatureParameter, ECSignatureParameter.id); this.v.addSchema(ECSignatureSchema, ECSignatureSchema.id); } public validate(instance: object, schema: Schema): ValidatorResult { -- cgit v1.2.3