import { ChannelUpdate, FullChannelState, FullTransferState } from "./channel"; import { ConditionalTransferCreatedPayload, ConditionalTransferRoutingCompletePayload } from "./engine"; import { EngineError, NodeError, MessagingError, ProtocolError, Result, RouterError, VectorError } from "./error"; import { LockInformation } from "./lock"; import { EngineParams, NodeResponses } from "./schemas"; export type CheckInInfo = { channelAddress: string }; export type CheckInResponse = { aliceIdentifier: string; bobIdentifier: string; chainId: number; channelAddress: string; }; // All basic NATS messaging services export interface IBasicMessaging { connect(): Promise; disconnect(): Promise; publish(subject: string, data: any): Promise; subscribe(subject: string, cb: (data: any) => any): Promise; unsubscribe(subject: string): Promise; flush(): Promise; request(subject: string, timeout: number, data: any): Promise; } type TransferQuoteRequest = Omit; export interface IMessagingService extends IBasicMessaging { onReceiveLockMessage( myPublicIdentifier: string, callback: (lockInfo: Result, from: string, inbox: string) => void, ): Promise; sendLockMessage( lockInfo: Result, to: string, from: string, timeout?: number, numRetries?: number, ): Promise>; respondToLockMessage(inbox: string, lockInformation: Result): Promise; onReceiveProtocolMessage( myPublicIdentifier: string, callback: ( result: Result<{ update: ChannelUpdate; previousUpdate: ChannelUpdate }, ProtocolError>, from: string, inbox: string, ) => void, ): Promise; sendProtocolMessage( channelUpdate: ChannelUpdate, previousUpdate?: ChannelUpdate, timeout?: number, numRetries?: number, ): Promise< Result<{ update: ChannelUpdate; previousUpdate: ChannelUpdate }, ProtocolError | MessagingError> >; respondToProtocolMessage( inbox: string, channelUpdate: ChannelUpdate, previousUpdate?: ChannelUpdate, ): Promise; respondWithProtocolError(inbox: string, error: ProtocolError): Promise; sendSetupMessage( setupInfo: Result, EngineError>, to: string, from: string, timeout?: number, numRetries?: number, ): Promise>; onReceiveSetupMessage( publicIdentifier: string, callback: ( setupInfo: Result, EngineError>, from: string, inbox: string, ) => void, ): Promise; respondToSetupMessage(inbox: string, params: Result<{ channelAddress: string }, EngineError>): Promise; // restore flow: // - restore-r sends request // - counterparty receives // 1. acquires lock // 2. sends restore data // - counterparty responds // - restore-r restores // - restore-r sends result (err or success) to counterparty // - counterparty receives // 1. releases lock sendRestoreStateMessage( restoreData: Result<{ chainId: number } | { channelAddress: string }, EngineError>, to: string, from: string, timeout?: number, numRetries?: number, ): Promise< Result<{ channel: FullChannelState; activeTransfers: FullTransferState[] } | void, EngineError | MessagingError> >; onReceiveRestoreStateMessage( publicIdentifier: string, callback: ( restoreData: Result<{ chainId: number } | { channelAddress: string }, EngineError>, from: string, inbox: string, ) => void, ): Promise; respondToRestoreStateMessage( inbox: string, restoreData: Result<{ channel: FullChannelState; activeTransfers: FullTransferState[] } | void, EngineError>, ): Promise; sendIsAliveMessage( isAlive: Result<{ channelAddress: string; skipCheckIn?: boolean }, EngineError>, to: string, from: string, timeout?: number, numRetries?: number, ): Promise>; onReceiveIsAliveMessage( publicIdentifier: string, callback: ( isAlive: Result<{ channelAddress: string; skipCheckIn?: boolean }, EngineError>, from: string, inbox: string, ) => void, ): Promise; respondToIsAliveMessage(inbox: string, params: Result<{ channelAddress: string }, EngineError>): Promise; sendRequestCollateralMessage( requestCollateralParams: Result, to: string, from: string, timeout?: number, numRetries?: number, ): Promise>; onReceiveRequestCollateralMessage( publicIdentifier: string, callback: (params: Result, from: string, inbox: string) => void, ): Promise; respondToRequestCollateralMessage(inbox: string, params: Result<{ message?: string }, EngineError>): Promise; onReceiveWithdrawalQuoteMessage( myPublicIdentifier: string, callback: (quoteRequest: Result, from: string, inbox: string) => void, ): Promise; sendWithdrawalQuoteMessage( quoteRequest: Result, to: string, from: string, timeout?: number, numRetries?: number, ): Promise>; respondToWithdrawalQuoteMessage( inbox: string, quote: Result, ): Promise; sendRouterConfigMessage( configRequest: Result, to: string, from: string, timeout?: number, numRetries?: number, ): Promise>; sendTransferQuoteMessage( quoteRequest: Result, to: string, from: string, timeout?: number, numRetries?: number, ): Promise>; publishTransferRoutingCompleteMessage( to: string, from: string, data: Result, VectorError>, ): Promise; onReceiveTransferRoutingCompleteMessage( myPublicIdentifier: string, callback: ( data: Result, NodeError>, from: string, inbox: string, ) => void, ): Promise; publishWithdrawalSubmittedMessage( to: string, from: string, data: Result<{ channelAddress: string; txHash: string; transferId: string }, VectorError>, ): Promise; onReceiveWithdrawalSubmittedMessage( myPublicIdentifier: string, callback: ( submitted: Result<{ channelAddress: string; txHash: string; transferId: string }, NodeError>, from: string, inbox: string, ) => void, ): Promise; }