examples/appnet-api-server/src/main/java/com/hedera/hashgraph/identity/hcs/example/appnet/handlers/DemoHandler.java
/**
   * Generates a new example verifiable credential document - a driving license.
   * The input data comes from request body.
   * Private key used to create a VC proof comes from the request header.
   * The VC is built manually here for demonstration purposes only.
   * A real-world application should use an RDF or JSON-LD library support to build flexible,
   * extensible and manageable verifiable credential documents.
   *
   * @param ctx The HTTP context.
   */
Generates a new example verifiable credential document - a driving license.
The input data comes from request body.
Private key used to create a VC proof comes from the request header.
The VC is built manually here for demonstration purposes only.
A real-world application should use an RDF or JSON-LD library support to build flexible,
extensible and manageable verifiable credential documents.

@param ctx The HTTP context.
Generates a new example verifiable credential document - a driving license . The input data comes from request body . Private key used to create a VC proof comes from the request header . The VC is built manually here for demonstration purposes only . A real - world application should use an RDF or JSON - LD library support to build flexible extensible and manageable verifiable credential documents . @param ctx The HTTP context .
public void generateDrivingLicense(final Context ctx) {
    ctx.getRequest().getBody().then(data -> {
      DrivingLicenseRequest req;
      try {
        req = JsonUtils.getGson().fromJson(data.getText(), DrivingLicenseRequest.class);
      } catch (Exception e) {
        ctx.getResponse().status(Status.BAD_REQUEST);
        ctx.render(Jackson.json(new ErrorResponse("Invalid request input.")));
        return;
      }
      log.info("Generating new driving license document for: " + req.getOwner());
      try {
        DrivingLicenseDocument vc = new DrivingLicenseDocument();
        vc.setIssuer(req.getIssuer());
        vc.setIssuanceDate(Instant.now());
        vc.addCredentialSubject(
                new DrivingLicense(req.getOwner(), req.getFirstName(), req.getLastName(),
                        req.getDrivingLicenseCategories(), req.getBirthDate()));
        CredentialSchema schema = new CredentialSchema(
                "http://localhost:5050/driving-license-schema.json",
                DrivingLicenseDocument.CREDENTIAL_SCHEMA_TYPE
        );
        vc.setCredentialSchema(schema);
        PrivateKey privateKey = getPrivateKeyFromHeader(ctx);
        Ed25519CredentialProof proof = new Ed25519CredentialProof(req.getIssuer());
        proof.sign(privateKey, vc.toNormalizedJson(true));
        vc.setProof(proof);
        storage.registerCredentialIssuance(vc.toCredentialHash(), privateKey.getPublicKey());
        ctx.render(vc.toNormalizedJson(false));
      } catch (Exception e) {
        ctx.getResponse().status(Status.INTERNAL_SERVER_ERROR);
        ctx.render(Jackson.json(new ErrorResponse("Driving license generation failed.", e)));
      }
    });
  }
public void generateDrivingLicense ( final Context ctx ) { ctx . getRequest ( ) . getBody ( ) . then ( data -> { DrivingLicenseRequest req ; try { req = JsonUtils . getGson ( ) . fromJson ( data . getText ( ) , DrivingLicenseRequest . class ) ; } catch ( Exception e ) { ctx . getResponse ( ) . status ( Status . BAD_REQUEST ) ; ctx . render ( Jackson . json ( new ErrorResponse ( "Invalid request input." ) ) ) ; return ; } log . info ( "Generating new driving license document for: " + req . getOwner ( ) ) ; try { DrivingLicenseDocument vc = new DrivingLicenseDocument ( ) ; vc . setIssuer ( req . getIssuer ( ) ) ; vc . setIssuanceDate ( Instant . now ( ) ) ; vc . addCredentialSubject ( new DrivingLicense ( req . getOwner ( ) , req . getFirstName ( ) , req . getLastName ( ) , req . getDrivingLicenseCategories ( ) , req . getBirthDate ( ) ) ) ; CredentialSchema schema = new CredentialSchema ( "http://localhost:5050/driving-license-schema.json" , DrivingLicenseDocument . CREDENTIAL_SCHEMA_TYPE ) ; vc . setCredentialSchema ( schema ) ; PrivateKey privateKey = getPrivateKeyFromHeader ( ctx ) ; Ed25519CredentialProof proof = new Ed25519CredentialProof ( req . getIssuer ( ) ) ; proof . sign ( privateKey , vc . toNormalizedJson ( true ) ) ; vc . setProof ( proof ) ; storage . registerCredentialIssuance ( vc . toCredentialHash ( ) , privateKey . getPublicKey ( ) ) ; ctx . render ( vc . toNormalizedJson ( false ) ) ; } catch ( Exception e ) { ctx . getResponse ( ) . status ( Status . INTERNAL_SERVER_ERROR ) ; ctx . render ( Jackson . json ( new ErrorResponse ( "Driving license generation failed." , e ) ) ) ; } } ) ; }
Generates a new example verifiable credential document - a driving license.
Generates a new example verifiable credential document - a driving license .
// TODO This check could be enabled in case we want to make sure the Issuer published their DID first. // HcsDidMessage issuer = storage.resolveDid(req.getIssuer()); // if (issuer == null) { // ctx.getResponse().status(Status.BAD_REQUEST); // ctx.render(Jackson.json(new ErrorResponse("The issuer DID could not be resolved: " + req.getIssuer()))); // return; // }