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