Search in sources :

Example 21 with PublicKey

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

the class TestnetTester method sendVotingKey2.

private static void sendVotingKey2(RepositoryFactory repositoryFactory) throws Exception {
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    Account account = Account.createFromPrivateKey(PRIVATE_KEY, networkType);
    System.out.println(account.getAddress().plain());
    Duration duration = repositoryFactory.getEpochAdjustment().toFuture().get();
    Deadline deadline = Deadline.create(duration);
    PublicKey votingKey = PublicKey.fromHexString("463CCC639B5306DD06E56A273E13EF08CAB8D46A8ACA1D3919F19AF89DE116C5");
    VotingKeyLinkTransaction transaction = VotingKeyLinkTransactionFactory.create(networkType, deadline, votingKey, (1), (26280), LinkAction.LINK).maxFee(MAX_FEE).build();
    announceTransaction(repositoryFactory, account, transaction);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) PublicKey(io.nem.symbol.core.crypto.PublicKey) VotingKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.VotingKeyLinkTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Duration(java.time.Duration)

Example 22 with PublicKey

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

the class TransactionSearchRepositoryIntegrationTest method searchBySignerPublicKey.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchBySignerPublicKey(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    Transaction transaction1 = get(streamer.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED)).take(1));
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.CONFIRMED);
    PublicKey expectedSignerPublicKey = transaction1.getSigner().get().getPublicKey();
    criteria.setSignerPublicKey(expectedSignerPublicKey);
    List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
    transactions.forEach(b -> Assertions.assertEquals(expectedSignerPublicKey, b.getSigner().get().getPublicKey()));
    Assertions.assertFalse(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 23 with PublicKey

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

the class NodeKeyLinkTransactionIntegrationTest method basicAnnounce.

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

Example 24 with PublicKey

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

the class Ed25519KeyGeneratorTest method derivePublicKey.

@Test
public void derivePublicKey() {
    final KeyGenerator generator = this.getKeyGenerator();
    final KeyPair keyPair = KeyPair.fromPrivate(PrivateKey.fromHexString("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d"));
    final PublicKey publicKey = generator.derivePublicKey(keyPair.getPrivateKey());
    final PublicKey expected = PublicKey.fromHexString("2134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F2");
    MatcherAssert.assertThat(publicKey, IsEqual.equalTo(expected));
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) PublicKey(io.nem.symbol.core.crypto.PublicKey) KeyGenerator(io.nem.symbol.core.crypto.KeyGenerator) Test(org.junit.jupiter.api.Test) KeyGeneratorTest(io.nem.symbol.core.crypto.KeyGeneratorTest)

Example 25 with PublicKey

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

the class Ed25519KeyGeneratorTest method derivePublicKeyReturnsExpectedPublicKey.

@Test
public void derivePublicKeyReturnsExpectedPublicKey() {
    // Arrange:
    final KeyGenerator generator = this.getKeyGenerator();
    for (int i = 0; i < 100; i++) {
        final KeyPair kp = generator.generateKeyPair();
        // Act:
        final PublicKey publicKey1 = generator.derivePublicKey(kp.getPrivateKey());
        final PublicKey publicKey2 = MathUtils.derivePublicKey(kp.getPrivateKey());
        // Assert:
        MatcherAssert.assertThat(publicKey1, IsEqual.equalTo(publicKey2));
    }
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) PublicKey(io.nem.symbol.core.crypto.PublicKey) KeyGenerator(io.nem.symbol.core.crypto.KeyGenerator) Test(org.junit.jupiter.api.Test) KeyGeneratorTest(io.nem.symbol.core.crypto.KeyGeneratorTest)

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