aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-25 18:06:38 +0800
committerFabio Berger <me@fabioberger.com>2017-05-25 18:06:38 +0800
commitfa559377c80a75ba4169cab0825e5808154ae72b (patch)
treec8de187221945b99b63fb8b21553274f4a6ef647
parent0b8ddc1ee18c6d52fbc72177e8c5e180f9106708 (diff)
downloaddexon-sol-tools-fa559377c80a75ba4169cab0825e5808154ae72b.tar
dexon-sol-tools-fa559377c80a75ba4169cab0825e5808154ae72b.tar.gz
dexon-sol-tools-fa559377c80a75ba4169cab0825e5808154ae72b.tar.bz2
dexon-sol-tools-fa559377c80a75ba4169cab0825e5808154ae72b.tar.lz
dexon-sol-tools-fa559377c80a75ba4169cab0825e5808154ae72b.tar.xz
dexon-sol-tools-fa559377c80a75ba4169cab0825e5808154ae72b.tar.zst
dexon-sol-tools-fa559377c80a75ba4169cab0825e5808154ae72b.zip
Improve ECSignature schema to check signature parameters and that v is 27 or 28
-rw-r--r--src/ts/schemas/ec_signature_schema.ts16
-rw-r--r--src/ts/utils/schema_validator.ts3
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 {