Java Code Examples for org.web3j.utils.Base64String#wrap()

The following examples show how to use org.web3j.utils.Base64String#wrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallPrivateSmartContractFunction.java    From besu with Apache License 2.0 6 votes vote down vote up
private CallPrivateSmartContractFunction(
    final String contractAddress,
    final String encodedFunction,
    final String transactionSigningKey,
    final long chainId,
    final String privateFrom,
    final List<String> privateFor,
    final String privacyGroupId) {

  this.contractAddress = contractAddress;
  this.encodedFunction = encodedFunction;
  this.senderCredentials = Credentials.create(transactionSigningKey);
  this.chainId = chainId;
  this.privateFrom = Base64String.wrap(privateFrom);
  this.privateFor = privateFor != null ? Base64String.wrapList(privateFor) : null;
  this.privacyGroupId = privacyGroupId != null ? Base64String.wrap(privacyGroupId) : null;
}
 
Example 2
Source File: BesuOnChainPrivacyIntegrationTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateAndFindOnChainPrivacyGroup() throws Exception {
    Base64String privacyGroupId = Base64String.wrap(generateRandomBytes(32));
    final String txHash =
            nodeAlice
                    .privOnChainCreatePrivacyGroup(
                            privacyGroupId,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_BOB))
                    .send()
                    .getTransactionHash();

    TransactionReceipt receipt = processor.waitForTransactionReceipt(txHash);
    assertTrue(receipt.isStatusOK());

    List<PrivacyGroup> groups =
            nodeAlice
                    .privOnChainFindPrivacyGroup(
                            Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB))
                    .send()
                    .getGroups();

    assertTrue(groups.stream().anyMatch(x -> x.getPrivacyGroupId().equals(privacyGroupId)));
}
 
Example 3
Source File: EeaSendTransactionJsonParameters.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public EeaSendTransactionJsonParameters(
    @JsonProperty("from") final String sender,
    @JsonProperty("privateFrom") final String privateFrom,
    @JsonProperty("restriction") final String restriction) {
  validateNotEmpty(sender);
  this.privateFrom = Base64String.wrap(privateFrom);
  this.restriction = restriction;
  this.sender = sender;
}
 
Example 4
Source File: PrivacyGroup.java    From web3j with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public PrivacyGroup(
        @JsonProperty(value = "privacyGroupId") final String privacyGroupId,
        @JsonProperty(value = "type") final Type type,
        @JsonProperty(value = "name") final String name,
        @JsonProperty(value = "description") final String description,
        @JsonProperty(value = "members") final List<Base64String> members) {
    this.privacyGroupId = Base64String.wrap(privacyGroupId);
    this.type = type;
    this.name = name;
    this.description = description;
    this.members = members;
}
 
Example 5
Source File: AddToOnChainPrivacyGroupTransaction.java    From besu with Apache License 2.0 5 votes vote down vote up
public AddToOnChainPrivacyGroupTransaction(
    final String privacyGroupId, final PrivacyNode adder, final PrivacyNode... nodes) {
  this.privacyGroupId = Base64String.wrap(privacyGroupId);
  this.adder = adder;
  this.addresses =
      Arrays.stream(nodes)
          .map(n -> n.getOrion().getDefaultPublicKey())
          .collect(Collectors.toList());
}
 
Example 6
Source File: CallOnChainPermissioningPrivateSmartContractFunction.java    From besu with Apache License 2.0 5 votes vote down vote up
public CallOnChainPermissioningPrivateSmartContractFunction(
    final String contractAddress,
    final String encodedFunction,
    final String transactionSigningKey,
    final long chainId,
    final String privateFrom,
    final String privacyGroupId) {

  this.contractAddress = contractAddress;
  this.encodedFunction = encodedFunction;
  this.senderCredentials = Credentials.create(transactionSigningKey);
  this.chainId = chainId;
  this.privateFrom = Base64String.wrap(privateFrom);
  this.privacyGroupId = Base64String.wrap(privacyGroupId);
}
 
Example 7
Source File: DeployPrivateSmartContractWithPrivacyGroupIdTransaction.java    From besu with Apache License 2.0 5 votes vote down vote up
public DeployPrivateSmartContractWithPrivacyGroupIdTransaction(
    final Class<T> clazz,
    final String transactionSigningKey,
    final long chainId,
    final String privateFrom,
    final String privacyGroupId) {
  this.clazz = clazz;
  this.senderCredentials = Credentials.create(transactionSigningKey);
  this.chainId = chainId;
  this.privateFrom = Base64String.wrap(privateFrom);
  this.privacyGroupId = Base64String.wrap(privacyGroupId);
}
 
