From 501768524dee032483a9b836e1ac4dfe85dc05f2 Mon Sep 17 00:00:00 2001 From: supaiku Date: Tue, 8 Oct 2019 03:41:33 +0200 Subject: [PATCH] fix: legacy multisignature schema --- .../unit/crypto/transactions/schemas.test.ts | 29 +++++++ .../crypto/src/transactions/types/schemas.ts | 75 ++++++++++++++----- 2 files changed, 86 insertions(+), 18 deletions(-) diff --git a/__tests__/unit/crypto/transactions/schemas.test.ts b/__tests__/unit/crypto/transactions/schemas.test.ts index 2b3b65201d..6ed7359a6d 100644 --- a/__tests__/unit/crypto/transactions/schemas.test.ts +++ b/__tests__/unit/crypto/transactions/schemas.test.ts @@ -695,6 +695,35 @@ describe("Multi Signature Registration Transaction", () => { const { error } = Ajv.validate(transactionSchema.$id, transaction.getStruct()); expect(error).not.toBeUndefined(); }); + + it("should validate legacy multisignature", () => { + const legacyMultiSignature = { + version: 1, + network: 23, + type: 4, + timestamp: 53253482, + senderPublicKey: "0333421e69d3531a1c43c43cd4b9344e5a10640644a5fd35618b6306f3a4d7f208", + fee: "2000000000", + amount: "0", + asset: { + multiSignatureLegacy: { + keysgroup: [ + "+034da006f958beba78ec54443df4a3f52237253f7ae8cbdb17dccf3feaa57f3126", + "+0310c283aac7b35b4ae6fab201d36e8322c3408331149982e16013a5bcb917081c", + "+0392a762e0123945455b7afe675e5ab98fb1586de43e5682514b9454d6edced724", + ], + lifetime: 24, + min: 2, + }, + }, + signature: + "304402206009fbf8592e2e3485bc0aa84dbbc8c78326d59191daf870693bc3446b5eeeee02200b4ff5dd53b1e337fe6fbe090f42337dcfc4242c802c340815326e3858d13d6b", + id: "32aa60577531c190e6a29d28f434367c84c2f0a62eceba5c5483a3983639d51a", + }; + + const { error } = Ajv.validate(transactionSchema.$id, legacyMultiSignature); + expect(error).toBeUndefined(); + }); }); describe("Multi Payment Transaction", () => { diff --git a/packages/crypto/src/transactions/types/schemas.ts b/packages/crypto/src/transactions/types/schemas.ts index b93e51f896..85c37d64ba 100644 --- a/packages/crypto/src/transactions/types/schemas.ts +++ b/packages/crypto/src/transactions/types/schemas.ts @@ -143,34 +143,73 @@ export const vote = extend(transactionBaseSchema, { export const multiSignature = extend(transactionBaseSchema, { $id: "multiSignature", - required: ["asset", "signatures"], + if: { properties: { version: { anyOf: [{ type: "null" }, { const: 1 }] } } }, + then: { required: ["asset"] }, + else: { required: ["asset", "signatures"] }, properties: { type: { transactionType: TransactionType.MultiSignature }, amount: { bignumber: { minimum: 0, maximum: 0 } }, asset: { - type: "object", - required: ["multiSignature"], - properties: { - multiSignature: { + anyOf: [ + { type: "object", - required: ["min", "publicKeys"], + required: ["multiSignature"], properties: { - min: { - type: "integer", - minimum: 1, - maximum: { $data: "1/publicKeys/length" }, + multiSignature: { + type: "object", + required: ["min", "publicKeys"], + properties: { + min: { + type: "integer", + minimum: 1, + maximum: { $data: "1/publicKeys/length" }, + }, + publicKeys: { + type: "array", + minItems: 1, + maxItems: 16, + additionalItems: false, + uniqueItems: true, + items: { $ref: "publicKey" }, + }, + }, }, - publicKeys: { - type: "array", - minItems: 1, - maxItems: 16, - additionalItems: false, - uniqueItems: true, - items: { $ref: "publicKey" }, + }, + }, + { + type: "object", + required: ["multiSignatureLegacy"], + properties: { + multiSignatureLegacy: { + type: "object", + required: ["keysgroup", "min", "lifetime"], + properties: { + min: { + type: "integer", + minimum: 1, + maximum: { $data: "1/keysgroup/length" }, + }, + lifetime: { + type: "integer", + minimum: 1, + maximum: 72, + }, + keysgroup: { + type: "array", + minItems: 1, + maxItems: 16, + additionalItems: false, + items: { + allOf: [ + { type: "string", minimum: 67, maximum: 67, transform: ["toLowerCase"] }, + ], + }, + }, + }, }, }, }, - }, + ], }, signatures: { type: "array",