Skip to content

Commit

Permalink
Initialized create proof #114
Browse files Browse the repository at this point in the history
Signed-off-by: Jannik Kiesel <jannik.kiesel@fau.de>
  • Loading branch information
jackDS008 committed Jun 28, 2022
1 parent 8efd2d5 commit 2de7f26
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package didentity.amos.digitalIdentity.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import didentity.amos.digitalIdentity.services.AuthenticationService;
import didentity.amos.digitalIdentity.services.ProofService;

@Controller
@RequestMapping(path = "/proof")
public class ProofController {

@Autowired
private AuthenticationService authenticationService;

@Autowired
private ProofService proofService;

// TODO RequestParam image can be added
@PostMapping(path = "/create")
public @ResponseBody ResponseEntity<String> createProof(
@RequestParam String requestedSelfAttestedAttributes,
@RequestParam String revocationFilterType,
@RequestParam String requestedAttributes,
@RequestParam String name,
@RequestParam String requestedPredicates,
@RequestParam String requestedDeviceBindingVerifications,
@RequestParam String version,
@RequestParam String revocationFilterTimes,
@RequestParam(required = false) String authorization) {

if (authenticationService.authentication(authorization) == false) {
return authenticationService.getError();
}

return proofService.createProof(requestedSelfAttestedAttributes, revocationFilterType, requestedAttributes, name, requestedPredicates, requestedDeviceBindingVerifications, version, revocationFilterTimes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ public ResponseEntity<String> issueCredential(String connectionId, String creden
return handleResponse(response);
}

public ResponseEntity<String> createProof(File image,
String requestedSelfAttestedAttributes,
String revocationFilterType,
String requestedAttributes,
String name,
String requestedPredicates,
String requestedDeviceBindingVerifications,
String version,
String revocationFilterTimes) {
String url = baseUrl + "/ctrl/api/v1.0/proof-templates/create";

ResponseEntity<String> response = httpService.executeRequest(url, HttpMethod.POST, String.class,
Pair.of("image", image),
Pair.of("requestedSelfAttestedAttributes", requestedSelfAttestedAttributes),
Pair.of("revocationFilterType", revocationFilterType),
Pair.of("requestedAttributes", requestedAttributes),
Pair.of("name", name),
Pair.of("requestedPredicates", requestedPredicates),
Pair.of("requestedDeviceBindingVerifications", requestedDeviceBindingVerifications),
Pair.of("version", version),
Pair.of("revocationFilterTimes", revocationFilterTimes));

// check response status code
return handleResponse(response);
}

public <T> ResponseEntity<T> handleResponse(ResponseEntity<T> response) {
if (response == null || response.getStatusCode().is2xxSuccessful() == false) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package didentity.amos.digitalIdentity.services;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
public class ProofService {

@Autowired
private LissiApiService lissiApiService;

@Autowired
private ResourceService resourceService;

public ResponseEntity<String> createProof(String requestedSelfAttestedAttributes,
String revocationFilterType,
String requestedAttributes,
String name,
String requestedPredicates,
String requestedDeviceBindingVerifications,
String version,
String revocationFilterTimes) {

File image = resourceService.getDummyPng();
if (image == null) {
return ResponseEntity.status(500).body("Could not find image.");
}

return lissiApiService.createProof(image, requestedSelfAttestedAttributes, revocationFilterType, requestedAttributes, name, requestedPredicates, requestedDeviceBindingVerifications, version, revocationFilterTimes);
}

}

0 comments on commit 2de7f26

Please sign in to comment.