From 9c850d152cd024c8852200c237790e8bee82b3a9 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 23 May 2018 16:52:41 -0700 Subject: Updated Order, SignedOrder schemas, removed ECSignature schema types and added Hex basic type --- .../json-schemas/schemas/basic_type_schemas.ts | 6 ++ .../json-schemas/schemas/ec_signature_schema.ts | 20 ------ packages/json-schemas/schemas/order_schemas.ts | 36 +++++------ packages/json-schemas/src/schemas.ts | 6 +- packages/json-schemas/test/schema_test.ts | 74 ++++++---------------- 5 files changed, 44 insertions(+), 98 deletions(-) delete mode 100644 packages/json-schemas/schemas/ec_signature_schema.ts (limited to 'packages/json-schemas') diff --git a/packages/json-schemas/schemas/basic_type_schemas.ts b/packages/json-schemas/schemas/basic_type_schemas.ts index 9d81ff333..8430b6f4a 100644 --- a/packages/json-schemas/schemas/basic_type_schemas.ts +++ b/packages/json-schemas/schemas/basic_type_schemas.ts @@ -4,6 +4,12 @@ export const addressSchema = { pattern: '^0x[0-9a-f]{40}$', }; +export const hexSchema = { + id: '/Hex', + type: 'string', + pattern: '^0x[0-9a-f]', +}; + export const numberSchema = { id: '/Number', type: 'string', diff --git a/packages/json-schemas/schemas/ec_signature_schema.ts b/packages/json-schemas/schemas/ec_signature_schema.ts deleted file mode 100644 index 71b840dd8..000000000 --- a/packages/json-schemas/schemas/ec_signature_schema.ts +++ /dev/null @@ -1,20 +0,0 @@ -export const ecSignatureParameterSchema = { - id: '/ECSignatureParameter', - type: 'string', - pattern: '^0[xX][0-9A-Fa-f]{64}$', -}; - -export const ecSignatureSchema = { - id: '/ECSignature', - properties: { - v: { - type: 'number', - minimum: 27, - maximum: 28, - }, - r: { $ref: '/ECSignatureParameter' }, - s: { $ref: '/ECSignatureParameter' }, - }, - required: ['v', 'r', 's'], - type: 'object', -}; diff --git a/packages/json-schemas/schemas/order_schemas.ts b/packages/json-schemas/schemas/order_schemas.ts index 6f17224ad..183118c23 100644 --- a/packages/json-schemas/schemas/order_schemas.ts +++ b/packages/json-schemas/schemas/order_schemas.ts @@ -1,30 +1,30 @@ export const orderSchema = { id: '/Order', properties: { - maker: { $ref: '/Address' }, - taker: { $ref: '/Address' }, + makerAddress: { $ref: '/Address' }, + takerAddress: { $ref: '/Address' }, makerFee: { $ref: '/Number' }, takerFee: { $ref: '/Number' }, - makerTokenAmount: { $ref: '/Number' }, - takerTokenAmount: { $ref: '/Number' }, - makerTokenAddress: { $ref: '/Address' }, - takerTokenAddress: { $ref: '/Address' }, + makerAssetAmount: { $ref: '/Number' }, + takerAssetAmount: { $ref: '/Number' }, + makerAssetData: { $ref: '/Hex' }, + takerAssetData: { $ref: '/Hex' }, salt: { $ref: '/Number' }, - feeRecipient: { $ref: '/Address' }, - expirationUnixTimestampSec: { $ref: '/Number' }, - exchangeContractAddress: { $ref: '/Address' }, + feeRecipientAddress: { $ref: '/Address' }, + expirationTimeSeconds: { $ref: '/Number' }, }, required: [ - 'maker', - 'taker', + 'makerAddress', + 'takerAddress', 'makerFee', 'takerFee', - 'makerTokenAmount', - 'takerTokenAmount', + 'makerAssetAmount', + 'takerAssetAmount', + 'makerAssetData', + 'takerAssetData', 'salt', - 'feeRecipient', - 'expirationUnixTimestampSec', - 'exchangeContractAddress', + 'feeRecipientAddress', + 'expirationTimeSeconds', ], type: 'object', }; @@ -35,9 +35,9 @@ export const signedOrderSchema = { { $ref: '/Order' }, { properties: { - ecSignature: { $ref: '/ECSignature' }, + signature: { $ref: '/Hex' }, }, - required: ['ecSignature'], + required: ['signature'], }, ], }; diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts index 5cb07acfe..26d6e6cf1 100644 --- a/packages/json-schemas/src/schemas.ts +++ b/packages/json-schemas/src/schemas.ts @@ -1,6 +1,5 @@ -import { addressSchema, numberSchema } from '../schemas/basic_type_schemas'; +import { addressSchema, hexSchema, numberSchema } from '../schemas/basic_type_schemas'; import { blockParamSchema, blockRangeSchema } from '../schemas/block_range_schema'; -import { ecSignatureParameterSchema, ecSignatureSchema } from '../schemas/ec_signature_schema'; import { indexFilterValuesSchema } from '../schemas/index_filter_values_schema'; import { orderCancellationRequestsSchema } from '../schemas/order_cancel_schema'; import { orderFillOrKillRequestsSchema } from '../schemas/order_fill_or_kill_requests_schema'; @@ -31,8 +30,7 @@ import { jsNumber, txDataSchema } from '../schemas/tx_data_schema'; export const schemas = { numberSchema, addressSchema, - ecSignatureSchema, - ecSignatureParameterSchema, + hexSchema, indexFilterValuesSchema, orderCancellationRequestsSchema, orderFillOrKillRequestsSchema, diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index b9574a0c9..d8479ef4f 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -14,8 +14,6 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; const { numberSchema, addressSchema, - ecSignatureSchema, - ecSignatureParameterSchema, orderCancellationRequestsSchema, orderFillOrKillRequestsSchema, orderFillRequestsSchema, @@ -85,47 +83,15 @@ describe('Schema', () => { validateAgainstSchema(testCases, addressSchema, shouldFail); }); }); - describe('#ecSignatureParameterSchema', () => { - it('should validate valid parameters', () => { - const testCases = [ - '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - ]; - validateAgainstSchema(testCases, ecSignatureParameterSchema); - }); - it('should fail for invalid parameters', () => { - const testCases = [ - '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter - '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters - '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x - ]; - const shouldFail = true; - validateAgainstSchema(testCases, ecSignatureParameterSchema, shouldFail); - }); - }); - describe('#ecSignatureSchema', () => { - it('should validate valid signature', () => { - const signature = { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - }; - const testCases = [ - signature, - { - ...signature, - v: 28, - }, - ]; - validateAgainstSchema(testCases, ecSignatureSchema); + describe('#hexSchema', () => { + it('should validate valid hex string', () => { + const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', NULL_ADDRESS]; + validateAgainstSchema(testCases, addressSchema); }); - it('should fail for invalid signature', () => { - const v = 27; - const r = '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33'; - const s = '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254'; - const testCases = [{}, { v }, { r, s, v: 31 }]; + it('should fail for invalid hex string', () => { + const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; const shouldFail = true; - validateAgainstSchema(testCases, ecSignatureSchema, shouldFail); + validateAgainstSchema(testCases, addressSchema, shouldFail); }); }); describe('#orderHashSchema', () => { @@ -202,18 +168,17 @@ describe('Schema', () => { }); describe('order including schemas', () => { const order = { - maker: NULL_ADDRESS, - taker: NULL_ADDRESS, + makerAddress: NULL_ADDRESS, + takerAddress: NULL_ADDRESS, makerFee: '1', takerFee: '2', - makerTokenAmount: '1', - takerTokenAmount: '2', - makerTokenAddress: NULL_ADDRESS, - takerTokenAddress: NULL_ADDRESS, + makerAssetAmount: '1', + takerAssetAmount: '2', + makerAssetData: NULL_ADDRESS, + takerAssetData: NULL_ADDRESS, salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500', - feeRecipient: NULL_ADDRESS, - exchangeContractAddress: NULL_ADDRESS, - expirationUnixTimestampSec: '42', + feeRecipientAddress: NULL_ADDRESS, + expirationTimeSeconds: '42', }; describe('#orderSchema', () => { it('should validate valid order', () => { @@ -239,11 +204,8 @@ describe('Schema', () => { describe('signed order including schemas', () => { const signedOrder = { ...order, - ecSignature: { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - }, + signature: + '0x031b61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', }; describe('#signedOrdersSchema', () => { it('should validate valid signed orders', () => { @@ -265,7 +227,7 @@ describe('Schema', () => { const testCases = [ { ...signedOrder, - ecSignature: undefined, + signature: undefined, }, ]; const shouldFail = true; -- cgit v1.2.3