Search in sources :

Example 26 with PublicKey

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

the class Ed25519KeyGeneratorTest method derivedPublicKeyIsValidPointOnCurve.

@Test
public void derivedPublicKeyIsValidPointOnCurve() {
    // Arrange:
    final KeyGenerator generator = this.getKeyGenerator();
    for (int i = 0; i < 100; i++) {
        final KeyPair kp = generator.generateKeyPair();
        // Act:
        final PublicKey publicKey = generator.derivePublicKey(kp.getPrivateKey());
        // Assert (throws if not on the curve):
        Ed25519GroupElement decode = new Ed25519EncodedGroupElement(publicKey.getBytes()).decode();
        Assertions.assertNotNull(decode);
    }
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) PublicKey(io.nem.symbol.core.crypto.PublicKey) Ed25519GroupElement(io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519GroupElement) KeyGenerator(io.nem.symbol.core.crypto.KeyGenerator) Ed25519EncodedGroupElement(io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519EncodedGroupElement) Test(org.junit.jupiter.api.Test) KeyGeneratorTest(io.nem.symbol.core.crypto.KeyGeneratorTest)

Example 27 with PublicKey

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

the class Ed25519BlockDeriveVectorTester method testResolveSharedKey.

@ParameterizedTest
@MethodSource("testResolveSharedKey")
void testResolveSharedKey(String privateKey, String otherPublicKey, String scalarMulResult, String sharedKey) {
    PrivateKey privateKeyObject = PrivateKey.fromHexString(privateKey);
    PublicKey otherPublicKeyObject = PublicKey.fromHexString(otherPublicKey);
    byte[] resolvedSharedKey = Ed25519BlockCipher.getSharedKey(privateKeyObject, otherPublicKeyObject);
    byte[] resolvedSharedSecret = Ed25519BlockCipher.getSharedSecret(privateKeyObject, otherPublicKeyObject);
    Assertions.assertEquals(sharedKey.toUpperCase(), ConvertUtils.toHex(resolvedSharedKey).toUpperCase());
    Assertions.assertEquals(scalarMulResult.toUpperCase(), ConvertUtils.toHex(resolvedSharedSecret).toUpperCase());
}
Also used : PrivateKey(io.nem.symbol.core.crypto.PrivateKey) PublicKey(io.nem.symbol.core.crypto.PublicKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 28 with PublicKey

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

the class TransactionSearchCriteriaTest method shouldUseBuilderMethods.

@Test
void shouldUseBuilderMethods() {
    Address address1 = Address.generateRandom(NetworkType.MIJIN_TEST);
    Address address2 = Address.generateRandom(NetworkType.MIJIN_TEST);
    PublicKey signerPublicKey = PublicKey.fromHexString("227F");
    MosaicId mosaicId = new MosaicId(BigInteger.TEN);
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED).id("theId").order(OrderBy.ASC).pageSize(10).pageNumber(5).transactionTypes(Collections.singletonList(TransactionType.MOSAIC_GLOBAL_RESTRICTION));
    criteria.address(address1);
    criteria.recipientAddress(address2);
    criteria.embedded(true);
    criteria.height(BigInteger.ONE);
    criteria.offset("offset1");
    criteria.signerPublicKey(signerPublicKey);
    criteria.fromTransferAmount(BigInteger.valueOf(10));
    criteria.toTransferAmount(BigInteger.valueOf(20));
    criteria.transferMosaicId(mosaicId);
    Assertions.assertEquals("theId", criteria.getId());
    Assertions.assertEquals(OrderBy.ASC, criteria.getOrder());
    Assertions.assertEquals(10, criteria.getPageSize());
    Assertions.assertEquals(5, criteria.getPageNumber());
    Assertions.assertEquals(Collections.singletonList(TransactionType.MOSAIC_GLOBAL_RESTRICTION), criteria.getTransactionTypes());
    Assertions.assertEquals(address1, criteria.getAddress());
    Assertions.assertEquals(address2, criteria.getRecipientAddress());
    Assertions.assertEquals(true, criteria.getEmbedded());
    Assertions.assertEquals("offset1", criteria.getOffset());
    Assertions.assertEquals(BigInteger.ONE, criteria.getHeight());
    Assertions.assertEquals(signerPublicKey, criteria.getSignerPublicKey());
    Assertions.assertEquals(BigInteger.valueOf(10), criteria.getFromTransferAmount());
    Assertions.assertEquals(BigInteger.valueOf(20), criteria.getToTransferAmount());
    Assertions.assertEquals(mosaicId, criteria.getTransferMosaicId());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PublicKey(io.nem.symbol.core.crypto.PublicKey) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 29 with PublicKey

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

the class TransactionSearchCriteriaTest method shouldSetValues.

@Test
void shouldSetValues() {
    Address address1 = Address.generateRandom(NetworkType.MIJIN_TEST);
    Address address2 = Address.generateRandom(NetworkType.MIJIN_TEST);
    PublicKey signerPublicKey = PublicKey.fromHexString("227F");
    MosaicId mosaicId = new MosaicId(BigInteger.TEN);
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED);
    criteria.setId("theId");
    criteria.setOrder(OrderBy.DESC);
    criteria.setPageSize(10);
    criteria.setTransactionTypes(Collections.singletonList(TransactionType.MOSAIC_GLOBAL_RESTRICTION));
    criteria.setPageNumber(5);
    criteria.setAddress(address1);
    criteria.setRecipientAddress(address2);
    criteria.setEmbedded(true);
    criteria.setHeight(BigInteger.ONE);
    criteria.setFromHeight(BigInteger.valueOf(2));
    criteria.setToHeight(BigInteger.valueOf(3));
    criteria.setOffset("offset1");
    criteria.setSignerPublicKey(signerPublicKey);
    criteria.setFromTransferAmount(BigInteger.valueOf(10));
    criteria.setToTransferAmount(BigInteger.valueOf(20));
    criteria.setTransferMosaicId(mosaicId);
    criteria.setSignerPublicKey(signerPublicKey);
    Assertions.assertEquals("theId", criteria.getId());
    Assertions.assertEquals(OrderBy.DESC, criteria.getOrder());
    Assertions.assertEquals(10, criteria.getPageSize());
    Assertions.assertEquals(5, criteria.getPageNumber());
    Assertions.assertEquals(Collections.singletonList(TransactionType.MOSAIC_GLOBAL_RESTRICTION), criteria.getTransactionTypes());
    Assertions.assertEquals(address1, criteria.getAddress());
    Assertions.assertEquals(address2, criteria.getRecipientAddress());
    Assertions.assertEquals(true, criteria.getEmbedded());
    Assertions.assertEquals("offset1", criteria.getOffset());
    Assertions.assertEquals(BigInteger.ONE, criteria.getHeight());
    Assertions.assertEquals(BigInteger.valueOf(2), criteria.getFromHeight());
    Assertions.assertEquals(BigInteger.valueOf(3), criteria.getToHeight());
    Assertions.assertEquals(signerPublicKey, criteria.getSignerPublicKey());
    Assertions.assertEquals(BigInteger.valueOf(10), criteria.getFromTransferAmount());
    Assertions.assertEquals(BigInteger.valueOf(20), criteria.getToTransferAmount());
    Assertions.assertEquals(mosaicId, criteria.getTransferMosaicId());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PublicKey(io.nem.symbol.core.crypto.PublicKey) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 30 with PublicKey

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

the class TransactionSearchCriteriaTest method shouldBeEquals.

@Test
void shouldBeEquals() {
    Address address1 = Address.generateRandom(NetworkType.MIJIN_TEST);
    Address address2 = Address.generateRandom(NetworkType.MIJIN_TEST);
    PublicKey signerPublicKey = PublicKey.fromHexString("227F");
    TransactionSearchCriteria criteria1 = new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED).id("theId").order(OrderBy.ASC).pageSize(10).pageNumber(5).transactionTypes(Collections.singletonList(TransactionType.MOSAIC_GLOBAL_RESTRICTION));
    criteria1.address(address1);
    criteria1.recipientAddress(address2);
    criteria1.embedded(true);
    criteria1.height(BigInteger.ONE);
    criteria1.offset("offset1");
    criteria1.setSignerPublicKey(signerPublicKey);
    criteria1.setFromHeight(BigInteger.valueOf(2));
    criteria1.setToHeight(BigInteger.valueOf(3));
    TransactionSearchCriteria criteria2 = new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED).id("theId").order(OrderBy.ASC).pageSize(10).pageNumber(5).transactionTypes(Collections.singletonList(TransactionType.MOSAIC_GLOBAL_RESTRICTION));
    criteria2.address(address1);
    criteria2.recipientAddress(address2);
    criteria2.embedded(true);
    criteria2.height(BigInteger.ONE);
    criteria2.offset("offset1");
    criteria2.setSignerPublicKey(signerPublicKey);
    criteria2.setFromHeight(BigInteger.valueOf(2));
    criteria2.setToHeight(BigInteger.valueOf(3));
    Assertions.assertEquals(new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED), new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED));
    Assertions.assertEquals(criteria1, criteria2);
    Assertions.assertEquals(criteria1, criteria1);
    Assertions.assertEquals(criteria1.hashCode(), criteria2.hashCode());
    criteria2.embedded(false);
    Assertions.assertNotEquals(criteria1, criteria2);
    Assertions.assertNotEquals(criteria1.hashCode(), criteria2.hashCode());
    criteria2.pageNumber(100);
    criteria2.embedded(true);
    Assertions.assertNotEquals(criteria1, criteria2);
    Assertions.assertNotEquals(criteria1.hashCode(), criteria2.hashCode());
    Assertions.assertNotEquals("ABC", criteria2);
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PublicKey(io.nem.symbol.core.crypto.PublicKey) Test(org.junit.jupiter.api.Test)

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