Example 8
Source File: LoadPrivateSmartContractTransaction.java    From besu with Apache License 2.0 5 votes vote down vote up
public LoadPrivateSmartContractTransaction(
    final String contractAddress,
    final Class<T> clazz,
    final String transactionSigningKey,
    final long chainId,
    final String privateFrom,
    final List<String> privateFor) {

  this.contractAddress = contractAddress;
  this.clazz = clazz;
  this.senderCredentials = Credentials.create(transactionSigningKey);
  this.chainId = chainId;
  this.privateFrom = Base64String.wrap(privateFrom);
  this.privateFor = Base64String.wrapList(privateFor);
}
 
Example 9
Source File: DeployPrivateSmartContractTransaction.java    From besu with Apache License 2.0 5 votes vote down vote up
public DeployPrivateSmartContractTransaction(
    final Class<T> clazz,
    final String transactionSigningKey,
    final long chainId,
    final String privateFrom,
    final List<String> privateFor) {
  this.clazz = clazz;
  this.senderCredentials = Credentials.create(transactionSigningKey);
  this.chainId = chainId;
  this.privateFrom = Base64String.wrap(privateFrom);
  this.privateFor = Base64String.wrapList(privateFor);
}
 
Example 10
Source File: BesuOnChainPrivacyIntegrationTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testCannotAddToAlreadyLockedGroup() throws Exception {
    Base64String privacyGroupId = Base64String.wrap(generateRandomBytes(32));
    final String createTxHash =
            nodeAlice
                    .privOnChainCreatePrivacyGroup(
                            privacyGroupId,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_BOB))
                    .send()
                    .getTransactionHash();

    TransactionReceipt createReceipt = processor.waitForTransactionReceipt(createTxHash);
    assertTrue(createReceipt.isStatusOK());

    final String lockTxHash =
            nodeAlice
                    .privOnChainSetGroupLockState(
                            privacyGroupId, ALICE, ENCLAVE_KEY_ALICE, true)
                    .send()
                    .getTransactionHash();

    TransactionReceipt lockReceipt = processor.waitForTransactionReceipt(lockTxHash);
    assertTrue(lockReceipt.isStatusOK());

    assertThrows(
            TransactionException.class,
            () ->
                    nodeBob.privOnChainAddToPrivacyGroup(
                                    privacyGroupId,
                                    BOB,
                                    ENCLAVE_KEY_BOB,
                                    Collections.singletonList(ENCLAVE_KEY_CHARLIE))
                            .send());
}
 
Example 11
Source File: ResponseTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testPrivGetPrivateTransactionPrivacyGroup() {
    buildResponse(
            "{\n"
                    + "    \"id\":1,\n"
                    + "    \"jsonrpc\":\"2.0\",\n"
                    + "    \"result\": {\n"
                    + "        \"hash\":\"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b\",\n"
                    + "        \"nonce\":\"0x00\",\n"
                    + "        \"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\n"
                    + "        \"to\":\"0x85h43d8a49eeb85d32cf465507dd71d507100c1\",\n"
                    + "        \"value\":\"0x7f110\",\n"
                    + "        \"gas\": \"0x7f110\",\n"
                    + "        \"gasPrice\":\"0x09184e72a000\",\n"
                    + "        \"input\":\"0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360\",\n"
                    + "        \"r\":\"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc\",\n"
                    + "        \"s\":\"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62\",\n"
                    + "        \"v\":\"0x00\",\n"
                    + "        \"privateFrom\":\"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=\",\n"
                    + "        \"privateFor\":\"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=\",\n"
                    + "        \"restriction\":\"restricted\""
                    + "  }\n"
                    + "}");
    PrivateTransactionWithPrivacyGroup privateTransaction =
            new PrivateTransactionWithPrivacyGroup(
                    "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
                    "0x00",
                    "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
                    "0x85h43d8a49eeb85d32cf465507dd71d507100c1",
                    "0x7f110",
                    "0x7f110",
                    "0x09184e72a000",
                    "0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360",
                    "0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc",
                    "0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62",
                    "0x00",
                    Base64String.wrap("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="),
                    Base64String.wrap("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="),
                    "restricted");

    PrivGetPrivateTransaction privPrivateTransaction =
            deserialiseResponse(PrivGetPrivateTransaction.class);
    assertEquals(privPrivateTransaction.getPrivateTransaction().get(), (privateTransaction));
}
 
