Search in sources :

Example 6 with SignatureMap

use of com.hederahashgraph.api.proto.java.SignatureMap in project hedera-mirror-node by hashgraph.

the class AbstractEntityRecordItemListenerTest method getDefaultSigMap.

private static SignatureMap getDefaultSigMap() {
    String key1 = "11111111111111111111c61eab86e2a9c164565b4e7a9a4146106e0a6cd03a8c395a110e91";
    String signature1 = "Signature 1 here";
    String key2 = "22222222222222222222c61eab86e2a9c164565b4e7a9a4146106e0a6cd03a8c395a110e91";
    String signature2 = "Signature 2 here";
    SignatureMap.Builder sigMap = SignatureMap.newBuilder();
    SignaturePair.Builder sigPair = SignaturePair.newBuilder();
    sigPair.setEd25519(ByteString.copyFromUtf8(signature1));
    sigPair.setPubKeyPrefix(ByteString.copyFromUtf8(key1));
    sigMap.addSigPair(sigPair);
    sigPair = SignaturePair.newBuilder();
    sigPair.setEd25519(ByteString.copyFromUtf8(signature2));
    sigPair.setPubKeyPrefix(ByteString.copyFromUtf8(key2));
    sigMap.addSigPair(sigPair);
    return sigMap.build();
}
Also used : SignaturePair(com.hederahashgraph.api.proto.java.SignaturePair) ByteString(com.google.protobuf.ByteString) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap)

Example 7 with SignatureMap

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

the class CryptoOpsUsageTest method accumulatesBptAndRbhAsExpectedForCryptoCreateWithoutMaxAutoAssociations.

@Test
void accumulatesBptAndRbhAsExpectedForCryptoCreateWithoutMaxAutoAssociations() {
    givenCreationOpWithOutMaxAutoAssociaitons();
    final ByteString canonicalSig = ByteString.copyFromUtf8("0123456789012345678901234567890123456789012345678901234567890123");
    final SignatureMap onePairSigMap = SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFromUtf8("a")).setEd25519(canonicalSig)).build();
    final SigUsage singleSigUsage = new SigUsage(1, onePairSigMap.getSerializedSize(), 1);
    final var opMeta = new CryptoCreateMeta(txn.getCryptoCreateAccount());
    final var baseMeta = new BaseTransactionMeta(memo.length(), 0);
    var actual = new UsageAccumulator();
    var expected = new UsageAccumulator();
    var baseSize = memo.length() + getAccountKeyStorageSize(key) + BASIC_ENTITY_ID_SIZE;
    expected.resetForTransaction(baseMeta, singleSigUsage);
    expected.addBpt(baseSize + 2 * LONG_SIZE + BOOL_SIZE);
    expected.addRbs((CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + baseSize) * secs);
    expected.addNetworkRbs(BASIC_ENTITY_ID_SIZE * USAGE_PROPERTIES.legacyReceiptStorageSecs());
    subject.cryptoCreateUsage(singleSigUsage, baseMeta, opMeta, actual);
    assertEquals(expected, actual);
}
Also used : BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) ByteString(com.google.protobuf.ByteString) SigUsage(com.hedera.services.usage.SigUsage) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test)

Example 8 with SignatureMap

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

the class CryptoOpsUsageTest method accumulatesBptAndRbhAsExpectedForCryptoCreateWithMaxAutoAssociations.

@Test
void accumulatesBptAndRbhAsExpectedForCryptoCreateWithMaxAutoAssociations() {
    givenCreationOpWithMaxAutoAssociaitons();
    final ByteString canonicalSig = ByteString.copyFromUtf8("0123456789012345678901234567890123456789012345678901234567890123");
    final SignatureMap onePairSigMap = SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFromUtf8("a")).setEd25519(canonicalSig)).build();
    final SigUsage singleSigUsage = new SigUsage(1, onePairSigMap.getSerializedSize(), 1);
    final var opMeta = new CryptoCreateMeta(txn.getCryptoCreateAccount());
    final var baseMeta = new BaseTransactionMeta(memo.length(), 0);
    var actual = new UsageAccumulator();
    var expected = new UsageAccumulator();
    var baseSize = memo.length() + getAccountKeyStorageSize(key) + BASIC_ENTITY_ID_SIZE + INT_SIZE;
    expected.resetForTransaction(baseMeta, singleSigUsage);
    expected.addBpt(baseSize + 2 * LONG_SIZE + BOOL_SIZE);
    expected.addRbs((CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + baseSize) * secs);
    expected.addRbs(maxAutoAssociations * secs * CryptoOpsUsage.CREATE_SLOT_MULTIPLIER);
    expected.addNetworkRbs(BASIC_ENTITY_ID_SIZE * USAGE_PROPERTIES.legacyReceiptStorageSecs());
    subject.cryptoCreateUsage(singleSigUsage, baseMeta, opMeta, actual);
    assertEquals(expected, actual);
}
Also used : BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) ByteString(com.google.protobuf.ByteString) SigUsage(com.hedera.services.usage.SigUsage) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test)

