Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
[PAN-2825] eea send raw transaction with privacy group id (#1611)
Browse files Browse the repository at this point in the history
* Add privacy group id to private transaction

* Update enclave send methods to accept privacy group id

* Update eea sendRawTransaction endpoint

* extract privacy group id from private transaction if present
* extract privateFor/privateFrom if privacy group id is not present

* Fix tests

* Change abstract class invocation to concrete class.

* Utility method to load enclave public key
  • Loading branch information
iikirilov authored and ekellstrand committed Jul 8, 2019
1 parent 779d995 commit 5001528
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.orion.testutil.OrionTestHarness;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.enclave.types.SendRequestLegacy;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void testOrionConnection(final PrivacyNode... otherNodes) {
Arrays.stream(otherNodes).map(node -> node.orion.nodeUrl()).toArray())));
Enclave orionEnclave = new Enclave(orion.clientUrl());
SendRequest sendRequest1 =
new SendRequest(
new SendRequestLegacy(
"SGVsbG8sIFdvcmxkIQ==",
orion.getPublicKeys().get(0),
Arrays.stream(otherNodes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import tech.pegasys.pantheon.enclave.types.ReceiveRequest;
import tech.pegasys.pantheon.enclave.types.ReceiveResponse;
import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.enclave.types.SendRequestLegacy;
import tech.pegasys.pantheon.enclave.types.SendRequestPantheon;
import tech.pegasys.pantheon.enclave.types.SendResponse;

import java.io.IOException;
Expand Down Expand Up @@ -73,7 +75,28 @@ public void testSendAndReceive() throws Exception {
List<String> publicKeys = testHarness.getPublicKeys();

SendRequest sc =
new SendRequest(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
new SendRequestLegacy(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
SendResponse sr = enclave.send(sc);

ReceiveRequest rc = new ReceiveRequest(sr.getKey(), publicKeys.get(0));
ReceiveResponse rr = enclave.receive(rc);

assertEquals(PAYLOAD, new String(rr.getPayload(), UTF_8));
assertNotNull(rr.getPrivacyGroupId());
}

@Test
public void testSendWithPrivacyGroupAndReceive() throws Exception {
List<String> publicKeys = testHarness.getPublicKeys();

CreatePrivacyGroupRequest privacyGroupRequest =
new CreatePrivacyGroupRequest(publicKeys.toArray(new String[0]), publicKeys.get(0), "", "");

PrivacyGroup privacyGroupResponse = enclave.createPrivacyGroup(privacyGroupRequest);

SendRequest sc =
new SendRequestPantheon(
PAYLOAD, publicKeys.get(0), privacyGroupResponse.getPrivacyGroupId());
SendResponse sr = enclave.send(sc);

ReceiveRequest rc = new ReceiveRequest(sr.getKey(), publicKeys.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,13 @@

import static java.nio.charset.StandardCharsets.UTF_8;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({"payload", "from", "to"})
public class SendRequest {
public abstract class SendRequest {
private byte[] payload;
private String from;
private List<String> to;

public SendRequest(
@JsonProperty(value = "payload") final String payload,
@JsonProperty(value = "from") final String from,
@JsonProperty(value = "to") final List<String> to) {
public SendRequest(final String payload, final String from) {
this.payload = payload.getBytes(UTF_8);
this.from = from;
this.to = to;
}

public byte[] getPayload() {
Expand All @@ -41,8 +30,4 @@ public byte[] getPayload() {
public String getFrom() {
return from;
}

public List<String> getTo() {
return to;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.enclave.types;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({"payload", "from", "to"})
public class SendRequestLegacy extends SendRequest {
private List<String> to;

public SendRequestLegacy(
@JsonProperty(value = "payload") final String payload,
@JsonProperty(value = "from") final String from,
@JsonProperty(value = "to") final List<String> to) {
super(payload, from);
this.to = to;
}

public List<String> getTo() {
return to;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.enclave.types;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({"payload", "from", "privacyGroupId"})
public class SendRequestPantheon extends SendRequest {
private String privacyGroupId;

public SendRequestPantheon(
@JsonProperty(value = "payload") final String payload,
@JsonProperty(value = "from") final String from,
@JsonProperty(value = "to") final String privacyGroupId) {
super(payload, from);

this.privacyGroupId = privacyGroupId;
}

public String getPrivacyGroupId() {
return privacyGroupId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tech.pegasys.orion.testutil.OrionTestHarnessFactory;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.enclave.types.SendRequestLegacy;
import tech.pegasys.pantheon.enclave.types.SendResponse;
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.Address;
Expand Down Expand Up @@ -151,7 +152,8 @@ public void testSendAndReceive() throws Exception {
List<String> publicKeys = testHarness.getPublicKeys();

String s = new String(VALID_PRIVATE_TRANSACTION_RLP_BASE64, UTF_8);
SendRequest sc = new SendRequest(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
SendRequest sc =
new SendRequestLegacy(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
SendResponse sr = enclave.send(sc);

PrivacyPrecompiledContract privacyPrecompiledContract =
Expand All @@ -178,7 +180,7 @@ public void testNoPrivateKeyError() throws RuntimeException {
publicKeys.add("noPrivateKey");

String s = new String(VALID_PRIVATE_TRANSACTION_RLP_BASE64, UTF_8);
SendRequest sc = new SendRequest(s, publicKeys.get(0), publicKeys);
SendRequest sc = new SendRequestLegacy(s, publicKeys.get(0), publicKeys);

final Throwable thrown = catchThrowable(() -> enclave.send(sc));

Expand All @@ -191,7 +193,7 @@ public void testWrongPrivateKeyError() throws RuntimeException {
publicKeys.add("noPrivateKenoPrivateKenoPrivateKenoPrivateK");

String s = new String(VALID_PRIVATE_TRANSACTION_RLP_BASE64, UTF_8);
SendRequest sc = new SendRequest(s, publicKeys.get(0), publicKeys);
SendRequest sc = new SendRequestLegacy(s, publicKeys.get(0), publicKeys);

final Throwable thrown = catchThrowable(() -> enclave.send(sc));

Expand Down
Loading

0 comments on commit 5001528

Please sign in to comment.