use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.
the class HederaKeyActivationTest method canMatchCompressedEcdsaSecp256k1Key.
@Test
void canMatchCompressedEcdsaSecp256k1Key() throws Exception {
final var mockTxnBytes = "012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789".getBytes();
final var explicitList = keyList.getKeyList().getKeysList();
final var secp256k1Key = explicitList.get(0);
final var ed25519Key = explicitList.get(1);
final var keyFactory = KeyFactory.getDefaultInstance();
final var mockSigs = mock(PubKeyToSigBytes.class);
given(mockSigs.sigBytesFor(explicitList.get(0).getECDSASecp256k1Key())).willReturn(signBytes(keccak256DigestOf(mockTxnBytes), keyFactory.lookupPrivateKey(hex(secp256k1Key.getECDSASecp256k1Key()))));
given(mockSigs.sigBytesFor(explicitList.get(1).getEd25519())).willReturn(signBytes(mockTxnBytes, keyFactory.lookupPrivateKey(hex(ed25519Key.getEd25519()))));
final var accessor = mock(TxnAccessor.class);
given(accessor.getTxnBytes()).willReturn(mockTxnBytes);
final var cryptoSigs = createCryptoSigsFrom(explicitList, mockSigs, new ReusableBodySigningFactory(accessor)).getPlatformSigs();
new CryptoEngine().verifySync(cryptoSigs);
final var subject = pkToSigMapFrom(cryptoSigs);
final var ed25519Sig = subject.apply(ed25519Key.getEd25519());
assertEquals(SignatureType.ED25519, ed25519Sig.getSignatureType());
assertEquals(VerificationStatus.VALID, ed25519Sig.getSignatureStatus());
final var secp256k1Sig = subject.apply(secp256k1Key.getECDSASecp256k1Key());
assertEquals(SignatureType.ECDSA_SECP256K1, secp256k1Sig.getSignatureType());
}
use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.
the class HederaToPlatformSigOpsTest method stopImmediatelyOnOtherPartiesSigCreationFailure.
@Test
void stopImmediatelyOnOtherPartiesSigCreationFailure() throws Exception {
final var mockAccessor = mock(PlatformTxnAccessor.class);
given(keyOrdering.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(payerKey));
given(keyOrdering.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(otherKeys));
given(allSigBytes.sigBytesFor(any())).willReturn("1".getBytes()).willReturn("2".getBytes()).willThrow(KeyPrefixMismatchException.class);
givenMirrorMock(mockAccessor, platformTxn);
final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
rationalization.performFor(mockAccessor);
assertEquals(KEY_PREFIX_MISMATCH, rationalization.finalStatus());
}
use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.
the class HederaToPlatformSigOpsTest method stopImmediatelyOnPayerKeyOrderFailure.
@Test
void stopImmediatelyOnPayerKeyOrderFailure() {
given(keyOrdering.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(INVALID_ACCOUNT_ID));
final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
rationalization.performFor(platformTxn);
assertEquals(INVALID_ACCOUNT_ID, rationalization.finalStatus());
}
use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.
the class HederaToPlatformSigOpsTest method stopImmediatelyOnOtherPartiesKeyOrderFailure.
@Test
void stopImmediatelyOnOtherPartiesKeyOrderFailure() throws Exception {
wellBehavedOrdersAndSigSources();
given(keyOrdering.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(INVALID_ACCOUNT_ID));
final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
rationalization.performFor(platformTxn);
assertEquals(INVALID_ACCOUNT_ID, rationalization.finalStatus());
}
use of com.hedera.services.sigs.factories.ReusableBodySigningFactory in project hedera-services by hashgraph.
the class HederaToPlatformSigOpsTest method rationalizesMissingSigs.
@Test
void rationalizesMissingSigs() throws Exception {
final var rationalization = new Rationalization(ALWAYS_VALID, keyOrdering, new ReusableBodySigningFactory());
final var captor = ArgumentCaptor.forClass(RationalizedSigMeta.class);
final var mockAccessor = mock(PlatformTxnAccessor.class);
wellBehavedOrdersAndSigSources();
givenMirrorMock(mockAccessor, platformTxn);
rationalization.performFor(mockAccessor);
assertEquals(OK, rationalization.finalStatus());
assertTrue(rationalization.usedSyncVerification());
verify(mockAccessor).setSigMeta(captor.capture());
final var sigMeta = captor.getValue();
assertEquals(expectedSigsWithNoErrors(), sigMeta.verifiedSigs());
platformTxn.setSigMeta(sigMeta);
assertTrue(allVerificationStatusesAre(VerificationStatus.VALID::equals));
}
Aggregations