Example 12
Source File: ResponseTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testPrivGetPrivateTransactionLegacy() {

    buildResponse(
            "{\n"
                    + "    \"id\":1,\n"
                    + "    \"jsonrpc\":\"2.0\",\n"
                    + "    \"result\": {\n"
                    + "        \"hash\":\"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b\",\n"
                    + "        \"nonce\":\"0x00\",\n"
                    + "        \"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\n"
                    + "        \"to\":\"0x85h43d8a49eeb85d32cf465507dd71d507100c1\",\n"
                    + "        \"value\":\"0x7f110\",\n"
                    + "        \"gas\": \"0x7f110\",\n"
                    + "        \"gasPrice\":\"0x09184e72a000\",\n"
                    + "        \"input\":\"0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360\",\n"
                    + "        \"r\":\"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc\",\n"
                    + "        \"s\":\"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62\",\n"
                    + "        \"v\":\"0x00\",\n"
                    + "        \"privateFrom\":\"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=\",\n"
                    + "        \"privateFor\":[\"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=\",\"Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=\"],\n"
                    + "        \"restriction\":\"restricted\""
                    + "  }\n"
                    + "}");
    PrivateTransactionLegacy privateTransaction =
            new PrivateTransactionLegacy(
                    "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
                    "0x00",
                    "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
                    "0x85h43d8a49eeb85d32cf465507dd71d507100c1",
                    "0x7f110",
                    "0x7f110",
                    "0x09184e72a000",
                    "0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360",
                    "0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc",
                    "0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62",
                    "0x00",
                    Base64String.wrap("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="),
                    Base64String.wrapList(
                            "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=",
                            "Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs="),
                    "restricted");

    PrivGetPrivateTransaction privPrivateTransaction =
            deserialiseResponse(PrivGetPrivateTransaction.class);
    assertEquals(privPrivateTransaction.getPrivateTransaction().get(), (privateTransaction));
}
 
Example 13
Source File: PrivateTransactionDecoder.java    From web3j with Apache License 2.0 4 votes vote down vote up
private static Base64String extractBase64(final RlpType value) {
    return Base64String.wrap(((RlpString) value).getBytes());
}
 
Example 14
Source File: BesuOnChainPrivacyIntegrationTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testCannotAddDuplicateMemberToPrivacyGroup() throws Exception {
    Base64String privacyGroupId = Base64String.wrap(generateRandomBytes(32));
    final String txHash =
            nodeAlice
                    .privOnChainCreatePrivacyGroup(
                            privacyGroupId,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_BOB))
                    .send()
                    .getTransactionHash();

    TransactionReceipt receipt = processor.waitForTransactionReceipt(txHash);
    assertTrue(receipt.isStatusOK());

    final String addTxHash =
            nodeAlice
                    .privOnChainAddToPrivacyGroup(
                            privacyGroupId,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_CHARLIE))
                    .send()
                    .getTransactionHash();

    TransactionReceipt addReceipt = processor.waitForTransactionReceipt(addTxHash);
    assertTrue(addReceipt.isStatusOK());

    final String secondAddTxHash =
            nodeAlice
                    .privOnChainAddToPrivacyGroup(
                            privacyGroupId,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_CHARLIE))
                    .send()
                    .getTransactionHash();

    TransactionReceipt secondAddTxReceipt =
            processor.waitForTransactionReceipt(secondAddTxHash);
    assertFalse(secondAddTxReceipt.isStatusOK());
}
 
Example 15
Source File: BesuOnChainPrivacyIntegrationTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testCanExecuteSmartContractsInOnChainPrivacyGroup() throws Exception {
    Base64String aliceBobGroup = Base64String.wrap(generateRandomBytes(32));
    final String createTxHash =
            nodeAlice
                    .privOnChainCreatePrivacyGroup(
                            aliceBobGroup,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_BOB))
                    .send()
                    .getTransactionHash();

    TransactionReceipt createReceipt = processor.waitForTransactionReceipt(createTxHash);
    assertTrue(createReceipt.isStatusOK());

    // Find the privacy group that was built by Alice from Bob's node
    final Base64String aliceBobGroupFromBobNode =
            nodeBob
                    .privOnChainFindPrivacyGroup(
                            Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB))
                    .send().getGroups().stream()
                    .filter(g -> g.getPrivacyGroupId().equals(aliceBobGroup))
                    .findFirst()
                    .orElseThrow(RuntimeException::new)
                    .getPrivacyGroupId();

    final PrivateTransactionManager tmAlice =
            new BesuPrivateTransactionManager(
                    nodeAlice,
                    ZERO_GAS_PROVIDER,
                    ALICE,
                    2018,
                    ENCLAVE_KEY_ALICE,
                    aliceBobGroup);
    final PrivateTransactionManager tmBob =
            new BesuPrivateTransactionManager(
                    nodeBob,
                    ZERO_GAS_PROVIDER,
                    BOB,
                    2018,
                    ENCLAVE_KEY_BOB,
                    aliceBobGroupFromBobNode);

    final HumanStandardToken tokenAlice =
            HumanStandardToken.deploy(
                            nodeAlice,
                            tmAlice,
                            ZERO_GAS_PROVIDER,
                            BigInteger.TEN,
                            "eea_token",
                            BigInteger.TEN,
                            "EEATKN")
                    .send();

    final HumanStandardToken tokenBob =
            HumanStandardToken.load(
                    tokenAlice.getContractAddress(), nodeBob, tmBob, ZERO_GAS_PROVIDER);

    tokenAlice.transfer(BOB.getAddress(), BigInteger.TEN).send();
    testBalances(tokenAlice, tokenBob, BigInteger.ZERO, BigInteger.TEN);
}
 
