Search in sources :

Example 1 with Key

use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.

the class FeeBuilderTest method assertCalculateKeysMetadata.

@Test
void assertCalculateKeysMetadata() {
    int[] countKeyMetatData = { 0, 0 };
    Key validKey = Key.newBuilder().setEd25519(ByteString.copyFromUtf8("a479462fba67674b5a41acfb16cb6828626b61d3f389fa611005a45754130e5c749073c0b1b791596430f4a54649cc8a3f6d28147dd4099070a5c3c4811d1771")).build();
    Key validKey1 = Key.newBuilder().setEd25519(ByteString.copyFromUtf8("a479462fba67674b5a41acfb16cb6828626b61d3f389fa611005a45754130e5c749073c0b1b791596430f4a54649cc8a3f6d28147dd4099070a5c3c4811d1771")).build();
    Key validED25519Keys = Key.newBuilder().setKeyList(KeyList.newBuilder().addKeys(validKey).addKeys(validKey1).build()).build();
    assertEquals(countKeyMetatData.length, FeeBuilder.calculateKeysMetadata(validED25519Keys, countKeyMetatData).length);
    assertEquals(4, FeeBuilder.calculateKeysMetadata(validED25519Keys, countKeyMetatData)[0]);
}
Also used : Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) Test(org.junit.jupiter.api.Test)

Example 2 with Key

use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.

the class ImpliedTransfersMarshalTest method hasAliasInChanges.

@Test
void hasAliasInChanges() {
    Key aliasA = KeyFactory.getDefaultInstance().newEd25519();
    Key aliasB = KeyFactory.getDefaultInstance().newEd25519();
    AccountID a = AccountID.newBuilder().setShardNum(0).setRealmNum(0).setAccountNum(9_999L).setAlias(aliasA.toByteString()).build();
    AccountID validAliasAccount = AccountID.newBuilder().setAlias(aliasB.toByteString()).build();
    setupProps();
    final var builder = CryptoTransferTransactionBody.newBuilder().setTransfers(TransferList.newBuilder().addAccountAmounts(adjustFrom(a, -100)).addAccountAmounts(adjustFrom(validAliasAccount, 100)).build());
    op = builder.build();
    final List<BalanceChange> expectedChanges = new ArrayList<>();
    expectedChanges.add(changingHbar(adjustFrom(a, -100), payer));
    expectedChanges.add(changingHbar(adjustFrom(validAliasAccount, +100), payer));
    final var expectedMeta = new ImpliedTransfersMeta(propsWithAutoCreation, OK, Collections.emptyList(), NO_ALIASES);
    givenValidity(OK);
    final var result = subject.unmarshalFromGrpc(op, payer);
    assertEquals(expectedChanges, result.getAllBalanceChanges());
    assertEquals(aliasA.toByteString(), result.getAllBalanceChanges().get(0).alias());
    assertEquals(aliasB.toByteString(), result.getAllBalanceChanges().get(1).alias());
    assertEquals(result.getMeta(), expectedMeta);
    assertTrue(result.getAssessedCustomFees().isEmpty());
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) BalanceChange(com.hedera.services.ledger.BalanceChange) ArrayList(java.util.ArrayList) Key(com.hederahashgraph.api.proto.java.Key) Test(org.junit.jupiter.api.Test)

Example 3 with Key

use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.

the class CryptoCreateSuite method createAnAccountInvalidThresholdKey.

