import { Decrypter, Encrypter, Message, Signer } from "./message"; import { Client, TopicId, TopicMessageSubmitTransaction, Transaction, TransactionId } from "@hashgraph/sdk"; import { MessageEnvelope } from "./message-envelope"; import { MessageListener } from "./message-listener"; import { Validator } from "../../utils/validator"; export declare abstract class MessageTransaction { private static SUBTRACT_TIME; protected topicId: TopicId; protected message: MessageEnvelope; private encrypter; private decrypter; private buildTransactionFunction; private receiver; private errorHandler; private executed; private signer; private listener; /** * Creates a new instance of a message transaction. * * @param topicId Consensus topic ID to which message will be submitted. */ constructor(topicId: TopicId); /** * Creates a new instance of a message transaction with already prepared message. * * @param topicId Consensus topic ID to which message will be submitted. * @param message The message signed and ready to be sent. */ constructor(topicId: TopicId, message: MessageEnvelope); /** * Method that constructs a message envelope with a message of type T. * * @return The message envelope with a message inside ready to sign. */ protected abstract buildMessage(): MessageEnvelope; /** * Provides an instance of a message encrypter. * * @param encryptionFunction Encryption function used to encrypt single message property. * @return The message encrypter instance. */ protected abstract provideMessageEncrypter(encryptionFunction: Encrypter): (input: T) => T; /** * Provides a {@link MessageListener} instance specific to the submitted message type. * * @param topicIdToListen ID of the HCS topic. * @return The topic listener for this message on a mirror node. */ protected abstract provideTopicListener(topicIdToListen: TopicId): MessageListener; /** * Handles the error. * If external error handler is defined, passes the error there, otherwise raises RuntimeException. * * @param err The error. * @throws RuntimeException Runtime exception with the given error in case external error handler is not defined. */ protected handleError(err: Error): void; /** * Defines encryption function that encrypts the message attributes before submission. * * @param encrypter The encrypter to use. * @return This transaction instance. */ onEncrypt(encrypter: Encrypter): MessageTransaction; /** * Handles event from a mirror node when a message was consensus was reached and message received. * * @param receiver The receiver handling incoming message. * @return This transaction instance. */ onMessageConfirmed(receiver: (input: MessageEnvelope) => void): MessageTransaction; /** * Defines a handler for errors when they happen during execution. * * @param handler The error handler. * @return This transaction instance. */ onError(handler: (input: Error) => void): MessageTransaction; /** * Defines decryption function that decrypts message attributes after consensus is reached. * Decryption function must accept a byte array of encrypted message and an Timestamp that is its consensus timestamp, * * @param decrypter The decrypter to use. * @return This transaction instance. */ onDecrypt(decrypter: Decrypter): MessageTransaction; /** * Defines a function that signs the message. * * @param signer The signing function to set. * @return This transaction instance. */ signMessage(signer: Signer): MessageTransaction; /** * Sets {@link TopicMessageSubmitTransaction} parameters, builds and signs it without executing it. * Topic ID and transaction message content are already set in the incoming transaction. * * @param builderFunction The transaction builder function. * @return This transaction instance. */ buildAndSignTransaction(builderFunction: (input: TopicMessageSubmitTransaction) => Transaction): MessageTransaction; /** * Builds the message and submits it to appnet's topic. * * @param client The hedera network client. * @return Transaction ID. */ execute(client: Client): Promise; /** * Runs validation logic. * * @param validator The errors validator. */ protected validate(validator: Validator): void; }