examples/appnet-api-server/src/main/java/com/hedera/hashgraph/identity/hcs/example/appnet/handlers/DemoHandler.java
/**
   * Signs the message of a given type with a private key provided in the request header.
   * Writes the signed message into the response body.
   *
   * @param <T>          The type of the message.
   * @param ctx          The HTTP context.
   * @param json         The message as JSON string.
   * @param privateKey   Private key of the signer.
   * @param messageClass The class type of the message.
   */
Signs the message of a given type with a private key provided in the request header.
Writes the signed message into the response body.

@param           The type of the message.
@param ctx          The HTTP context.
@param json         The message as JSON string.
@param privateKey   Private key of the signer.
@param messageClass The class type of the message.
Signs the message of a given type with a private key provided in the request header . Writes the signed message into the response body . @param The type of the message . @param ctx The HTTP context . @param json The message as JSON string . @param privateKey Private key of the signer . @param messageClass The class type of the message .
private <T extends Message> void signAndReturnMessage(final Context ctx, final String json,
                                                        final PrivateKey privateKey,
                                                        final Class<T> messageClass) {
    try {
      MessageEnvelope<T> envelope = MessageEnvelope.fromJson(json, messageClass);
      ctx.render(new String(envelope.sign(privateKey::sign), StandardCharsets.UTF_8));
    } catch (Exception e) {
      ctx.getResponse().status(Status.BAD_REQUEST);
      ctx.render(Jackson.json(new ErrorResponse("Invalid message content received.", e)));
    }
  }
private < T extends Message > void signAndReturnMessage ( final Context ctx , final String json , final PrivateKey privateKey , final Class < T > messageClass ) { try { MessageEnvelope < T > envelope = MessageEnvelope . fromJson ( json , messageClass ) ; ctx . render ( new String ( envelope . sign ( privateKey :: sign ) , StandardCharsets . UTF_8 ) ) ; } catch ( Exception e ) { ctx . getResponse ( ) . status ( Status . BAD_REQUEST ) ; ctx . render ( Jackson . json ( new ErrorResponse ( "Invalid message content received." , e ) ) ) ; } }
Signs the message of a given type with a private key provided in the request header.
Signs the message of a given type with a private key provided in the request header .