Search in sources :

Example 1 with JKey

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;
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) JKey(com.hedera.services.legacy.core.jproto.JKey) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)

Example 2 with JKey

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());
}
Also used : JKey(com.hedera.services.legacy.core.jproto.JKey) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Test(org.junit.jupiter.api.Test)

Example 3 with JKey

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();
}
Also used : JKey(com.hedera.services.legacy.core.jproto.JKey) ArrayList(java.util.ArrayList) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Test(org.junit.jupiter.api.Test)

Example 4 with JKey

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));
}
Also used : JKey(com.hedera.services.legacy.core.jproto.JKey) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Test(org.junit.jupiter.api.Test)

Example 5 with JKey

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();
}
Also used : UnknownHederaFunctionality(com.hedera.services.exceptions.UnknownHederaFunctionality) JKey(com.hedera.services.legacy.core.jproto.JKey)

Aggregations

JKey (com.hedera.services.legacy.core.jproto.JKey)13 Test (org.junit.jupiter.api.Test)7 JEd25519Key (com.hedera.services.legacy.core.jproto.JEd25519Key)5 ArrayList (java.util.ArrayList)3 HederaAccountCustomizer (com.hedera.services.ledger.accounts.HederaAccountCustomizer)2 TransactionSignature (com.swirlds.common.crypto.TransactionSignature)2 ByteString (com.google.protobuf.ByteString)1 UnknownHederaFunctionality (com.hedera.services.exceptions.UnknownHederaFunctionality)1 JKeyList (com.hedera.services.legacy.core.jproto.JKeyList)1 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)1 MerkleToken (com.hedera.services.state.merkle.MerkleToken)1 EntityId (com.hedera.services.state.submerkle.EntityId)1 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)1 FcTokenAllowance (com.hedera.services.state.submerkle.FcTokenAllowance)1 FcTokenAllowanceId (com.hedera.services.state.submerkle.FcTokenAllowanceId)1 EntityNum (com.hedera.services.utils.EntityNum)1 AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)1 AccountID (com.hederahashgraph.api.proto.java.AccountID)1 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)1 NftTransfer (com.hederahashgraph.api.proto.java.NftTransfer)1