import { EventName , EventNames , EventPayload } from "./events" ; import { Address , PublicIdentifier } from "./basic" ; import { ILoggerService } from "./logger" ; import { ProtocolName , ProtocolParam } from "./protocol" ; export type GenericMessage < T = any > = { data : T ; from : Address ; type : EventName ; } ; export type ProtocolEventMessage < T extends EventName > = { data : EventPayload [ T ] ; from : Address ; type : T ; } ; export const CHANNEL_PROTOCOL_VERSION = "1.0.0" ; export type ProtocolMessageData = { processID : string ; protocol : ProtocolName ; protocolVersion : string ; params : ProtocolParam ; to : PublicIdentifier ; error ? : string ; seq : number ; prevMessageReceived ? : number ; customData : { [ key ] : any ; } ; } ; export type CreateChannelMessage = ProtocolEventMessage < typeof EventNames [ "CREATE_CHANNEL_EVENT" ] > ; export type DepositConfirmationMessage = ProtocolEventMessage < typeof EventNames [ "DEPOSIT_CONFIRMED_EVENT" ] > ; export type DepositFailedMessage = ProtocolEventMessage < typeof EventNames [ "DEPOSIT_FAILED_EVENT" ] > ; export type DepositStartedMessage = ProtocolEventMessage < typeof EventNames [ "DEPOSIT_STARTED_EVENT" ] > ; export type InstallMessage = ProtocolEventMessage < typeof EventNames [ "INSTALL_EVENT" ] > ; export type ProtocolMessage = ProtocolEventMessage < typeof EventNames [ "PROTOCOL_MESSAGE_EVENT" ] > ; export type ProposeMessage = ProtocolEventMessage < typeof EventNames [ "PROPOSE_INSTALL_EVENT" ] > ; export type RejectProposalMessage = ProtocolEventMessage < typeof EventNames [ "REJECT_INSTALL_EVENT" ] > ; export type SyncMessage = ProtocolEventMessage < typeof EventNames [ "SYNC" ] > ; export type UninstallMessage = ProtocolEventMessage < typeof EventNames [ "UNINSTALL_EVENT" ] > ; export type UninstallFailedMessage = ProtocolEventMessage < typeof EventNames [ "UNINSTALL_FAILED_EVENT" ] > ; export type UpdateStateMessage = ProtocolEventMessage < typeof EventNames [ "UPDATE_STATE_EVENT" ] > ; export interface MessagingConfig { clusterId ? : string ; logger ? : ILoggerService ; messagingUrl : string | string [ ] ; options ? : any ; privateKey ? : string ; publicKey ? : string ; token ? : string ; } export interface IMessagingService { connect ( ) : Promise < void > ; disconnect ( ) : Promise < void > ; flush ( ) : Promise < void > ; onReceive ( subject , callback ) : Promise < void > ; publish ( subject , data ) : Promise < void > ; request ( subject , timeout , data , callback ? ) : Promise < any > ; send ( to , msg ) : Promise < void > ; subscribe ( subject , callback ) : Promise < void > ; unsubscribe ( subject ) : Promise < void > ; }