UNPKG

lisk-framework

Version:

Lisk blockchain application platform

41 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTransaction = void 0; const lisk_chain_1 = require("@liskhq/lisk-chain"); const lisk_codec_1 = require("@liskhq/lisk-codec"); const lisk_cryptography_1 = require("@liskhq/lisk-cryptography"); const lisk_transactions_1 = require("@liskhq/lisk-transactions"); const createTransaction = ({ module, commandClass, params, nonce, fee, passphrase, chainID, }) => { const { publicKey, privateKey } = lisk_cryptography_1.legacy.getPrivateAndPublicKeyFromPassphrase(passphrase !== null && passphrase !== void 0 ? passphrase : ''); const commandInstance = new commandClass(); const command = commandInstance.name; const paramsBytes = commandInstance.schema && params ? lisk_codec_1.codec.encode(commandInstance.schema, params) : Buffer.alloc(0); const transaction = { module, command, nonce: nonce !== null && nonce !== void 0 ? nonce : BigInt(0), fee: fee !== null && fee !== void 0 ? fee : BigInt(0), senderPublicKey: publicKey, params, signatures: [], }; if (commandInstance.schema) { const validationErrors = (0, lisk_transactions_1.validateTransaction)(transaction, commandInstance.schema); if (validationErrors) { throw validationErrors; } } const result = new lisk_chain_1.Transaction({ ...transaction, params: paramsBytes }); if (!passphrase) { return result; } if (!chainID) { throw new Error('Network identifier is required to sign a transaction'); } result.sign(chainID, privateKey); return result; }; exports.createTransaction = createTransaction; //# sourceMappingURL=create_transaction.js.map