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