UNPKG

1.7 kBPlain TextView Raw
1import { enumify } from "./utils";
2import { ProtocolParams, ProtocolName } from "./protocol";
3import { AppInstanceJson } from "./app";
4import { StateChannelJSON } from "./state";
5
6// Note: these are also used in the node so shouldn't be moved into cf-core
7
8export type GenericMiddleware = {
9 (args: any): any;
10};
11
12////////////////////////////////////////
13// validation middleware
14export const ProtocolRoles = enumify({
15 initiator: "initiator",
16 responder: "responder",
17});
18export type ProtocolRoles = typeof ProtocolRoles[keyof typeof ProtocolRoles];
19export type ProtocolRole = keyof typeof ProtocolRoles;
20
21export type SetupMiddlewareContext = {
22 role: ProtocolRole;
23 params: Omit<ProtocolParams.Setup, "chainId">;
24};
25export type ProposeMiddlewareContext = {
26 role: ProtocolRole;
27 params: ProtocolParams.Propose;
28 proposal: AppInstanceJson;
29 stateChannel: StateChannelJSON;
30};
31export type InstallMiddlewareContext = {
32 role: ProtocolRole;
33 params: ProtocolParams.Install;
34 appInstance: AppInstanceJson;
35 stateChannel: StateChannelJSON;
36};
37export type TakeActionMiddlewareContext = {
38 role: ProtocolRole;
39 params: ProtocolParams.TakeAction;
40 appInstance: AppInstanceJson; // pre-action
41 stateChannel: StateChannelJSON;
42};
43export type UninstallMiddlewareContext = {
44 role: ProtocolRole;
45 params: ProtocolParams.Uninstall;
46 appInstance: AppInstanceJson;
47 stateChannel: StateChannelJSON;
48};
49
50export type MiddlewareContext =
51 | SetupMiddlewareContext
52 | ProposeMiddlewareContext
53 | InstallMiddlewareContext
54 | TakeActionMiddlewareContext
55 | UninstallMiddlewareContext;
56
57export type ValidationMiddleware = {
58 (protocol: ProtocolName, context: MiddlewareContext): Promise<void>;
59};