@Test public void sendForRecipient() throws Exception { final Base64.Encoder base64Encoder = Base64.getEncoder(); final SendRequest sendRequest = new SendRequest(); sendRequest.setPayload(base64Encoder.encode("PAYLOAD".getBytes())); sendRequest.setTo(Base64.getEncoder().encodeToString("Mr Benn".getBytes())); final PublicKey sender = mock(PublicKey.class); when(transactionManager.defaultPublicKey()).thenReturn(sender); final com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class); final MessageHash messageHash = mock(MessageHash.class); final byte[] txnData = "TxnData".getBytes(); when(messageHash.getHashBytes()).thenReturn(txnData); when(sendResponse.getTransactionHash()).thenReturn(messageHash); when(transactionManager.send(any(com.quorum.tessera.transaction.SendRequest.class))) .thenReturn(sendResponse); final Response result = transactionResource.send(sendRequest); assertThat(result.getStatus()).isEqualTo(201); assertThat(result.getLocation().getPath()).isEqualTo("transaction/"+ base64Encoder.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, response = SendResponse.class, message = "Send response"), @ApiResponse(code = 400, message = "For unknown and unknown keys") }) @POST @Path("send") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) public Response send( @ApiParam(name = "sendRequest", required = true) @NotNull @Valid final SendRequest sendRequest) throws UnsupportedEncodingException { Base64.Decoder base64Decoder = Base64.getDecoder(); PublicKey sender = Optional.ofNullable(sendRequest.getFrom()) .map(base64Decoder::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); final List<PublicKey> recipientList = Stream.of(sendRequest) .filter(sr -> Objects.nonNull(sr.getTo())) .flatMap(s -> Stream.of(s.getTo())) .map(base64Decoder::decode) .map(PublicKey::from) .collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withRecipients(recipientList) .withSender(sender) .withPayload(sendRequest.getPayload()) .build(); final com.quorum.tessera.transaction.SendResponse response = transactionManager.send(request); final String encodedKey = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .get(); final SendResponse sendResponse = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .map(SendResponse::new) .get(); final URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedKey, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.CREATED).type(APPLICATION_JSON).location(location).entity(sendResponse).build(); }
TransactionResource { @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) public Response send( @ApiParam(name = "sendRequest", required = true) @NotNull @Valid final SendRequest sendRequest) throws UnsupportedEncodingException { Base64.Decoder base64Decoder = Base64.getDecoder(); PublicKey sender = Optional.ofNullable(sendRequest.getFrom()) .map(base64Decoder::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); final List<PublicKey> recipientList = Stream.of(sendRequest) .filter(sr -> Objects.nonNull(sr.getTo())) .flatMap(s -> Stream.of(s.getTo())) .map(base64Decoder::decode) .map(PublicKey::from) .collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withRecipients(recipientList) .withSender(sender) .withPayload(sendRequest.getPayload()) .build(); final com.quorum.tessera.transaction.SendResponse response = transactionManager.send(request); final String encodedKey = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .get(); final SendResponse sendResponse = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .map(SendResponse::new) .get(); final URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedKey, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.CREATED).type(APPLICATION_JSON).location(location).entity(sendResponse).build(); } }
TransactionResource { @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) public Response send( @ApiParam(name = "sendRequest", required = true) @NotNull @Valid final SendRequest sendRequest) throws UnsupportedEncodingException { Base64.Decoder base64Decoder = Base64.getDecoder(); PublicKey sender = Optional.ofNullable(sendRequest.getFrom()) .map(base64Decoder::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); final List<PublicKey> recipientList = Stream.of(sendRequest) .filter(sr -> Objects.nonNull(sr.getTo())) .flatMap(s -> Stream.of(s.getTo())) .map(base64Decoder::decode) .map(PublicKey::from) .collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withRecipients(recipientList) .withSender(sender) .withPayload(sendRequest.getPayload()) .build(); final com.quorum.tessera.transaction.SendResponse response = transactionManager.send(request); final String encodedKey = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .get(); final SendResponse sendResponse = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .map(SendResponse::new) .get(); final URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedKey, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.CREATED).type(APPLICATION_JSON).location(location).entity(sendResponse).build(); } TransactionResource(TransactionManager transactionManager); }
TransactionResource { @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) public Response send( @ApiParam(name = "sendRequest", required = true) @NotNull @Valid final SendRequest sendRequest) throws UnsupportedEncodingException { Base64.Decoder base64Decoder = Base64.getDecoder(); PublicKey sender = Optional.ofNullable(sendRequest.getFrom()) .map(base64Decoder::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); final List<PublicKey> recipientList = Stream.of(sendRequest) .filter(sr -> Objects.nonNull(sr.getTo())) .flatMap(s -> Stream.of(s.getTo())) .map(base64Decoder::decode) .map(PublicKey::from) .collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withRecipients(recipientList) .withSender(sender) .withPayload(sendRequest.getPayload()) .build(); final com.quorum.tessera.transaction.SendResponse response = transactionManager.send(request); final String encodedKey = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .get(); final SendResponse sendResponse = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .map(SendResponse::new) .get(); final URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedKey, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.CREATED).type(APPLICATION_JSON).location(location).entity(sendResponse).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, response = SendResponse.class, message = "Send response"), @ApiResponse(code = 400, message = "For unknown and unknown keys") }) @POST @Path("send") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) public Response send( @ApiParam(name = "sendRequest", required = true) @NotNull @Valid final SendRequest sendRequest) throws UnsupportedEncodingException { Base64.Decoder base64Decoder = Base64.getDecoder(); PublicKey sender = Optional.ofNullable(sendRequest.getFrom()) .map(base64Decoder::decode) .map(PublicKey::from) .orElseGet(transactionManager::defaultPublicKey); final List<PublicKey> recipientList = Stream.of(sendRequest) .filter(sr -> Objects.nonNull(sr.getTo())) .flatMap(s -> Stream.of(s.getTo())) .map(base64Decoder::decode) .map(PublicKey::from) .collect(Collectors.toList()); com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create() .withRecipients(recipientList) .withSender(sender) .withPayload(sendRequest.getPayload()) .build(); final com.quorum.tessera.transaction.SendResponse response = transactionManager.send(request); final String encodedKey = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .get(); final SendResponse sendResponse = Optional.of(response) .map(com.quorum.tessera.transaction.SendResponse::getTransactionHash) .map(MessageHash::getHashBytes) .map(Base64.getEncoder()::encodeToString) .map(SendResponse::new) .get(); final URI location = UriBuilder.fromPath("transaction") .path(URLEncoder.encode(encodedKey, StandardCharsets.UTF_8.toString())) .build(); return Response.status(Status.CREATED).type(APPLICATION_JSON).location(location).entity(sendResponse).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);  }