Search in sources :

Example 6 with TransactionSignature

use of com.hedera.mirror.common.domain.transaction.TransactionSignature in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method insertTransactionSignatures.

private void insertTransactionSignatures(EntityId entityId, long consensusTimestamp, List<SignaturePair> signaturePairList) {
    Set<ByteString> publicKeyPrefixes = new HashSet<>();
    signaturePairList.forEach(signaturePair -> {
        ByteString prefix = signaturePair.getPubKeyPrefix();
        ByteString signature = null;
        var signatureCase = signaturePair.getSignatureCase();
        int type = signatureCase.getNumber();
        switch(signatureCase) {
            case CONTRACT:
                signature = signaturePair.getContract();
                break;
            case ECDSA_384:
                signature = signaturePair.getECDSA384();
                break;
            case ECDSA_SECP256K1:
                signature = signaturePair.getECDSASecp256K1();
                break;
            case ED25519:
                signature = signaturePair.getEd25519();
                break;
            case RSA_3072:
                signature = signaturePair.getRSA3072();
                break;
            case SIGNATURE_NOT_SET:
                Map<Integer, UnknownFieldSet.Field> unknownFields = signaturePair.getUnknownFields().asMap();
                // field that has exactly one length-delimited value and assume it's our new signature bytes.
                for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.entrySet()) {
                    UnknownFieldSet.Field field = entry.getValue();
                    if (field.getLengthDelimitedList().size() == 1) {
                        signature = field.getLengthDelimitedList().get(0);
                        type = entry.getKey();
                        break;
                    }
                }
                if (signature == null) {
                    throw new InvalidDatasetException("Unsupported signature: " + unknownFields);
                }
                break;
            default:
                throw new InvalidDatasetException("Unsupported signature: " + signaturePair.getSignatureCase());
        }
        // Handle potential public key prefix collisions by taking first occurrence only ignoring duplicates
        if (publicKeyPrefixes.add(prefix)) {
            TransactionSignature transactionSignature = new TransactionSignature();
            transactionSignature.setConsensusTimestamp(consensusTimestamp);
            transactionSignature.setEntityId(entityId);
            transactionSignature.setPublicKeyPrefix(DomainUtils.toBytes(prefix));
            transactionSignature.setSignature(DomainUtils.toBytes(signature));
            transactionSignature.setType(type);
            entityListener.onTransactionSignature(transactionSignature);
        }
    });
}
Also used : ByteString(com.google.protobuf.ByteString) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) Map(java.util.Map) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) HashSet(java.util.HashSet)

Example 7 with TransactionSignature

use of com.hedera.mirror.common.domain.transaction.TransactionSignature in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerScheduleTest method scheduleSign.

@Test
void scheduleSign() {
    insertScheduleCreateTransaction(CREATE_TIMESTAMP, null, SCHEDULE_ID);
    // sign
    SignatureMap signatureMap = getSigMap(3, true);
    insertScheduleSign(SIGN_TIMESTAMP, signatureMap, SCHEDULE_ID);
    // verify entity count
    assertEquals(1, entityRepository.count());
    // verify schedule
    assertThat(scheduleRepository.count()).isOne();
    assertScheduleInRepository(SCHEDULE_ID, CREATE_TIMESTAMP, PAYER, null);
    // verify schedule signatures
    List<TransactionSignature> expectedTransactionSignatureList = new ArrayList<>(defaultSignatureList);
    expectedTransactionSignatureList.addAll(toTransactionSignatureList(SIGN_TIMESTAMP, SCHEDULE_ID, signatureMap));
    assertTransactionSignatureInRepository(expectedTransactionSignatureList);
    // verify transaction
    assertTransactionInRepository(SIGN_TIMESTAMP, false, SUCCESS);
}
Also used : ArrayList(java.util.ArrayList) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with TransactionSignature

use of com.hedera.mirror.common.domain.transaction.TransactionSignature in project hedera-mirror-node by hashgraph.

the class TransactionSignatureTest method setup.

@BeforeEach
void setup() {
    CommonParserProperties commonParserProperties = new CommonParserProperties();
    EntityProperties entityProperties = new EntityProperties();
    RecordParserProperties parserProperties = new RecordParserProperties();
    entityRecordItemListener = new EntityRecordItemListener(commonParserProperties, entityProperties, addressBookService, nonFeeTransferExtractionStrategy, entityIdService, entityListener, transactionHandlerFactory, fileDataRepository, parserProperties, contractResultService);
    defaultSignatureMap = getDefaultSignatureMap();
    defaultTransactionSignatures = defaultSignatureMap.getSigPairList().stream().map(pair -> {
        TransactionSignature transactionSignature = new TransactionSignature();
        transactionSignature.setConsensusTimestamp(CONSENSUS_TIMESTAMP);
        transactionSignature.setEntityId(ENTITY_ID);
        transactionSignature.setPublicKeyPrefix(pair.getPubKeyPrefix().toByteArray());
        transactionSignature.setSignature(pair.getEd25519().toByteArray());
        transactionSignature.setType(SignaturePair.SignatureCase.ED25519.getNumber());
        return transactionSignature;
    }).collect(Collectors.toList());
    transactionSignatures = entityProperties.getPersist().getTransactionSignatures();
    doReturn(ENTITY_ID).when(transactionHandler).getEntity(any(RecordItem.class));
    doReturn(transactionHandler).when(transactionHandlerFactory).get(any(TransactionType.class));
}
Also used : TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) CommonParserProperties(com.hedera.mirror.importer.parser.CommonParserProperties) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TransactionSignature (com.hedera.mirror.common.domain.transaction.TransactionSignature)8 Test (org.junit.jupiter.api.Test)5 SignatureMap (com.hederahashgraph.api.proto.java.SignatureMap)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ArrayList (java.util.ArrayList)3 ByteString (com.google.protobuf.ByteString)2 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)2 Entity (com.hedera.mirror.common.domain.entity.Entity)2 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)1 TransactionType (com.hedera.mirror.common.domain.transaction.TransactionType)1 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)1 InvalidDatasetException (com.hedera.mirror.importer.exception.InvalidDatasetException)1 CommonParserProperties (com.hedera.mirror.importer.parser.CommonParserProperties)1 RecordParserProperties (com.hedera.mirror.importer.parser.record.RecordParserProperties)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1