Search in sources :

Example 1 with PublicKey

use of io.nem.symbol.core.crypto.PublicKey in project nem2-sdk-java by nemtech.

the class AbstractTransactionMapper method mapTransaction.

private D mapTransaction(Transaction transaction, boolean embedded) {
    TransactionDTO dto = new TransactionDTO();
    dto.setSignerPublicKey(transaction.getSigner().map(PublicAccount::getPublicKey).map(PublicKey::toHex).orElse(null));
    dto.setVersion(transaction.getVersion());
    dto.setNetwork(NetworkTypeEnum.fromValue(transaction.getNetworkType().getValue()));
    dto.setType(transaction.getType().getValue());
    if (!embedded) {
        dto.setSize(transaction.getSize());
        dto.setMaxFee(transaction.getMaxFee());
        dto.setDeadline(transaction.getDeadline().toBigInteger());
        dto.setSignature(transaction.getSignature().orElse(null));
    }
    D specificDto = getJsonHelper().parse(getJsonHelper().print(dto), transactionDtoClass);
    copyToDto((T) transaction, specificDto);
    return specificDto;
}
Also used : TransactionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionDTO) PublicKey(io.nem.symbol.core.crypto.PublicKey)

Example 2 with PublicKey

use of io.nem.symbol.core.crypto.PublicKey in project nem2-sdk-java by nemtech.

the class VrfKeyLinkTransactionMapper method createFactory.

@Override
protected TransactionFactory<VrfKeyLinkTransaction> createFactory(NetworkType networkType, Deadline deadline, VrfKeyLinkTransactionDTO transaction) {
    PublicKey linkedPublicKey = PublicKey.fromHexString(transaction.getLinkedPublicKey());
    LinkAction linkAction = LinkAction.rawValueOf(transaction.getLinkAction().getValue());
    return VrfKeyLinkTransactionFactory.create(networkType, deadline, linkedPublicKey, linkAction);
}
Also used : PublicKey(io.nem.symbol.core.crypto.PublicKey) LinkAction(io.nem.symbol.sdk.model.transaction.LinkAction)

Example 3 with PublicKey

use of io.nem.symbol.core.crypto.PublicKey in project nem2-sdk-java by nemtech.

the class TransactionSearchRepositoryIntegrationTest method searchBySignerPublicKeyInvalid.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchBySignerPublicKeyInvalid(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.CONFIRMED);
    PublicKey expectedSignerPublicKey = Account.generateNewAccount(getNetworkType()).getPublicAccount().getPublicKey();
    criteria.setSignerPublicKey(expectedSignerPublicKey);
    List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
    Assertions.assertTrue(transactions.isEmpty());
    helper.assertById(transactionRepository, TransactionGroup.CONFIRMED, transactions);
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) PublicKey(io.nem.symbol.core.crypto.PublicKey) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with PublicKey

use of io.nem.symbol.core.crypto.PublicKey in project nem2-sdk-java by nemtech.

the class VrfKeyLinkTransactionIntegrationTest method basicAnnounce.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void basicAnnounce(RepositoryType type) {
    Account account = config().getNemesisAccount2();
    PublicKey linkedPublicKey = PublicKey.fromHexString("F5D0AAD909CFBC810A3F888C33C57A9051AE1A59D1CDA872A8B90BCA7EF2D34A");
    VrfKeyLinkTransaction linkTransaction = VrfKeyLinkTransactionFactory.create(getNetworkType(), getDeadline(), linkedPublicKey, LinkAction.LINK).maxFee(maxFee).build();
    announceAndValidate(type, account, linkTransaction);
    VrfKeyLinkTransaction unlinkTransaction = VrfKeyLinkTransactionFactory.create(getNetworkType(), getDeadline(), linkedPublicKey, LinkAction.UNLINK).maxFee(maxFee).build();
    announceAndValidate(type, account, unlinkTransaction);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) VrfKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.VrfKeyLinkTransaction) PublicKey(io.nem.symbol.core.crypto.PublicKey) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with PublicKey

use of io.nem.symbol.core.crypto.PublicKey in project nem2-sdk-java by nemtech.

the class Ed25519KeyGenerator method derivePublicKey.

@Override
public PublicKey derivePublicKey(final PrivateKey privateKey) {
    final Ed25519EncodedFieldElement a = Ed25519Utils.prepareForScalarMultiply(privateKey);
    // a * base point is the public key.
    final Ed25519GroupElement pubKey = Ed25519Group.BASE_POINT.scalarMultiply(a);
    // a suitable table of group elements.
    return new PublicKey(pubKey.encode().getRaw());
}
Also used : PublicKey(io.nem.symbol.core.crypto.PublicKey) Ed25519EncodedFieldElement(io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519EncodedFieldElement) Ed25519GroupElement(io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519GroupElement)

Aggregations

PublicKey (io.nem.symbol.core.crypto.PublicKey)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 Test (org.junit.jupiter.api.Test)7 LinkAction (io.nem.symbol.sdk.model.transaction.LinkAction)6 KeyPair (io.nem.symbol.core.crypto.KeyPair)5 Account (io.nem.symbol.sdk.model.account.Account)5 PrivateKey (io.nem.symbol.core.crypto.PrivateKey)4 KeyGenerator (io.nem.symbol.core.crypto.KeyGenerator)3 KeyGeneratorTest (io.nem.symbol.core.crypto.KeyGeneratorTest)3 Address (io.nem.symbol.sdk.model.account.Address)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 CryptoEngine (io.nem.symbol.core.crypto.CryptoEngine)2 Ed25519GroupElement (io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519GroupElement)2 BlockPaginationStreamer (io.nem.symbol.sdk.api.BlockPaginationStreamer)2 BlockRepository (io.nem.symbol.sdk.api.BlockRepository)2 BlockSearchCriteria (io.nem.symbol.sdk.api.BlockSearchCriteria)2 TransactionPaginationStreamer (io.nem.symbol.sdk.api.TransactionPaginationStreamer)2 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)2 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)2