Example 9 with SignatureMap

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

the class PojoSigMapPubKeyToSigBytesTest method rejectsNonUniqueSigBytes.

@Test
void rejectsNonUniqueSigBytes() {
    // given:
    String str = "TEST_STRING";
    byte[] pubKey = str.getBytes(StandardCharsets.UTF_8);
    SignaturePair sigPair = SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFromUtf8(str)).build();
    SignatureMap sigMap = SignatureMap.newBuilder().addSigPair(sigPair).addSigPair(sigPair).build();
    PojoSigMapPubKeyToSigBytes sigMapPubKeyToSigBytes = new PojoSigMapPubKeyToSigBytes(sigMap);
    // expect:
    KeyPrefixMismatchException exception = assertThrows(KeyPrefixMismatchException.class, () -> {
        sigMapPubKeyToSigBytes.sigBytesFor(pubKey);
    });
    assertEquals("Source signature map with prefix 544553545f535452494e47 is ambiguous for given public key! " + "(544553545f535452494e47)", exception.getMessage());
}
Also used : KeyPrefixMismatchException(com.hedera.services.legacy.exception.KeyPrefixMismatchException) SignaturePair(com.hederahashgraph.api.proto.java.SignaturePair) ByteString(com.google.protobuf.ByteString) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test)

Example 10 with SignatureMap

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

the class HapiSpecOperation method finalizedTxnFromTxnWithBodyBytesAndSigMap.

private Transaction finalizedTxnFromTxnWithBodyBytesAndSigMap(Transaction txnWithBodyBytesAndSigMap) throws Throwable {
    if (asTxnWithOnlySigMap) {
        return txnWithBodyBytesAndSigMap.toBuilder().clearBodyBytes().build();
    }
    if (alwaysWithLegacyProtoStructure) {
        return txnWithBodyBytesAndSigMap;
    }
    ByteString bodyByteString = CommonUtils.extractTransactionBodyByteString(txnWithBodyBytesAndSigMap);
    SignatureMap sigMap = CommonUtils.extractSignatureMap(txnWithBodyBytesAndSigMap);
    SignedTransaction signedTransaction = SignedTransaction.newBuilder().setBodyBytes(bodyByteString).setSigMap(sigMap).build();
    Transaction.Builder txnWithSignedTxnBytesBuilder = Transaction.newBuilder().setSignedTransactionBytes(signedTransaction.toByteString());
    if (asTxnWithSignedTxnBytesAndSigMap) {
        return txnWithSignedTxnBytesBuilder.setSigMap(sigMap).build();
    }
    if (asTxnWithSignedTxnBytesAndBodyBytes) {
        return txnWithSignedTxnBytesBuilder.setBodyBytes(bodyByteString).build();
    }
    if (txnProtoStructure == HapiSpecSetup.TxnProtoStructure.OLD) {
        return txnWithBodyBytesAndSigMap;
    }
    return txnWithSignedTxnBytesBuilder.build();
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) ByteString(com.google.protobuf.ByteString) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap)

Aggregations

SignatureMap (com.hederahashgraph.api.proto.java.SignatureMap)12 Test (org.junit.jupiter.api.Test)8 ByteString (com.google.protobuf.ByteString)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 TransactionSignature (com.hedera.mirror.common.domain.transaction.TransactionSignature)4 SignaturePair (com.hederahashgraph.api.proto.java.SignaturePair)4 ArrayList (java.util.ArrayList)3 Entity (com.hedera.mirror.common.domain.entity.Entity)2 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)2 SigUsage (com.hedera.services.usage.SigUsage)2 UsageAccumulator (com.hedera.services.usage.state.UsageAccumulator)2 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)1 InvalidDatasetException (com.hedera.mirror.importer.exception.InvalidDatasetException)1 KeyPrefixMismatchException (com.hedera.services.legacy.exception.KeyPrefixMismatchException)1 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1