Search in sources :

Example 6 with PrivacyViolationException

use of com.quorum.tessera.transaction.exception.PrivacyViolationException in project tessera by ConsenSys.

the class PrivacyGroupManagerImpl method createPrivacyGroup.

@Override
public PrivacyGroup createPrivacyGroup(String name, String description, PublicKey from, List<PublicKey> members, byte[] seed) {
    final Set<PublicKey> localKeys = enclave.getPublicKeys();
    if (!members.contains(from)) {
        throw new PrivacyViolationException("The list of members in a privacy group should include self");
    }
    final byte[] groupIdBytes = privacyGroupUtil.generateId(members, seed);
    final PrivacyGroup created = PrivacyGroup.Builder.create().withPrivacyGroupId(groupIdBytes).withName(name).withDescription(description).withMembers(members).withSeed(seed).withType(PrivacyGroup.Type.PANTHEON).withState(PrivacyGroup.State.ACTIVE).build();
    final byte[] lookupId = privacyGroupUtil.generateLookupId(members);
    final byte[] encodedData = privacyGroupUtil.encode(created);
    final List<PublicKey> forwardingMembers = members.stream().filter(Predicate.not(localKeys::contains)).collect(Collectors.toList());
    privacyGroupDAO.save(new PrivacyGroupEntity(groupIdBytes, lookupId, encodedData), () -> {
        publisher.publishPrivacyGroup(encodedData, forwardingMembers);
        return null;
    });
    return created;
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) PrivacyViolationException(com.quorum.tessera.transaction.exception.PrivacyViolationException) PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup)

Aggregations

PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)6 PublicKey (com.quorum.tessera.encryption.PublicKey)4 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)3 PrivacyGroupEntity (com.quorum.tessera.data.PrivacyGroupEntity)2 Config (com.quorum.tessera.config.Config)1 ResidentGroup (com.quorum.tessera.config.ResidentGroup)1 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)1 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)1 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)1 ResidentGroupHandler (com.quorum.tessera.privacygroup.ResidentGroupHandler)1 PersistenceException (jakarta.persistence.PersistenceException)1 Response (jakarta.ws.rs.core.Response)1 java.util (java.util)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1