diff --git a/protocol-specs/generators/multisignature_registration/index.js b/protocol-specs/generators/multisignature_registration/index.js index 877a4ed46b9..2cc4f45a2c0 100644 --- a/protocol-specs/generators/multisignature_registration/index.js +++ b/protocol-specs/generators/multisignature_registration/index.js @@ -17,6 +17,7 @@ const { signData } = require('@liskhq/lisk-cryptography'); const { Codec } = require('@liskhq/lisk-codec'); const BaseGenerator = require('../base_generator'); +const { baseTransactionSchema } = require('../../utils/schema'); const codec = new Codec(); @@ -100,41 +101,6 @@ const outputBase64Account = account => ({ address: account.address.toString('base64'), }); -const baseSchema = { - $id: 'baseSchema', - type: 'object', - required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'], - properties: { - type: { - dataType: 'uint32', - fieldNumber: 1, - }, - nonce: { - dataType: 'uint64', - fieldNumber: 2, - }, - fee: { - dataType: 'uint64', - fieldNumber: 3, - }, - senderPublicKey: { - dataType: 'bytes', - fieldNumber: 4, - }, - asset: { - dataType: 'bytes', - fieldNumber: 5, - }, - signatures: { - type: 'array', - items: { - dataType: 'bytes', - }, - fieldNumber: 6, - }, - }, -}; - const multisigRegAsset = { type: 'object', properties: { @@ -162,7 +128,7 @@ const getSignBytes = tx => { asset: assetBytes, signatures: [], }; - return codec.encode(baseSchema, signingTx); + return codec.encode(baseTransactionSchema, signingTx); }; const encode = tx => { @@ -171,7 +137,7 @@ const encode = tx => { ...tx, asset: assetBytes, }; - return codec.encode(baseSchema, txWithAssetBytes); + return codec.encode(baseTransactionSchema, txWithAssetBytes); }; const sortKeysAscending = publicKeys => diff --git a/protocol-specs/generators/proof_of_misbehavior_transaction/index.js b/protocol-specs/generators/proof_of_misbehavior_transaction/index.js index 6621e2e97f7..9cd08bf9928 100644 --- a/protocol-specs/generators/proof_of_misbehavior_transaction/index.js +++ b/protocol-specs/generators/proof_of_misbehavior_transaction/index.js @@ -21,6 +21,7 @@ const { signDataWithPrivateKey, } = require('@liskhq/lisk-cryptography'); const { Codec } = require('@liskhq/lisk-codec'); +const { baseTransactionSchema } = require('../../utils/schema'); const BaseGenerator = require('../base_generator'); @@ -31,41 +32,6 @@ const networkIdentifier = Buffer.from( 'hex', ); -const baseSchema = { - $id: 'baseSchema', - type: 'object', - required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'], - properties: { - type: { - dataType: 'uint32', - fieldNumber: 1, - }, - nonce: { - dataType: 'uint64', - fieldNumber: 2, - }, - fee: { - dataType: 'uint64', - fieldNumber: 3, - }, - senderPublicKey: { - dataType: 'bytes', - fieldNumber: 4, - }, - asset: { - dataType: 'bytes', - fieldNumber: 5, - }, - signatures: { - type: 'array', - items: { - dataType: 'bytes', - }, - fieldNumber: 6, - }, - }, -}; - const pomAsset = { $id: 'asset/pom', type: 'object', @@ -164,7 +130,7 @@ const getSignBytes = tx => { asset: assetBytes, signatures: [], }; - return codec.encode(baseSchema, signingTx); + return codec.encode(baseTransactionSchema, signingTx); }; const encode = tx => { @@ -173,7 +139,7 @@ const encode = tx => { ...tx, asset: assetBytes, }; - return codec.encode(baseSchema, txWithAssetBytes); + return codec.encode(baseTransactionSchema, txWithAssetBytes); }; const createSignatureObject = (txBuffer, account) => ({ diff --git a/protocol-specs/generators/transaction_network_id_and_change_order/index.js b/protocol-specs/generators/transaction_network_id_and_change_order/index.js index e0019dff893..bedabc77347 100644 --- a/protocol-specs/generators/transaction_network_id_and_change_order/index.js +++ b/protocol-specs/generators/transaction_network_id_and_change_order/index.js @@ -17,6 +17,7 @@ const { signData } = require('@liskhq/lisk-cryptography'); const { Codec } = require('@liskhq/lisk-codec'); const BaseGenerator = require('../base_generator'); +const { baseTransactionSchema } = require('../../utils/schema'); const codec = new Codec(); @@ -84,41 +85,6 @@ const networkIdentifier = Buffer.from( 'hex', ); -const baseSchema = { - $id: 'baseSchema', - type: 'object', - required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'], - properties: { - type: { - dataType: 'uint32', - fieldNumber: 1, - }, - nonce: { - dataType: 'uint64', - fieldNumber: 2, - }, - fee: { - dataType: 'uint64', - fieldNumber: 3, - }, - senderPublicKey: { - dataType: 'bytes', - fieldNumber: 4, - }, - asset: { - dataType: 'bytes', - fieldNumber: 5, - }, - signatures: { - type: 'array', - items: { - dataType: 'bytes', - }, - fieldNumber: 6, - }, - }, -}; - const balanceTransferAsset = { type: 'object', $id: 'balanceTransferAsset', @@ -156,7 +122,7 @@ const generateValidTransferTransaction = () => { asset: assetBytes, signatures: [], }; - const signingBytes = codec.encode(baseSchema, signingTx); + const signingBytes = codec.encode(baseTransactionSchema, signingTx); const signature = Buffer.from( signData( @@ -166,7 +132,7 @@ const generateValidTransferTransaction = () => { 'hex', ); - const encodedTx = codec.encode(baseSchema, { + const encodedTx = codec.encode(baseTransactionSchema, { ...tx, asset: assetBytes, signatures: [signature], @@ -207,7 +173,7 @@ const generateValidDelegateTransaction = () => { asset: assetBytes, signatures: [], }; - const signingBytes = codec.encode(baseSchema, signingTx); + const signingBytes = codec.encode(baseTransactionSchema, signingTx); const signature = Buffer.from( signData( @@ -217,7 +183,7 @@ const generateValidDelegateTransaction = () => { 'hex', ); - const encodedTx = codec.encode(baseSchema, { + const encodedTx = codec.encode(baseTransactionSchema, { ...tx, asset: assetBytes, signatures: [signature], diff --git a/protocol-specs/generators/unlocking_transaction/index.js b/protocol-specs/generators/unlocking_transaction/index.js index 004d821b8fe..e8068f021ea 100644 --- a/protocol-specs/generators/unlocking_transaction/index.js +++ b/protocol-specs/generators/unlocking_transaction/index.js @@ -17,6 +17,7 @@ const { signData } = require('@liskhq/lisk-cryptography'); const { Codec } = require('@liskhq/lisk-codec'); const BaseGenerator = require('../base_generator'); +const { baseTransactionSchema } = require('../../utils/schema'); const codec = new Codec(); @@ -177,41 +178,6 @@ const delegateAccounts = [ }, ]; -const baseSchema = { - $id: 'baseSchema', - type: 'object', - required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'], - properties: { - type: { - dataType: 'uint32', - fieldNumber: 1, - }, - nonce: { - dataType: 'uint64', - fieldNumber: 2, - }, - fee: { - dataType: 'uint64', - fieldNumber: 3, - }, - senderPublicKey: { - dataType: 'bytes', - fieldNumber: 4, - }, - asset: { - dataType: 'bytes', - fieldNumber: 5, - }, - signatures: { - type: 'array', - items: { - dataType: 'bytes', - }, - fieldNumber: 6, - }, - }, -}; - const assetSchema = { $id: 'asset/unlock', type: 'object', @@ -242,7 +208,7 @@ const getSignBytes = tx => { asset: assetBytes, signatures: [], }; - return codec.encode(baseSchema, signingTx); + return codec.encode(baseTransactionSchema, signingTx); }; const encode = tx => { @@ -251,7 +217,7 @@ const encode = tx => { ...tx, asset: assetBytes, }; - return codec.encode(baseSchema, txWithAssetBytes); + return codec.encode(baseTransactionSchema, txWithAssetBytes); }; const generateValidUpvoteTransaction = () => { diff --git a/protocol-specs/generators/vote_transaction/index.js b/protocol-specs/generators/vote_transaction/index.js index 2d08fe2784c..2ea15c39a4b 100644 --- a/protocol-specs/generators/vote_transaction/index.js +++ b/protocol-specs/generators/vote_transaction/index.js @@ -17,6 +17,7 @@ const { signData } = require('@liskhq/lisk-cryptography'); const { Codec } = require('@liskhq/lisk-codec'); const BaseGenerator = require('../base_generator'); +const { baseTransactionSchema } = require('../../utils/schema'); const codec = new Codec(); @@ -217,41 +218,6 @@ const delegateAccounts = [ }, ]; -const baseSchema = { - $id: 'baseSchema', - type: 'object', - required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'], - properties: { - type: { - dataType: 'uint32', - fieldNumber: 1, - }, - nonce: { - dataType: 'uint64', - fieldNumber: 2, - }, - fee: { - dataType: 'uint64', - fieldNumber: 3, - }, - senderPublicKey: { - dataType: 'bytes', - fieldNumber: 4, - }, - asset: { - dataType: 'bytes', - fieldNumber: 5, - }, - signatures: { - type: 'array', - items: { - dataType: 'bytes', - }, - fieldNumber: 6, - }, - }, -}; - const assetSchema = { type: 'object', properties: { @@ -280,7 +246,7 @@ const getSignBytes = tx => { asset: assetBytes, signatures: [], }; - return codec.encode(baseSchema, signingTx); + return codec.encode(baseTransactionSchema, signingTx); }; const encode = tx => { @@ -289,7 +255,7 @@ const encode = tx => { ...tx, asset: assetBytes, }; - return codec.encode(baseSchema, txWithAssetBytes); + return codec.encode(baseTransactionSchema, txWithAssetBytes); }; const generateValidUpvoteTransaction = () => { diff --git a/protocol-specs/utils/schema.js b/protocol-specs/utils/schema.js new file mode 100644 index 00000000000..3affc7b7313 --- /dev/null +++ b/protocol-specs/utils/schema.js @@ -0,0 +1,52 @@ +/* + * Copyright © 2020 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +const baseTransactionSchema = { + $id: 'baseTransactionSchema', + type: 'object', + required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'], + properties: { + type: { + dataType: 'uint32', + fieldNumber: 1, + }, + nonce: { + dataType: 'uint64', + fieldNumber: 2, + }, + fee: { + dataType: 'uint64', + fieldNumber: 3, + }, + senderPublicKey: { + dataType: 'bytes', + fieldNumber: 4, + }, + asset: { + dataType: 'bytes', + fieldNumber: 5, + }, + signatures: { + type: 'array', + items: { + dataType: 'bytes', + }, + fieldNumber: 6, + }, + }, +}; + +module.exports = { + baseTransactionSchema, +};