use of com.swirlds.common.crypto.engine.CryptoEngine 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.swirlds.common.crypto.engine.CryptoEngine in project hedera-services by hashgraph.
the class SigOpsRegressionTest method invokeRationalizationScenario.
private Rationalization invokeRationalizationScenario() {
// setup:
SyncVerifier syncVerifier = new CryptoEngine()::verifySync;
final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
SigMetadataLookup sigMetaLookups = defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, () -> null, ref -> null, ref -> null);
SigRequirements keyOrder = new SigRequirements(sigMetaLookups, mockSignatureWaivers);
// given:
final var rationalization = new Rationalization(syncVerifier, keyOrder, new ReusableBodySigningFactory());
rationalization.performFor(platformTxn);
return rationalization;
}
use of com.swirlds.common.crypto.engine.CryptoEngine in project hedera-services by hashgraph.
the class SigVerifierRegressionTest method setupFor.
private void setupFor(TxnHandlingScenario scenario) throws Throwable {
accounts = scenario.accounts();
platformTxn = scenario.platformTxn();
aliasManager = mock(AliasManager.class);
keyOrder = new SigRequirements(defaultLookupsFor(aliasManager, null, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
final var nodeInfo = mock(NodeInfo.class);
given(nodeInfo.selfAccount()).willReturn(DEFAULT_NODE);
isQueryPayment = PrecheckUtils.queryPaymentTestFor(nodeInfo);
SyncVerifier syncVerifier = new CryptoEngine()::verifySync;
precheckKeyReqs = new PrecheckKeyReqs(keyOrder, isQueryPayment);
precheckVerifier = new PrecheckVerifier(syncVerifier, precheckKeyReqs);
}
Aggregations