use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class FlexiblePrivacyController method sendRequest.
private SendResponse sendRequest(final PrivateTransaction privateTransaction, final Optional<PrivacyGroup> maybePrivacyGroup) {
final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
final PrivacyGroup privacyGroup = maybePrivacyGroup.orElseThrow();
final Optional<TransactionProcessingResult> version = privateTransactionSimulator.process(privateTransaction.getPrivacyGroupId().orElseThrow().toBase64String(), buildCallParams(GET_VERSION_METHOD_SIGNATURE));
new VersionedPrivateTransaction(privateTransaction, version).writeTo(rlpOutput);
final List<String> flexiblePrivateFor = privacyGroup.getMembers();
return enclave.send(rlpOutput.encoded().toBase64String(), privateTransaction.getPrivateFrom().toBase64String(), flexiblePrivateFor);
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class FlexiblePrivacyController method findPrivacyGroupByMembers.
@Override
public PrivacyGroup[] findPrivacyGroupByMembers(final List<String> addresses, final String privacyUserId) {
final ArrayList<PrivacyGroup> privacyGroups = new ArrayList<>();
final PrivacyGroupHeadBlockMap privacyGroupHeadBlockMap = privateStateStorage.getPrivacyGroupHeadBlockMap(blockchain.getChainHeadHash()).orElse(PrivacyGroupHeadBlockMap.empty());
privacyGroupHeadBlockMap.keySet().forEach(c -> {
final Optional<PrivacyGroup> maybePrivacyGroup = findPrivacyGroupByGroupId(c.toBase64String(), privacyUserId);
if (maybePrivacyGroup.isPresent() && maybePrivacyGroup.get().getMembers().containsAll(addresses)) {
privacyGroups.add(maybePrivacyGroup.get());
}
});
return privacyGroups.toArray(new PrivacyGroup[0]);
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class PrivacyPrecompiledContractTest method testInvalidPrivateTransaction.
@Test
public void testInvalidPrivateTransaction() {
final Enclave enclave = mock(Enclave.class);
when(enclave.retrievePrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID)).thenReturn(new PrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", Arrays.asList(VALID_BASE64_ENCLAVE_KEY.toBase64String())));
final PrivacyPrecompiledContract contract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, privateStateRootResolver, privateStateGenesisAllocator, "RestrictedPrivacyTest");
contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.invalid(ValidationResult.invalid(TransactionInvalidReason.INCORRECT_NONCE))));
final PrivateTransaction privateTransaction = privateTransactionBesu();
final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
final String privateFrom = privateTransaction.getPrivateFrom().toBase64String();
final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
when(enclave.receive(any(String.class))).thenReturn(response);
final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.EMPTY);
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class MultiTenancyPrivacyControllerTest method sendsBesuTransactionWithPrivacyUserIdInPrivacyGroupAndProducesSuccessfulResponse.
@Test
public void sendsBesuTransactionWithPrivacyUserIdInPrivacyGroupAndProducesSuccessfulResponse() {
final PrivateTransaction transaction = PrivateTransaction.builder().privateFrom(Bytes.fromBase64String(ENCLAVE_PUBLIC_KEY1)).privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)).build();
final PrivacyGroup privacyGroupWithPrivacyUserId = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2));
when(privacyController.createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithPrivacyUserId))).thenReturn(ENCLAVE_KEY);
final String response = multiTenancyPrivacyController.createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithPrivacyUserId));
assertThat(response).isEqualTo(ENCLAVE_KEY);
verify(privacyController).createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithPrivacyUserId));
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class MultiTenancyPrivacyControllerTest method findsPrivacyGroupWhenPrivacyUserIdInAddresses.
@Test
public void findsPrivacyGroupWhenPrivacyUserIdInAddresses() {
final List<String> addresses = List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2);
final PrivacyGroup privacyGroup = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2));
when(privacyController.findPrivacyGroupByMembers(addresses, ENCLAVE_PUBLIC_KEY1)).thenReturn(new PrivacyGroup[] { privacyGroup });
final PrivacyGroup[] privacyGroups = multiTenancyPrivacyController.findPrivacyGroupByMembers(addresses, ENCLAVE_PUBLIC_KEY1);
assertThat(privacyGroups).hasSize(1);
assertThat(privacyGroups[0]).usingRecursiveComparison().isEqualTo(privacyGroup);
verify(privacyController).findPrivacyGroupByMembers(addresses, ENCLAVE_PUBLIC_KEY1);
}
Aggregations