Skip to content

Commit

Permalink
modified flexibleutil to support ec keys
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Rojo <miguelangel.rojofernandez@mastercard.com>
  • Loading branch information
freemanzMrojo committed Aug 19, 2022
1 parent 4159147 commit 46e2e41
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ public PrivxCreatePrivacyGroupResponse privxCreatePrivacyGroup(
Numeric.toHexString(
PrivateTransactionEncoder.signMessage(
privateTransaction, Credentials.create(creator.getTransactionSigningKey()))));
final String transactionHash = ethSendTransactionRequest.send().getTransactionHash();
final EthSendTransaction ethSendTransaction = ethSendTransactionRequest.send();
final String transactionHash = ethSendTransaction.getTransactionHash();
return new PrivxCreatePrivacyGroupResponse(privacyGroupId.toBase64String(), transactionHash);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ public class FlexiblePrivacyAcceptanceTest extends FlexiblePrivacyAcceptanceTest
private final EnclaveType enclaveType;
private final EnclaveEncryptorType enclaveEncryptorType;

public FlexiblePrivacyAcceptanceTest(final EnclaveType enclaveType, final EnclaveEncryptorType enclaveEncryptorType) {
public FlexiblePrivacyAcceptanceTest(
final EnclaveType enclaveType, final EnclaveEncryptorType enclaveEncryptorType) {
this.enclaveType = enclaveType;
this.enclaveEncryptorType = enclaveEncryptorType;
}

@Parameters(name = "{0} enclave type with {1} encryptor")
public static Collection<Object[]> enclaveParameters() {
return Arrays.asList(
new Object[][] {
{TESSERA, NACL},
{TESSERA, EC}
});
new Object[][] {
{TESSERA, NACL},
{TESSERA, EC}
});
}

private PrivacyNode alice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ public static boolean isGroupAdditionTransaction(final PrivateTransaction privat
public static List<String> getParticipantsFromParameter(final Bytes input) {
final List<String> participants = new ArrayList<>();
final Bytes mungedParticipants = input.slice(4 + 32 + 32);
for (int i = 0; i <= mungedParticipants.size() - 32; i += 32) {
participants.add(mungedParticipants.slice(i, 32).toBase64String());
final int numberOfParticipants = input.slice(32 + 32, 4).toInt();
final int participantSize = mungedParticipants.size() / numberOfParticipants;

for (int i = 0; i <= mungedParticipants.size() - participantSize; i += participantSize) {
participants.add(mungedParticipants.slice(i, participantSize).toBase64String());
}

return participants;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.hyperledger.besu.ethereum.privacy;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;

import org.apache.tuweni.bytes.Bytes;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class FlexibleUtilTest {

@Test
public void testGetParticipantsFromParameter() {
final String parameterNaCl =
"0xb4926e2500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002035695b4cc4b0941e60551d7a19cf30603db5bfc23e5ac43a56f57f25f75486a2a8d9b56a0fe9cd94d60be4413bcb721d3a7be27ed8e28b3a6346df874ee141b";
final String expectedNaClParticipant1 = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
final String expectedNaClParticipant2 = "Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=";

List<String> actualParticipants =
FlexibleUtil.getParticipantsFromParameter(Bytes.fromHexString(parameterNaCl));

assertThat(actualParticipants).hasSize(2);
assertThat(actualParticipants.get(0)).isEqualTo(expectedNaClParticipant1);
assertThat(actualParticipants.get(1)).isEqualTo(expectedNaClParticipant2);

final String parameterEC =
"0xb4926e25000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000023059301306072a8648ce3d020106082a8648ce3d030107034200044bc9c2e2a4ff29da00a13485deab3fe3b0d4b038a1c956d68918d9022cafaa9f5e48392a57547394cfb9f283b09e9151c2f58d64cf80c4c5714fe32fc5db2a303059301306072a8648ce3d020106082a8648ce3d030107034200045c8819a91036e55fb79cdf83a3a6f9af48e252e9ee6fab9b8cf86ac07a4fc4fe38b94621f5128240d467b2a089f4f8de4e70bc47789e264ec7580972714d5bba";
final String expectedECParticipant1 =
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAES8nC4qT/KdoAoTSF3qs/47DUsDihyVbWiRjZAiyvqp9eSDkqV1RzlM+58oOwnpFRwvWNZM+AxMVxT+MvxdsqMA==";
final String expectedECParticipant2 =
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEXIgZqRA25V+3nN+Do6b5r0jiUunub6ubjPhqwHpPxP44uUYh9RKCQNRnsqCJ9PjeTnC8R3ieJk7HWAlycU1bug==";

actualParticipants =
FlexibleUtil.getParticipantsFromParameter(Bytes.fromHexString(parameterEC));

assertThat(actualParticipants).hasSize(2);
assertThat(actualParticipants.get(0)).isEqualTo(expectedECParticipant1);
assertThat(actualParticipants.get(1)).isEqualTo(expectedECParticipant2);
}
}

0 comments on commit 46e2e41

Please sign in to comment.