use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EncoderCompatibilityTest method encodeDecodeV3PrivateStateValidation.
@Test
public void encodeDecodeV3PrivateStateValidation() {
final V3EncodedPayload payload = V3EncodedPayload.Builder.create().withSenderKey(PublicKey.from("SENDER".getBytes())).withCipherText("CIPHER_TEXT".getBytes()).withCipherTextNonce(new Nonce("NONCE".getBytes())).withRecipientBoxes(singletonList("recipientBox".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(List.of(PublicKey.from("KEY1".getBytes()))).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withAffectedContractTransactions(Map.of(TxHash.from("hash1".getBytes()), "1".getBytes(), TxHash.from("hash2".getBytes()), "2".getBytes())).withExecHash("EXEC_HASH".getBytes()).withPrivacyGroupId(PrivacyGroup.Id.fromBytes("GROUP_ID".getBytes())).build();
final byte[] encoded = v3Encoder.encode(payload);
final V3EncodedPayload result = v3Encoder.decode(encoded);
assertThat(result.getSenderKey()).isEqualTo(payload.getSenderKey());
assertThat(result.getCipherText()).isEqualTo(payload.getCipherText());
assertThat(result.getCipherTextNonce()).isEqualTo(payload.getCipherTextNonce());
assertThat(result.getRecipientBoxes()).isEqualTo(payload.getRecipientBoxes());
assertThat(result.getRecipientNonce()).isEqualTo(payload.getRecipientNonce());
assertThat(result.getRecipientKeys()).isEqualTo(payload.getRecipientKeys());
assertThat(result.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
assertThat(result.getAffectedContractTransactions()).isEqualTo(payload.getAffectedContractTransactions());
assertThat(result.getExecHash()).isEqualTo(payload.getExecHash());
assertThat(result.getPrivacyGroupId()).isEqualTo(payload.getPrivacyGroupId());
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EncoderCompatibilityTest method v4ToLegacy.
@Test
public void v4ToLegacy() {
final EncodedPayload payload = EncodedPayload.Builder.create().withSenderKey(PublicKey.from("SENDER".getBytes())).withCipherText("CIPHER_TEXT".getBytes()).withCipherTextNonce(new Nonce("NONCE".getBytes())).withRecipientBoxes(singletonList("recipientBox".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(List.of(PublicKey.from("KEY1".getBytes()))).withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).withAffectedContractTransactions(emptyMap()).build();
final byte[] encoded = v4Encoder.encode(payload);
final LegacyEncodedPayload legacy = legacyEncoder.decode(encoded);
final List<RecipientBox> boxes = legacy.getRecipientBoxes().stream().map(RecipientBox::from).collect(Collectors.toList());
assertThat(legacy.getSenderKey()).isEqualTo(payload.getSenderKey());
assertThat(legacy.getCipherText()).isEqualTo(payload.getCipherText());
assertThat(legacy.getCipherTextNonce()).isEqualTo(payload.getCipherTextNonce());
assertThat(boxes).isEqualTo(payload.getRecipientBoxes());
assertThat(legacy.getRecipientNonce()).isEqualTo(payload.getRecipientNonce());
assertThat(legacy.getRecipientKeys()).isEqualTo(payload.getRecipientKeys());
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EncoderCompatibilityTest method v4ToV3.
@Test
public void v4ToV3() {
// Payload to a v3 node should not have mandatoryRecipients
final EncodedPayload payload = EncodedPayload.Builder.create().withSenderKey(PublicKey.from("SENDER".getBytes())).withCipherText("CIPHER_TEXT".getBytes()).withCipherTextNonce(new Nonce("NONCE".getBytes())).withRecipientBoxes(singletonList("recipientBox".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(List.of(PublicKey.from("KEY1".getBytes()))).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withAffectedContractTransactions(Map.of(TxHash.from("hash".getBytes()), "hash".getBytes())).withExecHash("EXEC_HASH".getBytes()).withPrivacyGroupId(PrivacyGroup.Id.fromBytes("group".getBytes())).build();
final byte[] encoded = v4Encoder.encode(payload);
final V3EncodedPayload v3Payload = v3Encoder.decode(encoded);
assertThat(v3Payload.getSenderKey()).isEqualTo(payload.getSenderKey());
assertThat(v3Payload.getCipherText()).isEqualTo(payload.getCipherText());
assertThat(v3Payload.getCipherTextNonce()).isEqualTo(payload.getCipherTextNonce());
assertThat(v3Payload.getRecipientBoxes()).isEqualTo(payload.getRecipientBoxes());
assertThat(v3Payload.getRecipientNonce()).isEqualTo(payload.getRecipientNonce());
assertThat(v3Payload.getRecipientKeys()).isEqualTo(payload.getRecipientKeys());
// Enhanced privacy values
assertThat(v3Payload.getPrivacyMode()).isEqualTo(payload.getPrivacyMode());
assertThat(v3Payload.getAffectedContractTransactions()).isEqualTo(payload.getAffectedContractTransactions());
assertThat(v3Payload.getExecHash()).isEqualTo(payload.getExecHash());
assertThat(v3Payload.getPrivacyGroupId().get().getBytes()).isEqualTo("group".getBytes());
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EncoderCompatibilityTest method v3ToV2NonPsv.
@Test
public void v3ToV2NonPsv() {
// Payload to a v2 node should not have privacyGroupId
final V3EncodedPayload payload = V3EncodedPayload.Builder.create().withSenderKey(PublicKey.from("SENDER".getBytes())).withCipherText("CIPHER_TEXT".getBytes()).withCipherTextNonce(new Nonce("NONCE".getBytes())).withRecipientBoxes(singletonList("recipientBox".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(List.of(PublicKey.from("KEY1".getBytes()))).withPrivacyMode(PrivacyMode.PARTY_PROTECTION).withAffectedContractTransactions(Map.of(TxHash.from("hash".getBytes()), "hash".getBytes())).build();
final byte[] encoded = v3Encoder.encode(payload);
final V2EncodedPayload v2Payload = v2Encoder.decode(encoded);
assertThat(v2Payload.getSenderKey()).isEqualTo(payload.getSenderKey());
assertThat(v2Payload.getCipherText()).isEqualTo(payload.getCipherText());
assertThat(v2Payload.getCipherTextNonce()).isEqualTo(payload.getCipherTextNonce());
assertThat(v2Payload.getRecipientBoxes()).isEqualTo(payload.getRecipientBoxes());
assertThat(v2Payload.getRecipientNonce()).isEqualTo(payload.getRecipientNonce());
assertThat(v2Payload.getRecipientKeys()).isEqualTo(payload.getRecipientKeys());
// Enhanced privacy values
assertThat(v2Payload.getPrivacyMode()).isEqualTo(payload.getPrivacyMode());
assertThat(v2Payload.getAffectedContractTransactions()).isEqualTo(payload.getAffectedContractTransactions());
assertThat(v2Payload.getExecHash()).isNullOrEmpty();
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class EncoderCompatibilityTest method legacyToV3.
@Test
public void legacyToV3() {
final LegacyEncodedPayload legacyPayload = new LegacyEncodedPayload(PublicKey.from("SENDER".getBytes()), "cipherText".getBytes(), new Nonce("cipherTextNonce".getBytes()), List.of("box".getBytes()), new Nonce("recipientNonce".getBytes()), List.of(PublicKey.from("RECIPIENT".getBytes())));
final byte[] encoded = legacyEncoder.encode(legacyPayload);
final V3EncodedPayload payload = v3Encoder.decode(encoded);
final List<RecipientBox> boxes = legacyPayload.getRecipientBoxes().stream().map(RecipientBox::from).collect(Collectors.toList());
assertThat(payload.getSenderKey()).isEqualTo(legacyPayload.getSenderKey());
assertThat(payload.getCipherText()).isEqualTo(legacyPayload.getCipherText());
assertThat(payload.getCipherTextNonce()).isEqualTo(legacyPayload.getCipherTextNonce());
assertThat(payload.getRecipientBoxes()).isEqualTo(boxes);
assertThat(payload.getRecipientNonce()).isEqualTo(legacyPayload.getRecipientNonce());
assertThat(payload.getRecipientKeys()).isEqualTo(legacyPayload.getRecipientKeys());
// Default enhanced privacy values
assertThat(payload.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
assertThat(payload.getAffectedContractTransactions()).isEmpty();
assertThat(payload.getExecHash()).isNullOrEmpty();
assertThat(payload.getPrivacyGroupId()).isEmpty();
}
Aggregations