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();
}
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);
}
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);
}
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());
}
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();
}
Aggregations