// One of element in threshold key is not valid
private HapiApiSpec createAnAccountInvalidThresholdKey() {
    KeyShape emptyListShape = listOf(0);
    KeyShape thresholdShape = threshOf(1, SIMPLE, SIMPLE, emptyListShape);
    long initialBalance = 10_000L;
    // build a threshold key with one of key is invalid
    Key randomKey1 = Key.newBuilder().setEd25519(ByteString.copyFrom(randomUtf8Bytes(32))).build();
    Key randomKey2 = Key.newBuilder().setEd25519(ByteString.copyFrom(randomUtf8Bytes(32))).build();
    Key shortKey = Key.newBuilder().setEd25519(ByteString.copyFrom(new byte[10])).build();
    KeyList invalidKeyList = KeyList.newBuilder().addKeys(randomKey1).addKeys(randomKey2).addKeys(shortKey).build();
    ThresholdKey invalidThresholdKey = ThresholdKey.newBuilder().setThreshold(2).setKeys(invalidKeyList).build();
    Key regKey1 = Key.newBuilder().setThresholdKey(invalidThresholdKey).build();
    Key regKey2 = Key.newBuilder().setKeyList(invalidKeyList).build();
    return defaultHapiSpec("createAnAccountInvalidThresholdKey").given().when().then(withOpContext((spec, opLog) -> {
        spec.registry().saveKey("regKey1", regKey1);
        spec.registry().saveKey("regKey2", regKey2);
    }), cryptoCreate("badThresholdKeyAccount").keyShape(thresholdShape).balance(initialBalance).logged().hasPrecheck(BAD_ENCODING), cryptoCreate("badThresholdKeyAccount2").key("regKey1").balance(initialBalance).logged().signedBy(GENESIS).hasPrecheck(BAD_ENCODING), cryptoCreate("badThresholdKeyAccount3").key("regKey2").balance(initialBalance).logged().signedBy(GENESIS).hasPrecheck(BAD_ENCODING));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) KEY_REQUIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.KEY_REQUIRED) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) KeyList(com.hederahashgraph.api.proto.java.KeyList) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) UtilVerbs.validateChargedUsd(com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsd) REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) TxnUtils.randomUtf8Bytes(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) KeyList(com.hederahashgraph.api.proto.java.KeyList) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey)

Example 4 with Key

use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.

the class CryptoCreateSuite method createAnAccountInvalidED25519.

private HapiApiSpec createAnAccountInvalidED25519() {
    long initialBalance = 10_000L;
    Key emptyKey = Key.newBuilder().setEd25519(ByteString.EMPTY).build();
    Key shortKey = Key.newBuilder().setEd25519(ByteString.copyFrom(new byte[10])).build();
    return defaultHapiSpec("createAnAccountInvalidED25519").given().when().then(withOpContext((spec, opLog) -> {
        spec.registry().saveKey("shortKey", shortKey);
        spec.registry().saveKey("emptyKey", emptyKey);
    }), cryptoCreate("shortKey").key("shortKey").balance(initialBalance).signedBy(GENESIS).logged().hasPrecheck(BAD_ENCODING), cryptoCreate("emptyKey").key("emptyKey").balance(initialBalance).signedBy(GENESIS).logged().hasPrecheck(BAD_ENCODING));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) KEY_REQUIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.KEY_REQUIRED) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) KeyList(com.hederahashgraph.api.proto.java.KeyList) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) UtilVerbs.validateChargedUsd(com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsd) REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) TxnUtils.randomUtf8Bytes(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey)

Example 5 with Key

use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.

the class JKey method equalUpToDecodability.

public static boolean equalUpToDecodability(JKey a, JKey b) {
    Key aKey = null;
    Key bKey = null;
    try {
        aKey = mapJKey(a);
    } catch (Exception ignore) {
    }
    try {
        bKey = mapJKey(b);
    } catch (Exception ignore) {
    }
    return Objects.equals(aKey, bKey);
}
Also used : Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) DecoderException(org.apache.commons.codec.DecoderException) IOException(java.io.IOException)

Aggregations

Key (com.hederahashgraph.api.proto.java.Key)43 ByteString (com.google.protobuf.ByteString)20 Test (org.junit.jupiter.api.Test)20 ThresholdKey (com.hederahashgraph.api.proto.java.ThresholdKey)14 KeyList (com.hederahashgraph.api.proto.java.KeyList)12 List (java.util.List)12 ArrayList (java.util.ArrayList)10 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)8 PrivateKey (java.security.PrivateKey)8 Optional (java.util.Optional)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)6 IOException (java.io.IOException)6 Map (java.util.Map)6 MoreObjects (com.google.common.base.MoreObjects)5 AccountID (com.hederahashgraph.api.proto.java.AccountID)5 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)5 Transaction (com.hederahashgraph.api.proto.java.Transaction)5 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)5