import { enumify } from "./utils" ; import { ProtocolParams , ProtocolName } from "./protocol" ; import { AppInstanceJson } from "./app" ; import { StateChannelJSON } from "./state" ; export type MiddlewareMap = { [ protocolName ] : ( protocol : ProtocolName , middlewareContext : MiddlewareContext ) => Promise < void > ; } ; export type GenericMiddleware = { ( args ) : any ; } ; export const ProtocolRoles = enumify ( { initiator : "initiator" , responder : "responder" , } ) ; export type ProtocolRoles = typeof ProtocolRoles [ keyof typeof ProtocolRoles ] ; export type ProtocolRole = keyof typeof ProtocolRoles ; export type SetupMiddlewareContext = { role : ProtocolRole ; params : Omit < ProtocolParams . Setup , "chainId" > ; } ; export type ProposeMiddlewareContext = { role : ProtocolRole ; params : ProtocolParams . Propose ; proposal : AppInstanceJson ; stateChannel : StateChannelJSON ; } ; export type InstallMiddlewareContext = { role : ProtocolRole ; params : ProtocolParams . Install ; appInstance : AppInstanceJson ; stateChannel : StateChannelJSON ; } ; export type TakeActionMiddlewareContext = { role : ProtocolRole ; params : ProtocolParams . TakeAction ; appInstance : AppInstanceJson ; stateChannel : StateChannelJSON ; } ; export type UninstallMiddlewareContext = { role : ProtocolRole ; params : ProtocolParams . Uninstall ; appInstance : AppInstanceJson ; stateChannel : StateChannelJSON ; } ; export type MiddlewareContext = SetupMiddlewareContext | ProposeMiddlewareContext | InstallMiddlewareContext | TakeActionMiddlewareContext | UninstallMiddlewareContext ; export type ValidationMiddleware = { ( protocol , context ) : Promise < void > ; } ;