examples/appnet-api-server/src/main/java/com/hedera/hashgraph/identity/hcs/example/appnet/handlers/DemoHandler.java
/**
   * Method to generate an above-age presentation from a VC document containing the user's birthdate.
   * The input data comes from request body.
   * The user's and authority's public keys come from the request header.
   * The generated presentation is sent in the response body.
   *
   * @param ctx The HTTP context.
   */
Method to generate an above-age presentation from a VC document containing the user's birthdate.
The input data comes from request body.
The user's and authority's public keys come from the request header.
The generated presentation is sent in the response body.

@param ctx The HTTP context.
Method to generate an above - age presentation from a VC document containing the user ' s birthdate . The input data comes from request body . The user ' s and authority ' s public keys come from the request header . The generated presentation is sent in the response body . @param ctx The HTTP context .
public void generateDrivingAboveAgePresentation(final Context ctx) {
    ctx.getRequest().getBody().then(data -> {
      JsonObject req;
      DrivingLicenseZeroKnowledgeDocument doc;
      try {
        req = JsonUtils.getGson().fromJson(data.getText(), JsonObject.class);
        DrivingLicenseZeroKnowledgeVcMarshaller presenter = new DrivingLicenseZeroKnowledgeVcMarshaller();
        doc = presenter.fromStringToDocument(JsonUtils.getGson().toJson(req.get("verifiableCredential")));
      } catch (Exception e) {
        ctx.getResponse().status(Status.BAD_REQUEST);
        ctx.render(Jackson.json(new ErrorResponse("Invalid request input.")));
        return;
      }
      try {
        DriverAboveAgeVpMarshaller presenter = new DriverAboveAgeVpMarshaller();
        DrivingLicenseVpGenerator vpGenerator = new DrivingLicenseVpGenerator(
                new ZkSnarkAgeProverProvider(
                        new AgeCircuitProverInteractor(),
                        new AgeCircuitProverDataMapper(new MerkleTreeFactoryImpl())
                )
        );
        String holderPublicKeyBase58 = getBase58PublicKeyFromHeaderByLabel(ctx, "holderPublicKey");
        String holderPublicKey = ByteUtils.toHexString(Base58.decode(holderPublicKeyBase58));
        String authorityPublicKeyBase58 = getBase58PublicKeyFromHeaderByLabel(ctx, "authorityPublicKey");
        String authorityPublicKey = ByteUtils.toHexString(Base58.decode(authorityPublicKeyBase58));
        String secretKey = ByteUtils.toHexString(getSchnorrSecretKeyFromHeader(ctx).serializeSecretKey());
        Map<String, Object> metadataMap = new HashMap<>();
        metadataMap.put("challenge", req.get("challenge").getAsString());
        metadataMap.put("ageThreshold", req.get("ageThreshold").getAsString());
        metadataMap.put("secretKey", secretKey);
        metadataMap.put("dayLabel", req.get("dayLabel").getAsString());
        metadataMap.put("monthLabel", req.get("monthLabel").getAsString());
        metadataMap.put("yearLabel", req.get("yearLabel").getAsString());
        metadataMap.put("holderPublicKey", holderPublicKey);
        metadataMap.put("authorityPublicKey", authorityPublicKey);
        DriverAboveAgePresentation presentation = vpGenerator.generatePresentation(
                Collections.singletonList(doc),
                metadataMap
        );
        ctx.render(presenter.fromDocumentToString(presentation));
      } catch (Exception e) {
        ctx.getResponse().status(Status.INTERNAL_SERVER_ERROR);
        ctx.render(Jackson.json(new ErrorResponse("Cannot generate verifiable presentation document.")));
      }
    });
  }
public void generateDrivingAboveAgePresentation ( final Context ctx ) { ctx . getRequest ( ) . getBody ( ) . then ( data -> { JsonObject req ; DrivingLicenseZeroKnowledgeDocument doc ; try { req = JsonUtils . getGson ( ) . fromJson ( data . getText ( ) , JsonObject . class ) ; DrivingLicenseZeroKnowledgeVcMarshaller presenter = new DrivingLicenseZeroKnowledgeVcMarshaller ( ) ; doc = presenter . fromStringToDocument ( JsonUtils . getGson ( ) . toJson ( req . get ( "verifiableCredential" ) ) ) ; } catch ( Exception e ) { ctx . getResponse ( ) . status ( Status . BAD_REQUEST ) ; ctx . render ( Jackson . json ( new ErrorResponse ( "Invalid request input." ) ) ) ; return ; } try { DriverAboveAgeVpMarshaller presenter = new DriverAboveAgeVpMarshaller ( ) ; DrivingLicenseVpGenerator vpGenerator = new DrivingLicenseVpGenerator ( new ZkSnarkAgeProverProvider ( new AgeCircuitProverInteractor ( ) , new AgeCircuitProverDataMapper ( new MerkleTreeFactoryImpl ( ) ) ) ) ; String holderPublicKeyBase58 = getBase58PublicKeyFromHeaderByLabel ( ctx , "holderPublicKey" ) ; String holderPublicKey = ByteUtils . toHexString ( Base58 . decode ( holderPublicKeyBase58 ) ) ; String authorityPublicKeyBase58 = getBase58PublicKeyFromHeaderByLabel ( ctx , "authorityPublicKey" ) ; String authorityPublicKey = ByteUtils . toHexString ( Base58 . decode ( authorityPublicKeyBase58 ) ) ; String secretKey = ByteUtils . toHexString ( getSchnorrSecretKeyFromHeader ( ctx ) . serializeSecretKey ( ) ) ; Map < String , Object > metadataMap = new HashMap < > ( ) ; metadataMap . put ( "challenge" , req . get ( "challenge" ) . getAsString ( ) ) ; metadataMap . put ( "ageThreshold" , req . get ( "ageThreshold" ) . getAsString ( ) ) ; metadataMap . put ( "secretKey" , secretKey ) ; metadataMap . put ( "dayLabel" , req . get ( "dayLabel" ) . getAsString ( ) ) ; metadataMap . put ( "monthLabel" , req . get ( "monthLabel" ) . getAsString ( ) ) ; metadataMap . put ( "yearLabel" , req . get ( "yearLabel" ) . getAsString ( ) ) ; metadataMap . put ( "holderPublicKey" , holderPublicKey ) ; metadataMap . put ( "authorityPublicKey" , authorityPublicKey ) ; DriverAboveAgePresentation presentation = vpGenerator . generatePresentation ( Collections . singletonList ( doc ) , metadataMap ) ; ctx . render ( presenter . fromDocumentToString ( presentation ) ) ; } catch ( Exception e ) { ctx . getResponse ( ) . status ( Status . INTERNAL_SERVER_ERROR ) ; ctx . render ( Jackson . json ( new ErrorResponse ( "Cannot generate verifiable presentation document." ) ) ) ; } } ) ; }
Method to generate an above-age presentation from a VC document containing the user's birthdate.
Method to generate an above - age presentation from a VC document containing the user ' s birthdate .