use of com.hedera.services.legacy.core.jproto.JKey in project hedera-services by hashgraph.
the class CryptoUpdateTransitionLogic method validate.
private ResponseCodeEnum validate(TransactionBody cryptoUpdateTxn) {
CryptoUpdateTransactionBody op = cryptoUpdateTxn.getCryptoUpdateAccount();
var memoValidity = !op.hasMemo() ? OK : validator.memoCheck(op.getMemo().getValue());
if (memoValidity != OK) {
return memoValidity;
}
if (op.hasKey()) {
try {
JKey fcKey = JKey.mapKey(op.getKey());
/* Note that an empty key is never valid. */
if (!fcKey.isValid()) {
return BAD_ENCODING;
}
} catch (DecoderException e) {
return BAD_ENCODING;
}
}
if (op.hasAutoRenewPeriod() && !validator.isValidAutoRenewPeriod(op.getAutoRenewPeriod())) {
return AUTORENEW_DURATION_NOT_IN_RANGE;
}
return OK;
}
use of com.hedera.services.legacy.core.jproto.JKey in project hedera-services by hashgraph.
the class PlatformSigOpsTest method ignoresAmbiguousScheduledSig.
@Test
void ignoresAmbiguousScheduledSig() throws Throwable {
final JKey scheduledKey = new JEd25519Key("01234578901234578901234578901".getBytes());
scheduledKey.setForScheduledTxn(true);
given(sigBytes.sigBytesFor(any())).willThrow(KeyPrefixMismatchException.class);
final var result = createCryptoSigsFrom(List.of(scheduledKey), sigBytes, sigFactory);
assertFalse(result.hasFailed());
assertTrue(result.getPlatformSigs().isEmpty());
}
use of com.hedera.services.legacy.core.jproto.JKey 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.hedera.services.legacy.core.jproto.JKey in project hedera-services by hashgraph.
the class PrecheckKeyReqsTest method usesBothOrderForQueryPayments.
@Test
void usesBothOrderForQueryPayments() throws Exception {
final JKey key1 = new JEd25519Key("firstKey".getBytes());
final JKey key2 = new JEd25519Key("secondKey".getBytes());
final JKey key3 = new JEd25519Key("thirdKey".getBytes());
final JKey key4 = new JEd25519Key("firstKey".getBytes());
given(keyOrder.keysForPayer(txn, CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(List.of(key1)));
given(keyOrder.keysForOtherParties(txn, CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(List.of(key2, key3, key4)));
givenImpliedSubject(FOR_QUERY_PAYMENT);
// when:
keys = subject.getRequiredKeys(txn);
// then:
verify(keyOrder).keysForPayer(txn, CODE_ORDER_RESULT_FACTORY);
verify(keyOrder).keysForOtherParties(txn, CODE_ORDER_RESULT_FACTORY);
verifyNoMoreInteractions(keyOrder);
assertEquals(3, keys.size());
assertTrue(keys.contains(key1));
assertTrue(keys.contains(key2));
assertTrue(keys.contains(key3));
}
use of com.hedera.services.legacy.core.jproto.JKey in project hedera-services by hashgraph.
the class SigRequirements method mergeScheduledKeys.
private <T> Optional<SigningOrderResult<T>> mergeScheduledKeys(final List<JKey> required, final TransactionBody scheduledTxn, final SigningOrderResultFactory<T> factory, @Nullable final LinkedRefs linkedRefs) {
try {
final var scheduledFunction = MiscUtils.functionOf(scheduledTxn);
if (IMPOSSIBLE_TO_SCHEDULE.contains(scheduledFunction)) {
return Optional.of(factory.forUnschedulableTxn());
}
var scheduledOrderResult = keysForOtherParties(scheduledTxn, factory, linkedRefs);
if (scheduledOrderResult.hasErrorReport()) {
return Optional.of(factory.forUnresolvableRequiredSigners());
} else {
var scheduledKeys = scheduledOrderResult.getOrderedKeys();
for (JKey key : scheduledKeys) {
var dup = key.duplicate();
dup.setForScheduledTxn(true);
required.add(dup);
}
}
} catch (UnknownHederaFunctionality e) {
return Optional.of(factory.forUnschedulableTxn());
}
return Optional.empty();
}
Aggregations