participant Client [fillcolor="green"]
participant ISV [fillcolor="green"]
participant Oak Runner\n(untrusted) as Runner [fillcolor="orange"]
participant Oak Runtime\n(in Enclave) as Runtime [fillcolor="palegreen"]
participant Oak Module\n(in Enclave) as Node [fillcolor="palegreen"]

ISV --> Runner: CreateApplication(.wasm data, host:port)
Note over Runner: load engine and\n.wasm into enclave [fillcolor="orange"]
Runner -->> Runtime: create
Note over Runtime: create gRPC invocation\nchannel and assign handle [fillcolor="palegreen"]
Runtime -> Node: invoke oak_main(123)
Node -> Runtime: oak.wait_on_channels(123)

Runner --> ISV: Ack
ISV --> Client: Publish(host:port)

Note over ISV:  [color="white"]

Client --> Runtime: GetAttestationReq()
Runtime --> Client: GetAttestationRsp(key exchange)

Note over Client:  [color="white"]

Client --> Runtime: gRPC: DoSomethingRequest
Note over Runtime: decrypt & write\ngRPC req to new channel [fillcolor="palegreen"]
Note over Runtime: create new response channel [fillcolor="palegreen"]
Note over Runtime: write new channel handles\nto invocation channel [fillcolor="palegreen"]
Runtime -> Node: channel 123 ready
Note over Node: (prepare linear memory\narea for receive) [fillcolor="palegreen"]
Node -> Runtime: oak.channel_read(123, _, &handles)
Runtime -> Node: (read, write) handles (234,345)
Node -> Runtime: oak.channel_read(234, &buf, _)
Runtime -> Node: serialized gRPC request
Note over Node: unmarshal request [fillcolor="palegreen"]
Note over Node: do something [fillcolor="palegreen"]
Note over Node: serialize response [fillcolor="palegreen"]
Node -> Runtime: oak.channel_write(345, &rsp)
Note over Runtime: encrypt & send\ngRPC response [fillcolor="palegreen"]
Runtime -> Client: gRPC: DoSomethingResponse
Node -> Runtime: oak.channel_close(234)
Node -> Runtime: oak.channel_close(345)
Node -> Runtime: oak.wait_on_channels(123)

Note over Client: [color="white"]

Note over ISV:  [color="white"]

ISV --> Runner: TerminateApplication
Runner --> Runtime: destroy
Runtime -> Node: status=CHANNEL_CLOSED
Note over Node: oak_main exits [fillcolor="palegreen"]
