use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResource method delete.
@Deprecated
@Operation(summary = "/delete", operationId = "deleteDeprecated", description = "delete payload from database")
@ApiResponse(responseCode = "200", description = "delete successful", content = @Content(schema = @Schema(type = "string"), examples = @ExampleObject(value = "Delete successful")))
@POST
@Path("delete")
@Consumes(APPLICATION_JSON)
@Produces(TEXT_PLAIN)
public Response delete(@Valid final DeleteRequest deleteRequest) {
LOGGER.debug("Received deprecated delete request");
MessageHash messageHash = Optional.of(deleteRequest).map(DeleteRequest::getKey).map(base64Decoder::decode).map(MessageHash::new).get();
transactionManager.delete(messageHash);
return Response.status(Response.Status.OK).entity("Delete successful").build();
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResource3 method send.
// path /send is overloaded (application/json and application/vnd.tessera-2.1+json); swagger
// annotations cannot
// handle situations like this so this operation documents both
@Operation(summary = "/send", operationId = "encryptStoreAndSendJson", description = "encrypts a payload, stores result in database, and publishes result to recipients", requestBody = @RequestBody(content = { @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = SendRequest.class)), @Content(mediaType = MIME_TYPE_JSON_2_1, schema = @Schema(implementation = SendRequest.class)) }))
@ApiResponse(responseCode = "201", description = "encrypted payload hash", content = { @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = SendResponse.class)), @Content(mediaType = MIME_TYPE_JSON_2_1, schema = @Schema(implementation = SendResponse.class)) })
@ApiResponse(responseCode = "200", description = "hash returned when running in orion mode", content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = SendResponse.class)))
@POST
@Path("send")
@Consumes({ MIME_TYPE_JSON_2_1, MIME_TYPE_JSON_3 })
@Produces({ MIME_TYPE_JSON_2_1, MIME_TYPE_JSON_3 })
public Response send(@NotNull @Valid @PrivacyValid final SendRequest sendRequest) {
final PublicKey sender = Optional.ofNullable(sendRequest.getFrom()).map(base64Decoder::decode).map(PublicKey::from).orElseGet(transactionManager::defaultPublicKey);
final Optional<PrivacyGroup.Id> privacyGroupId = Optional.ofNullable(sendRequest.getPrivacyGroupId()).map(PrivacyGroup.Id::fromBase64String);
final List<PublicKey> recipientList = privacyGroupId.map(privacyGroupManager::retrievePrivacyGroup).map(PrivacyGroup::getMembers).orElse(Stream.of(sendRequest).filter(sr -> Objects.nonNull(sr.getTo())).flatMap(s -> Stream.of(s.getTo())).map(base64Decoder::decode).map(PublicKey::from).collect(Collectors.toList()));
final Set<MessageHash> affectedTransactions = Stream.ofNullable(sendRequest.getAffectedContractTransactions()).flatMap(Arrays::stream).map(base64Decoder::decode).map(MessageHash::new).collect(Collectors.toSet());
final byte[] execHash = Optional.ofNullable(sendRequest.getExecHash()).map(String::getBytes).orElse(new byte[0]);
final PrivacyMode privacyMode = PrivacyMode.fromFlag(sendRequest.getPrivacyFlag());
final com.quorum.tessera.transaction.SendRequest.Builder requestBuilder = com.quorum.tessera.transaction.SendRequest.Builder.create().withRecipients(recipientList).withSender(sender).withPayload(sendRequest.getPayload()).withExecHash(execHash).withPrivacyMode(privacyMode).withAffectedContractTransactions(affectedTransactions);
privacyGroupId.ifPresent(requestBuilder::withPrivacyGroupId);
final com.quorum.tessera.transaction.SendResponse response = transactionManager.send(requestBuilder.build());
final String encodedKey = Optional.of(response).map(com.quorum.tessera.transaction.SendResponse::getTransactionHash).map(MessageHash::getHashBytes).map(base64Encoder::encodeToString).get();
final String[] managedParties = Optional.of(response).map(com.quorum.tessera.transaction.SendResponse::getManagedParties).orElse(Collections.emptySet()).stream().map(PublicKey::encodeToBase64).toArray(String[]::new);
final SendResponse sendResponse = Optional.of(response).map(com.quorum.tessera.transaction.SendResponse::getTransactionHash).map(MessageHash::getHashBytes).map(base64Encoder::encodeToString).map(messageHash -> new SendResponse(messageHash, managedParties, sender.encodeToBase64())).get();
final URI location = UriBuilder.fromPath("transaction").path(URLEncoder.encode(encodedKey, StandardCharsets.UTF_8)).build();
return Response.created(location).entity(sendResponse).build();
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResource3 method deleteKey.
@Operation(summary = "/transaction/{hash}", operationId = "delete", description = "delete payload from database")
@ApiResponse(responseCode = "204", description = "delete successful")
@DELETE
@Path("/transaction/{hash}")
public Response deleteKey(@Parameter(description = "hash indicating encrypted payload to delete from database", schema = @Schema(format = "base64")) @PathParam("hash") final String hash) {
LOGGER.debug("Received delete key request");
MessageHash messageHash = new MessageHash(base64Decoder.decode(hash));
transactionManager.delete(messageHash);
return Response.noContent().build();
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResourceTest method sendForRecipient.
@Test
public void sendForRecipient() {
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);
// jersey.target("send").request().post(Entity.entity(sendRequest,
// MediaType.APPLICATION_JSON));
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();
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResourceTest method sendSignedTransactionWithPrivacy.
@Test
public void sendSignedTransactionWithPrivacy() {
com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class);
byte[] transactionHashData = "I Love Sparrows".getBytes();
final String base64EncodedTransactionHAshData = Base64.getEncoder().encodeToString(transactionHashData);
MessageHash transactionHash = mock(MessageHash.class);
when(transactionHash.getHashBytes()).thenReturn(transactionHashData);
when(sendResponse.getTransactionHash()).thenReturn(transactionHash);
when(transactionManager.sendSignedTransaction(any(com.quorum.tessera.transaction.SendSignedRequest.class))).thenReturn(sendResponse);
final String base64AffectedHash1 = Base64.getEncoder().encodeToString("aHash1".getBytes());
final String base64AffectedHash2 = Base64.getEncoder().encodeToString("aHash2".getBytes());
SendSignedRequest sendSignedRequest = new SendSignedRequest();
sendSignedRequest.setHash("SOMEDATA".getBytes());
sendSignedRequest.setTo("recipient1", "recipient2");
sendSignedRequest.setPrivacyFlag(3);
sendSignedRequest.setAffectedContractTransactions(base64AffectedHash1, base64AffectedHash2);
sendSignedRequest.setExecHash("execHash");
Response result = transactionResource.sendSignedTransactionEnhanced(sendSignedRequest);
// jersey.target("sendsignedtx")
// .request()
// .post(Entity.entity(sendSignedRequest,
// MediaType.APPLICATION_JSON_TYPE));
assertThat(result.getStatus()).isEqualTo(201);
SendResponse resultResponse = SendResponse.class.cast(result.getEntity());
assertThat(resultResponse.getKey()).isEqualTo(base64EncodedTransactionHAshData);
assertThat(result.getLocation()).hasPath("transaction/".concat(base64EncodedTransactionHAshData));
ArgumentCaptor<com.quorum.tessera.transaction.SendSignedRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendSignedRequest.class);
verify(transactionManager).sendSignedTransaction(argumentCaptor.capture());
com.quorum.tessera.transaction.SendSignedRequest obj = argumentCaptor.getValue();
assertThat(obj).isNotNull();
assertThat(obj.getSignedData()).isEqualTo("SOMEDATA".getBytes());
assertThat(obj.getRecipients()).hasSize(2);
assertThat(obj.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
assertThat(obj.getAffectedContractTransactions().stream().map(MessageHash::toString)).hasSize(2).containsExactlyInAnyOrder(base64AffectedHash1, base64AffectedHash2);
assertThat(obj.getExecHash()).isEqualTo("execHash".getBytes());
}
Aggregations