@Test public void sendRaw() throws UnsupportedEncodingException { byte[] txnData = "KEY".getBytes(); com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class); MessageHash messageHash = mock(MessageHash.class); when(messageHash.getHashBytes()).thenReturn(txnData); when(sendResponse.getTransactionHash()).thenReturn(messageHash); when(transactionManager.defaultPublicKey()).thenReturn(mock(PublicKey.class)); when(transactionManager.send(any(com.quorum.tessera.transaction.SendRequest.class))).thenReturn(sendResponse); Response result = transactionResource.sendRaw("", "someone", "".getBytes()); assertThat(result.getStatus()).isEqualTo(200); assertThat(result.getEntity()).isEqualTo(Base64.getEncoder().encodeToString(txnData)); verify(transactionManager).send(any(com.quorum.tessera.transaction.SendRequest.class)); verify(transactionManager).defaultPublicKey(); }
@ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, message = "Encoded Key", response = String.class), @ApiResponse(code = 500, message = "Unknown server error") }) @POST @Path("sendraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) public Response sendRaw( @HeaderParam("c11n-from") final String sender, @HeaderParam("c11n-to") final String recipientKeys, @NotNull @Size(min = 1) final byte[] payload) throws UnsupportedEncodingException { PublicKey senderKey = Optional.ofNullable(sender) .filter(Predicate.not(String::isEmpty)) .map(Base64.getDecoder()::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); List<PublicKey> receipents = Stream.of(recipientKeys) .filter(Objects::nonNull) .filter(s -> !Objects.equals("", s)) .map(v -> v.split(",")) .flatMap(Arrays::stream) .map(Base64.getDecoder()::decode) .map(PublicKey::from).collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withSender(senderKey) .withRecipients(receipents) .withPayload(payload) .build(); final com.quorum.tessera.transaction.SendResponse sendResponse = transactionManager.send(request); final String encodedTransactionHash = Optional.of(sendResponse) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString).get(); LOGGER.debug("Encoded key: {}", encodedTransactionHash); URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedTransactionHash, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.OK).entity(encodedTransactionHash).location(location).build(); }
TransactionResource { @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, message = "Encoded Key", response = String.class), @ApiResponse(code = 500, message = "Unknown server error") }) @POST @Path("sendraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) public Response sendRaw( @HeaderParam("c11n-from") final String sender, @HeaderParam("c11n-to") final String recipientKeys, @NotNull @Size(min = 1) final byte[] payload) throws UnsupportedEncodingException { PublicKey senderKey = Optional.ofNullable(sender) .filter(Predicate.not(String::isEmpty)) .map(Base64.getDecoder()::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); List<PublicKey> receipents = Stream.of(recipientKeys) .filter(Objects::nonNull) .filter(s -> !Objects.equals("", s)) .map(v -> v.split(",")) .flatMap(Arrays::stream) .map(Base64.getDecoder()::decode) .map(PublicKey::from).collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withSender(senderKey) .withRecipients(receipents) .withPayload(payload) .build(); final com.quorum.tessera.transaction.SendResponse sendResponse = transactionManager.send(request); final String encodedTransactionHash = Optional.of(sendResponse) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString).get(); LOGGER.debug("Encoded key: {}", encodedTransactionHash); URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedTransactionHash, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.OK).entity(encodedTransactionHash).location(location).build(); } }
TransactionResource { @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, message = "Encoded Key", response = String.class), @ApiResponse(code = 500, message = "Unknown server error") }) @POST @Path("sendraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) public Response sendRaw( @HeaderParam("c11n-from") final String sender, @HeaderParam("c11n-to") final String recipientKeys, @NotNull @Size(min = 1) final byte[] payload) throws UnsupportedEncodingException { PublicKey senderKey = Optional.ofNullable(sender) .filter(Predicate.not(String::isEmpty)) .map(Base64.getDecoder()::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); List<PublicKey> receipents = Stream.of(recipientKeys) .filter(Objects::nonNull) .filter(s -> !Objects.equals("", s)) .map(v -> v.split(",")) .flatMap(Arrays::stream) .map(Base64.getDecoder()::decode) .map(PublicKey::from).collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withSender(senderKey) .withRecipients(receipents) .withPayload(payload) .build(); final com.quorum.tessera.transaction.SendResponse sendResponse = transactionManager.send(request); final String encodedTransactionHash = Optional.of(sendResponse) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString).get(); LOGGER.debug("Encoded key: {}", encodedTransactionHash); URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedTransactionHash, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.OK).entity(encodedTransactionHash).location(location).build(); } TransactionResource(TransactionManager transactionManager); }
TransactionResource { @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, message = "Encoded Key", response = String.class), @ApiResponse(code = 500, message = "Unknown server error") }) @POST @Path("sendraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) public Response sendRaw( @HeaderParam("c11n-from") final String sender, @HeaderParam("c11n-to") final String recipientKeys, @NotNull @Size(min = 1) final byte[] payload) throws UnsupportedEncodingException { PublicKey senderKey = Optional.ofNullable(sender) .filter(Predicate.not(String::isEmpty)) .map(Base64.getDecoder()::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); List<PublicKey> receipents = Stream.of(recipientKeys) .filter(Objects::nonNull) .filter(s -> !Objects.equals("", s)) .map(v -> v.split(",")) .flatMap(Arrays::stream) .map(Base64.getDecoder()::decode) .map(PublicKey::from).collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withSender(senderKey) .withRecipients(receipents) .withPayload(payload) .build(); final com.quorum.tessera.transaction.SendResponse sendResponse = transactionManager.send(request); final String encodedTransactionHash = Optional.of(sendResponse) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString).get(); LOGGER.debug("Encoded key: {}", encodedTransactionHash); URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedTransactionHash, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.OK).entity(encodedTransactionHash).location(location).build(); } TransactionResource(TransactionManager transactionManager); @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, response = SendResponse.class, message = "Send response"), @ApiResponse(code = 400, message = "For unknown and unknown keys") }) @POST @Path("send") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) Response send(
            @ApiParam(name = "sendRequest", required = true) @NotNull @Valid
                    final SendRequest sendRequest); @ApiOperation(value = "Send private raw transaction payload") @ApiResponses({ @ApiResponse(code = 200, response = SendResponse.class, message = "Send response"), @ApiResponse(code = 400, message = "For unknown and unknown keys") }) @POST @Path("sendsignedtx") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) Response sendSignedTransaction(
            @HeaderParam("c11n-to") final String recipientKeys, @NotNull @Size(min = 1) final byte[] signedTransaction); @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, message = "Encoded Key", response = String.class), @ApiResponse(code = 500, message = "Unknown server error") }) @POST @Path("sendraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) Response sendRaw(
            @HeaderParam("c11n-from") final String sender,
            @HeaderParam("c11n-to") final String recipientKeys,
            @NotNull @Size(min = 1) final byte[] payload); @ApiOperation(value = "Returns decrypted payload back to Quorum") @ApiResponses({@ApiResponse(code = 200, response = ReceiveResponse.class, message = "Receive Response object")}) @GET @Path("/transaction/{hash}") @Produces(APPLICATION_JSON) Response receive(
            @ApiParam("Encoded hash used to decrypt the payload") @NotNull @Valid @PathParam("hash") final String hash,
            @ApiParam("Encoded recipient key") @Valid @QueryParam("to") final String toStr); @GET @Path("/receive") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) Response receive(@Valid final ReceiveRequest request); @ApiOperation(value = "Submit keys to retrieve payload and decrypt it") @ApiResponses({@ApiResponse(code = 200, message = "Raw payload", response = byte[].class)}) @GET @Path("receiveraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(APPLICATION_OCTET_STREAM) Response receiveRaw(
            @ApiParam("Encoded transaction hash") @NotNull @HeaderParam(value = "c11n-key") String hash,
            @ApiParam("Encoded Recipient Public Key") @HeaderParam(value = "c11n-to") String recipientKey); @Deprecated @ApiOperation("Deprecated: Replaced by /transaction/{key} DELETE HTTP method") @ApiResponses({ @ApiResponse(code = 200, message = "Status message", response = String.class), @ApiResponse(code = 404, message = "If the entity doesn't exist") }) @POST @Path("delete") @Consumes(APPLICATION_JSON) @Produces(TEXT_PLAIN) Response delete(
            @ApiParam(name = "deleteRequest", required = true, value = "Key data to be deleted") @Valid
                    final DeleteRequest deleteRequest); @ApiOperation("Delete single transaction from P2PRestApp node") @ApiResponses({ @ApiResponse(code = 204, message = "Successful deletion"), @ApiResponse(code = 404, message = "If the entity doesn't exist") }) @DELETE @Path("/transaction/{key}") Response deleteKey(@ApiParam("Encoded hash") @PathParam("key") final String key); @GET @Path("/transaction/{key}/isSender") Response isSender(@ApiParam("Encoded hash") @PathParam("key") final String ptmHash); @GET @Path("/transaction/{key}/participants") Response getParticipants(@ApiParam("Encoded hash") @PathParam("key") final String ptmHash); }
