use of com.swirlds.common.crypto.TransactionSignature in project hedera-services by hashgraph.
the class RationalizationTest method resetWorks.
@Test
void resetWorks() {
given(txnAccessor.getPlatformTxn()).willReturn(swirldsTxn);
final List<TransactionSignature> mockSigs = new ArrayList<>();
final JKey fake = new JEd25519Key("FAKE".getBytes(StandardCharsets.UTF_8));
subject = new Rationalization(syncVerifier, keyOrderer, sigFactory);
given(txnAccessor.getPkToSigsFn()).willReturn(pkToSigFn);
given(swirldsTxn.getSignatures()).willReturn(mockSigs);
// and:
subject.getRealPayerSigs().add(null);
subject.getRealOtherPartySigs().add(null);
subject.setReqPayerSig(fake);
subject.setReqOthersSigs(List.of(fake));
subject.setLastOrderResult(CODE_ORDER_RESULT_FACTORY.forGeneralError());
subject.setFinalStatus(INVALID_ACCOUNT_ID);
subject.setVerifiedSync(true);
// when:
subject.resetFor(txnAccessor);
// then:
assertSame(txnAccessor, subject.getTxnAccessor());
assertSame(syncVerifier, subject.getSyncVerifier());
assertSame(keyOrderer, subject.getSigReqs());
assertSame(pkToSigFn, subject.getPkToSigFn());
assertSame(mockSigs, subject.getTxnSigs());
// and:
assertTrue(subject.getRealPayerSigs().isEmpty());
assertTrue(subject.getRealOtherPartySigs().isEmpty());
// and:
assertFalse(subject.usedSyncVerification());
assertNull(subject.finalStatus());
assertNull(subject.getReqPayerSig());
assertNull(subject.getReqOthersSigs());
assertNull(subject.getLastOrderResult());
// and:
verify(sigFactory).resetFor(txnAccessor);
verify(pkToSigFn).resetAllSigsToUnused();
}
use of com.swirlds.common.crypto.TransactionSignature in project hedera-services by hashgraph.
the class SigOpsRegressionTest method otherPartySigsAreActive.
static boolean otherPartySigsAreActive(PlatformTxnAccessor accessor, SigRequirements keyOrder, SigningOrderResultFactory<ResponseCodeEnum> summaryFactory, KeyActivationCharacteristics characteristics) {
TransactionBody txn = accessor.getTxn();
Function<byte[], TransactionSignature> sigsFn = HederaKeyActivation.pkToSigMapFrom(accessor.getPlatformTxn().getSignatures());
final var othersResult = keyOrder.keysForOtherParties(txn, summaryFactory);
for (JKey otherKey : othersResult.getOrderedKeys()) {
if (!HederaKeyActivation.isActive(otherKey, sigsFn, HederaKeyActivation.ONLY_IF_SIG_IS_VALID, characteristics)) {
return false;
}
}
return true;
}
use of com.swirlds.common.crypto.TransactionSignature in project hedera-services by hashgraph.
the class SigOpsRegressionTest method invokePayerSigActivationScenario.
private boolean invokePayerSigActivationScenario(List<TransactionSignature> knownSigs) {
SigRequirements keysOrder = new SigRequirements(defaultLookupsFor(aliasManager, null, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
final var impliedOrdering = keysOrder.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
final var impliedKey = impliedOrdering.getPayerKey();
platformTxn.setSigMeta(RationalizedSigMeta.forPayerOnly(impliedKey, new ArrayList<>(knownSigs)));
return payerSigIsActive(platformTxn, ONLY_IF_SIG_IS_VALID);
}
use of com.swirlds.common.crypto.TransactionSignature in project hedera-services by hashgraph.
the class SigOpsRegressionTest method invokeOtherPartySigActivationScenario.
private boolean invokeOtherPartySigActivationScenario(List<TransactionSignature> knownSigs) {
platformTxn.getPlatformTxn().clear();
platformTxn.getPlatformTxn().addAll(knownSigs.toArray(new TransactionSignature[0]));
final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
SigRequirements keysOrder = new SigRequirements(defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, null, ref -> null, ref -> null), mockSignatureWaivers);
return otherPartySigsAreActive(platformTxn, keysOrder, CODE_ORDER_RESULT_FACTORY);
}
use of com.swirlds.common.crypto.TransactionSignature in project hedera-services by hashgraph.
the class HederaToPlatformSigOpsTest method rationalizesOnlyMissingSigs.
@Test
void rationalizesOnlyMissingSigs() throws Exception {
wellBehavedOrdersAndSigSources();
platformTxn.getPlatformTxn().addAll(asValid(expectedSigsWithOtherPartiesCreationError()).toArray(new TransactionSignature[0]));
final SyncVerifier syncVerifier = l -> {
if (l.equals(expectedSigsWithOtherPartiesCreationError())) {
throw new AssertionError("Payer sigs were verified async!");
} else {
ALWAYS_VALID.verifySync(l);
}
};
final var mockAccessor = mock(PlatformTxnAccessor.class);
final var captor = ArgumentCaptor.forClass(RationalizedSigMeta.class);
givenMirrorMock(mockAccessor, platformTxn);
final var rationalization = new Rationalization(syncVerifier, keyOrdering, new ReusableBodySigningFactory());
rationalization.performFor(mockAccessor);
assertTrue(rationalization.usedSyncVerification());
assertEquals(OK, rationalization.finalStatus());
verify(mockAccessor).setSigMeta(captor.capture());
final var sigMeta = captor.getValue();
platformTxn.setSigMeta(sigMeta);
assertEquals(expectedSigsWithNoErrors(), platformTxn.getSigMeta().verifiedSigs());
assertTrue(allVerificationStatusesAre(VerificationStatus.VALID::equals));
}
Aggregations