---
# System prepended metadata

title: Teaclave Service Protocols

---

Teaclave Service Protocols
==========================

![Teaclave Dataflow](https://i.imgur.com/JnKCPAU.jpg)

* This is a draft. Add `AuthorizeData` in ACS.

## Common Message Types

### UserCredential

```proto
message UserCredential {
  string id = 1;
  string token = 2;
}
```

### FileEncryptedInfo

```proto
enum FileType {
  AesGcm128EncryptedFile = 0;
  TeaclaveEncryptedFile = 1;
}

message FileEncryptedInfo {
  FileType type = 1;
  bytes key = 2;
}
```

### Empty

```proto
message Empty { }
```
## Teaclave Authorization Service

```proto
service TeaclaveAuthorizationService {
  rpc UserLogin (UserLoginRequest) returns (UserLoginResponse);
  rpc UserAuthorize (UserAuthorizeRequest) returns (UserAuthorizeResponse);
}
```
## Teaclave Authorization Service Message Types


### UserLogin

```proto
message UserLoginRequest {
  string id = 1;
  string password = 2;
}

message UserLoginResponse {
  string token = 1;
}
```

### UserAuthorize

```proto
message UserAuthorizeRequest {
  UserCredential credential = 1;
}

message UserAuthorizeResponse {
  bool accept = 1;
}
```

## Teaclave Frontend Service Interfaces

```proto
service TeaclaveFrontend {
  rpc RegisterInputFile (RegisterInputFileRequest) returns (RegisterInputFileResponse);
  rpc RegisterOutputFile (RegisterOutputFileRequest) returns (RegisterOutputFileResponse);
  
  rpc RegisterFunction (RegisterFunctionRequest) returns (RegisterFunctionResponse);
  rpc GetFunction (GetFunctionRequest) returns (GetFunctionResponse);
  
  rpc GetOutputFile (GetOutputFileRequest) returns (GetoutputFileResponse);
  rpc GetFusionData (GetFusionDataRequest) returns (GetFusionDataResponse);
  
  rpc InvokeTask (InvokeTaskRequest) returns (Empty);
  rpc GetTask (GetTaskRequest) returns (GetTaskResponse);
}
```


## Teaclave Frontend Service Message Types


### RegisterInputFile

```proto
message RegisterInputFileRequest {
  string uri = 1; 
  string hash = 2;
  FileEncryptedInfo encrypted_info = 3;
  UserCredential credential = 99;
} 

message RegisterInputFileResponse {
  string data_id = 1;
}
```

### RegisterOutputFile

```proto
message RegisterOutputFileRequest {
  string uri = 1; 
  FileEncryptedInfo encrypted_info = 2;
  UserCredential credential = 99;
} 

message RegisterOutputFileResponse {
  string data_id = 1;
}
```

### RegisterFunction

```proto
message FunctionInput {
  string name = 1;
  string description = 2;
}

message FunctionOutput {
  string name = 1;
  string description = 2;
}

message RegisterFunctionRequest {
  string name = 1;
  string description = 2;
  bytes function_content = 3;  
  bool is_public = 4;
  repeated FunctionInput input_list = 5;
  repeated FunctionOutput output_list = 6;
  UserCredential credential = 99;
}

message RegisterFunctionResponse {
  string function_id = 1; 
}

```

### GetFunction

```proto
message GetFunctionRequest {
  string function_id = 1;
  UserCredential credential = 99;
}

message GetFunctionResponse {
  string name = 1;
  string description = 2;
  bytes function_content = 3;  
  bool is_public = 4;
  repeated FunctionInput input_list = 5;
  repeated FunctionOutput output_list = 6;
}
```


### GetOutputFile

```proto
message GetOutputFileRequest {
  string data_id = 1;
  UserCredential credential = 99;
}

message GetOutputFileResponse {
  string hash = 1;
}
```

### GetFusionData

```proto
message GetFusionDataRequest {
  string data_id = 1;
  UserCredential credential = 99;
}

message GetFusionDataResponse {
  string hash = 1;
  repeated string data_owner_id_list = 2;
}
```

### InvokeTask


```proto
message InvokeTaskRequest {
  string task_payload = 1;
  map<string, string> signature_map = 2;
  UserCredential credential = 99; 
}


message InvokeTaskRequest {
  string task_id = 1;
  UserCredential credential = 99; 
}

```

### GetTask

```proto
message GetTaskRequest {
  string task_id = 1;
  UserCredential credential = 99;
}

message GetTaskResponse {
  string function_id = 1;
  string function_owner = 2;
  map<string, DataOwnerList> input_data_owner_list_map = 3;
  map<string, DataOwnerList> output_data_owner_list_map = 4;
  map<string, string> input_map = 2;
  map<string, string> output_map = 3;
  map<string, bytes> signature_map = 4;
}
```

## Teaclave Management Service Interfaces


```proto
service TeaclaveManagementService {
  rpc RegisterInputFile (RegisterInputFileRequest) returns (RegisterInputFileResponse);
  rpc RegisterOutputFile (RegisterOutputFileRequest) returns (RegisterOutputFileResponse);
  
  rpc RegisterFunction (RegisterFunctionRequest) returns (RegisterFunctionResponse);
  rpc GetFunction (GetFunctionRequest) returns (GetFunctionResponse);
  
  rpc GetOutputFile (GetOutputFileRequest) returns (GetoutputFileResponse);
  rpc GetFusionData (GetFusionDataRequest) returns (GetFusionDataResponse);
  
  rpc InvokeTask (InvokeTaskRequest) returns (Empty);
  rpc GetTask (GetTaskRequest) returns (GetTaskResponse);
}
```

## Teaclave Management Service Message Types

### RegisterInputFile

```proto
message RegisterInputFileRequest {
  string uri = 1; 
  string hash = 2;
  FileEncryptedInfo encrypted_info = 3;
  UserCredential credential = 99;
} 

message RegisterInputFileResponse {
  string data_id = 1;
}
```

### RegisterOutputFile

```proto
message RegisterOutputFileRequest {
  string uri = 1; 
  FileEncryptedInfo encrypted_info = 2;
  UserCredential credential = 99;
} 

message RegisterOutputFileResponse {
  string data_id = 1;
}
```

### RegisterFunction

```proto
message FunctionInput {
  string name = 1;
  string description = 2;
}

message FunctionOutput {
  string name = 1;
  string description = 2;
}

message RegisterFunctionRequest {
  string name = 1;
  string description = 2;
  bytes function_content = 3;  
  bool is_public = 4;
  repeated FunctionInput input_list = 5;
  repeated FunctionOutput output_list = 6;
  UserCredential credential = 99;
}

message RegisterFunctionResponse {
  string function_id = 1; 
}

```

### GetFunction

```proto
message GetFunctionRequest {
  string function_id = 1;
  UserCredential credential = 99;
}

message GetFunctionResponse {
  string name = 1;
  string description = 2;
  bytes function_content = 3;  
  bool is_public = 4;
  repeated FunctionInput input_list = 5;
  repeated FunctionOutput output_list = 6;
}
```


### GetOutputFile

```proto
message GetOutputFileRequest {
  string data_id = 1;
  UserCredential credential = 99;
}

message GetOutputFileResponse {
  string hash = 1;
}
```

### GetFusionData

```proto
message GetFusionDataRequest {
  string data_id = 1;
  UserCredential credential = 99;
}

message GetFusionDataResponse {
  string hash = 1;
  repeated string data_owner_id_list = 2;
}
```

### CreateTask

```proto
message DataOwnerList {
  repeated string user_id_list = 1;
}

message CreateTaskRequest {
  string function_id = 1;
  string function_owner = 2;
  map<string, DataOwnerList> input_data_owner_list_map = 3;
  map<string, DataOwnerList> output_data_owner_list_map = 4;
  UserCredential credential = 99; 
}

message CreateTaskResponse {
  string task_id = 1;
}
```

### InvokeTask


```proto
message InvokeTaskRequest {
  string task_id = 1;
  // name, data_id
  map<string, string> input_map = 2;
  map<string, string> output_map = 3;
  map<string, bytes> signatures = 4;
  UserCredential credential = 99; 
}


message InvokeTaskRequest {
  string task_id = 1;
  UserCredential credential = 99; 
}

```

### GetTask

```proto
message GetTaskRequest {
  string task_id = 1;
  UserCredential credential = 99;
}

message GetTaskResponse {
  string function_id = 1;
  string function_owner = 2;
  map<string, DataOwnerList> input_data_owner_list_map = 3;
  map<string, DataOwnerList> output_data_owner_list_map = 4;
  map<string, string> input_map = 2;
  map<string, string> output_map = 3;
  map<string, bytes> signatures = 4;
}
```

## Teaclave Access Control Service Interfaces
```
service AccessControlService {
  rpc AuthorizeData (AuthorizeDataRequest) returns (AuthorizeDataResponse);
  rpc AuthorizeFunction (AuthorizeFunctionRequest) returns (AuthorizeFunctionResponse);
  rpc AuthorizeTask (AuthorizeTaskRequest) returns (AuthorizeTaskResponse);
  rpc AuthorizeStagedTask (AuthorizeStagedTaskRequest) returns (AuthorizeStagedTaskResponse);
}
```

## Teaclave Access Control Service Message Types

```proto
message AuthorizeDataRequest {
  string subject_user_id = 1;
  repeated string object_data_owner_id_list = 2;
}

message AuthorizeDataResponse {
  bool accepted = 1;
}

message AuthorizeFunctionRequest {
  string subject_user_id = 1;
  string object_function_owner_id = 2;
}

message AuthorizeFunctionResponse {
  bool accepted = 1;
}

message AuthorizeTaskRequest {
  string subject_user_id = 1;
  string object_function_owner_id  = 2;
  repeated string object_input_owner_id_list  = 3;
  repeated string object_output_owner_id_list = 4;
}

message AuthorizeTaskResponse {
  bool accepted = 1;
}

message AuthorizeStagedTaskRequest {
  string subject_function_owner_id = 1;
  map<string, DataOwnerList> subject_input_owner_list_map = 2;
  map<string, DataOwnerList> subject_output_owner_list_map = 3;
  string object_function_owner_id = 4;
  string object_is_function_public = 5;
  map<string, DataOwnerList> object_input_owner_list_map = 6;
  map<string, DataOwnerList> object_output_owner_list_map = 7;
}

message AuthorizeStagedTaskResponse {
  bool accepted = 1;
}
```

## Teaclave Database Service Interfaces

```proto
service DatabaseService {
  rpc Get (GetRequest) returns (GetResponse);
  rpc Put (SetRequest) returns (Empty);
  rpc Delete (DeleteRequest) returns (Empty);
  
  rpc Enqueue (EnqueueRequest) returns (Empty);
  rpc Dequeue (DequeueRequest) returns (DequeueResponse);
}
```

## Teaclave Database Service Message Types

### Get
```proto
message GetRequest {
  bytes key = 1;
}

message GetResponse {
  bytes value = 1;
}
```

### Put
```proto
message PutRequest {
  bytes key = 1;
  bytes value = 2;
}
```

### Delete
```proto
message DeleteRequest {
  bytes key = 1;
}
```

### Enqueue
```proto
message EnqueueRequest {
  bytes key = 1;
  bytes value = 2;
}
```

### Dequeue
```proto
message DequeueRequest {
  bytes key = 1;
}

message DequeueResponse {
  bytes value = 1;
}
```

## Teaclave Task Scheduler Service

```proto
service TaskSchedulerService {
  rpc RegisterWorker (RegisterWorkerRequest) returns (RegisterWorkerResponse);
  rpc GetStagedTask (GetStagedTaskRequest) returns (GetStagedTaskReponse);
  rpc ReportStagedTaskStatus (ReportStagedTaskStatusRequest) returns (Empty);
}

message RegisterWorkerReqeust {
  string worker_label = 1;
  repeated string worker_capability = 2;
}

message RegisterWorkerResponse {
  string worker_id = 1;
}

message StagedArgument {
  string uri = 1; 
  string hash = 2;
  FileEncryptedInfo encrypted_info = 3;
}

message StagedFunction {
  bool is_builtin = 1;
  string function_id = 2;
  bytes function_content = 3;
}

message StagedTask {
  string task_id = 1;
  StagedFunction function = 2;
  map<string, StagedArgument> input_map = 3;
  map<string, StagedArgument> output_map = 4;
  map<string, StagedArgument> arg_map = 5;
}

message GetStagedTaskRequest {
  string worker_id;
}

message GetStagedTaskResponse {
  StagedTask task = 1;
}

enum StagedTaskStatus {
  Preparing = 0;
  Running = 1;
  Finished = 2;
  Failed = 3;
}


message ReportStagedTaskStatusRequest {
  StagedTaskStatus status;
}

```

## Teaclave Worker Interfaces (no interfaces)
