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);
}
});
}
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);
}
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));
}
Aggregations