examples/appnet-api-server/src/main/java/com/hedera/hashgraph/identity/hcs/example/appnet/handlers/DemoHandler.java
/**
   * Generates a verifiable credential document containing the driving license. This method uses the zero knowledge feature,
   * so it's including the merkle tree root and a zero knowledge signature in the proof section.
   * The input data comes from request body.
   * It needs both private key to sign the document and the Schnorr secret key to compute the zk signature.
   * Both the keys come from the request header.
   * @param ctx The HTTP context.
   */
Generates a verifiable credential document containing the driving license. This method uses the zero knowledge feature,
so it's including the merkle tree root and a zero knowledge signature in the proof section.
The input data comes from request body.
It needs both private key to sign the document and the Schnorr secret key to compute the zk signature.
Both the keys come from the request header.
@param ctx The HTTP context.
Generates a verifiable credential document containing the driving license . This method uses the zero knowledge feature so it ' s including the merkle tree root and a zero knowledge signature in the proof section . The input data comes from request body . It needs both private key to sign the document and the Schnorr secret key to compute the zk signature . Both the keys come from the request header . @param ctx The HTTP context .
public void generateZeroKnowledgeDrivingLicense(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 with zero knowledge for: " + req.getOwner());
      try {
        DrivingLicenseZeroKnowledgeDocument vc = new DrivingLicenseZeroKnowledgeDocument();
        DrivingLicenseZeroKnowledgeVcMarshaller presenter = new DrivingLicenseZeroKnowledgeVcMarshaller();
        vc.setIssuer(req.getIssuer());
        vc.setIssuanceDate(Instant.now());
        DrivingLicense drivingLicense = new DrivingLicense(req.getOwner(), req.getFirstName(), req.getLastName(),
                req.getDrivingLicenseCategories(), req.getBirthDate());
        vc.addCredentialSubject(drivingLicense);
        CredentialSchema schema = new CredentialSchema(
                "http://localhost:5050/driving-license-schema.json",
                DrivingLicenseDocument.CREDENTIAL_SCHEMA_TYPE
        );
        vc.setCredentialSchema(schema);
        PrivateKey privateKey = getPrivateKeyFromHeader(ctx);
        SchnorrSecretKey schnorrSecretKey = getSchnorrSecretKeyFromHeader(ctx);
        Ed25519CredentialProof proof = new Ed25519CredentialProof(req.getIssuer());
        proof.sign(privateKey, presenter.fromDocumentToString(vc));
        vc.setProof(proof);
        ZkSignature<DrivingLicense> zkSignature = new ZkSignature<>(
                new MerkleTreeFactoryImpl()
        );
        zkSignature.sign(schnorrSecretKey.serializeSecretKey(), vc);
        vc.setZeroKnowledgeSignature(zkSignature);
        storage.registerCredentialIssuance(vc.toCredentialHash(), privateKey.getPublicKey());
        ctx.render(presenter.fromDocumentToString(vc));
      } catch (Exception e) {
        ctx.getResponse().status(Status.INTERNAL_SERVER_ERROR);
        ctx.render(Jackson.json(new ErrorResponse("Driving license generation failed.", e)));
      }
    });
  }
public void generateZeroKnowledgeDrivingLicense ( 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 with zero knowledge for: " + req . getOwner ( ) ) ; try { DrivingLicenseZeroKnowledgeDocument vc = new DrivingLicenseZeroKnowledgeDocument ( ) ; DrivingLicenseZeroKnowledgeVcMarshaller presenter = new DrivingLicenseZeroKnowledgeVcMarshaller ( ) ; vc . setIssuer ( req . getIssuer ( ) ) ; vc . setIssuanceDate ( Instant . now ( ) ) ; DrivingLicense drivingLicense = new DrivingLicense ( req . getOwner ( ) , req . getFirstName ( ) , req . getLastName ( ) , req . getDrivingLicenseCategories ( ) , req . getBirthDate ( ) ) ; vc . addCredentialSubject ( drivingLicense ) ; CredentialSchema schema = new CredentialSchema ( "http://localhost:5050/driving-license-schema.json" , DrivingLicenseDocument . CREDENTIAL_SCHEMA_TYPE ) ; vc . setCredentialSchema ( schema ) ; PrivateKey privateKey = getPrivateKeyFromHeader ( ctx ) ; SchnorrSecretKey schnorrSecretKey = getSchnorrSecretKeyFromHeader ( ctx ) ; Ed25519CredentialProof proof = new Ed25519CredentialProof ( req . getIssuer ( ) ) ; proof . sign ( privateKey , presenter . fromDocumentToString ( vc ) ) ; vc . setProof ( proof ) ; ZkSignature < DrivingLicense > zkSignature = new ZkSignature < > ( new MerkleTreeFactoryImpl ( ) ) ; zkSignature . sign ( schnorrSecretKey . serializeSecretKey ( ) , vc ) ; vc . setZeroKnowledgeSignature ( zkSignature ) ; storage . registerCredentialIssuance ( vc . toCredentialHash ( ) , privateKey . getPublicKey ( ) ) ; ctx . render ( presenter . fromDocumentToString ( vc ) ) ; } catch ( Exception e ) { ctx . getResponse ( ) . status ( Status . INTERNAL_SERVER_ERROR ) ; ctx . render ( Jackson . json ( new ErrorResponse ( "Driving license generation failed." , e ) ) ) ; } } ) ; }
Generates a verifiable credential document containing the driving license.
Generates a verifiable credential document containing the 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; // }