Example 16
Source File: BesuOnChainPrivacyIntegrationTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateAddRemoveOnChainPrivacyGroup() throws Exception {
    Base64String privacyGroupId = Base64String.wrap(generateRandomBytes(32));
    final String createTxHash =
            nodeAlice
                    .privOnChainCreatePrivacyGroup(
                            privacyGroupId,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_BOB))
                    .send()
                    .getTransactionHash();

    TransactionReceipt createReceipt = processor.waitForTransactionReceipt(createTxHash);
    assertTrue(createReceipt.isStatusOK());

    final String addTxHash =
            nodeAlice
                    .privOnChainAddToPrivacyGroup(
                            privacyGroupId,
                            ALICE,
                            ENCLAVE_KEY_ALICE,
                            Collections.singletonList(ENCLAVE_KEY_CHARLIE))
                    .send()
                    .getTransactionHash();

    TransactionReceipt addReceipt = processor.waitForTransactionReceipt(addTxHash);
    assertTrue(addReceipt.isStatusOK());

    List<PrivacyGroup> groups =
            nodeAlice
                    .privOnChainFindPrivacyGroup(
                            Arrays.asList(
                                    ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB, ENCLAVE_KEY_CHARLIE))
                    .send()
                    .getGroups();
    assertTrue(
            groups.stream()
                    .anyMatch(
                            g ->
                                    g.getPrivacyGroupId().equals(privacyGroupId)
                                            && g.getMembers().size() == 3));

    final String removeTxHash =
            nodeAlice
                    .privOnChainRemoveFromPrivacyGroup(
                            privacyGroupId, ALICE, ENCLAVE_KEY_ALICE, ENCLAVE_KEY_CHARLIE)
                    .send()
                    .getTransactionHash();

    TransactionReceipt removeReceipt = processor.waitForTransactionReceipt(removeTxHash);
    assertTrue(removeReceipt.isStatusOK());

    List<PrivacyGroup> removedGroups =
            nodeAlice
                    .privOnChainFindPrivacyGroup(
                            Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB))
                    .send()
                    .getGroups();
    assertTrue(
            removedGroups.stream()
                    .anyMatch(
                            g ->
                                    g.getPrivacyGroupId().equals(privacyGroupId)
                                            && g.getMembers().size() == 2));
}
 
Example 17
Source File: LockOnChainPrivacyGroupTransaction.java    From besu with Apache License 2.0 4 votes vote down vote up
public LockOnChainPrivacyGroupTransaction(final String privacyGroupId, final PrivacyNode locker) {
  this.privacyGroupId = Base64String.wrap(privacyGroupId);
  this.locker = locker;
}
 
Example 18
Source File: RemoveFromOnChainPrivacyGroupTransaction.java    From besu with Apache License 2.0 4 votes vote down vote up
public RemoveFromOnChainPrivacyGroupTransaction(
    final String privacyGroupId, final PrivacyNode remover, final PrivacyNode toRemove) {
  this.privacyGroupId = Base64String.wrap(privacyGroupId);
  this.remover = remover;
  this.toRemove = toRemove.getOrion().getDefaultPublicKey();
}
 
Example 19
Source File: PrivacyRequestFactory.java    From besu with Apache License 2.0 4 votes vote down vote up
public OnChainPrivacyGroup(final String privacyGroupId, final List<Base64String> members) {
  this.privacyGroupId = Base64String.wrap(privacyGroupId);
  this.name = "";
  this.description = "";
  this.members = members;
}
 
Example 20
Source File: EeaSendRawTransaction.java    From ethsigner with Apache License 2.0 4 votes vote down vote up
private Base64String valueToBase64String(final String value) {
  return value == null ? null : Base64String.wrap(value);
}