TransactionResource { @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, message = "Encoded Key", response = String.class), @ApiResponse(code = 500, message = "Unknown server error") }) @POST @Path("sendraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) public Response sendRaw( @HeaderParam("c11n-from") final String sender, @HeaderParam("c11n-to") final String recipientKeys, @NotNull @Size(min = 1) final byte[] payload) throws UnsupportedEncodingException { PublicKey senderKey = Optional.ofNullable(sender) .filter(Predicate.not(String::isEmpty)) .map(Base64.getDecoder()::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); List<PublicKey> receipents = Stream.of(recipientKeys) .filter(Objects::nonNull) .filter(s -> !Objects.equals("", s)) .map(v -> v.split(",")) .flatMap(Arrays::stream) .map(Base64.getDecoder()::decode) .map(PublicKey::from).collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withSender(senderKey) .withRecipients(receipents) .withPayload(payload) .build(); final com.quorum.tessera.transaction.SendResponse sendResponse = transactionManager.send(request); final String encodedTransactionHash = Optional.of(sendResponse) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString).get(); LOGGER.debug("Encoded key: {}", encodedTransactionHash); URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedTransactionHash, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.OK).entity(encodedTransactionHash).location(location).build(); } TransactionResource(TransactionManager transactionManager); @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, response = SendResponse.class, message = "Send response"), @ApiResponse(code = 400, message = "For unknown and unknown keys") }) @POST @Path("send") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) Response send(
            @ApiParam(name = "sendRequest", required = true) @NotNull @Valid
                    final SendRequest sendRequest); @ApiOperation(value = "Send private raw transaction payload") @ApiResponses({ @ApiResponse(code = 200, response = SendResponse.class, message = "Send response"), @ApiResponse(code = 400, message = "For unknown and unknown keys") }) @POST @Path("sendsignedtx") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) Response sendSignedTransaction(
            @HeaderParam("c11n-to") final String recipientKeys, @NotNull @Size(min = 1) final byte[] signedTransaction); @ApiOperation(value = "Send private transaction payload") @ApiResponses({ @ApiResponse(code = 200, message = "Encoded Key", response = String.class), @ApiResponse(code = 500, message = "Unknown server error") }) @POST @Path("sendraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(TEXT_PLAIN) Response sendRaw(
            @HeaderParam("c11n-from") final String sender,
            @HeaderParam("c11n-to") final String recipientKeys,
            @NotNull @Size(min = 1) final byte[] payload); @ApiOperation(value = "Returns decrypted payload back to Quorum") @ApiResponses({@ApiResponse(code = 200, response = ReceiveResponse.class, message = "Receive Response object")}) @GET @Path("/transaction/{hash}") @Produces(APPLICATION_JSON) Response receive(
            @ApiParam("Encoded hash used to decrypt the payload") @NotNull @Valid @PathParam("hash") final String hash,
            @ApiParam("Encoded recipient key") @Valid @QueryParam("to") final String toStr); @GET @Path("/receive") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) Response receive(@Valid final ReceiveRequest request); @ApiOperation(value = "Submit keys to retrieve payload and decrypt it") @ApiResponses({@ApiResponse(code = 200, message = "Raw payload", response = byte[].class)}) @GET @Path("receiveraw") @Consumes(APPLICATION_OCTET_STREAM) @Produces(APPLICATION_OCTET_STREAM) Response receiveRaw(
            @ApiParam("Encoded transaction hash") @NotNull @HeaderParam(value = "c11n-key") String hash,
            @ApiParam("Encoded Recipient Public Key") @HeaderParam(value = "c11n-to") String recipientKey); @Deprecated @ApiOperation("Deprecated: Replaced by /transaction/{key} DELETE HTTP method") @ApiResponses({ @ApiResponse(code = 200, message = "Status message", response = String.class), @ApiResponse(code = 404, message = "If the entity doesn't exist") }) @POST @Path("delete") @Consumes(APPLICATION_JSON) @Produces(TEXT_PLAIN) Response delete(
            @ApiParam(name = "deleteRequest", required = true, value = "Key data to be deleted") @Valid
                    final DeleteRequest deleteRequest); @ApiOperation("Delete single transaction from P2PRestApp node") @ApiResponses({ @ApiResponse(code = 204, message = "Successful deletion"), @ApiResponse(code = 404, message = "If the entity doesn't exist") }) @DELETE @Path("/transaction/{key}") Response deleteKey(@ApiParam("Encoded hash") @PathParam("key") final String key); @GET @Path("/transaction/{key}/isSender") Response isSender(@ApiParam("Encoded hash") @PathParam("key") final String ptmHash); @GET @Path("/transaction/{key}/participants") Response getParticipants(@ApiParam("Encoded hash") @PathParam("key") final String ptmHash);  }