Search in sources :

Example 1 with PersistentHarvestingDelegationMessage

use of io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method createPersistentDelegationRequestTransaction.

@Test
void createPersistentDelegationRequestTransaction() {
    Duration epochAdjustment = Duration.ofSeconds(100);
    KeyPair signingPrivateKey = KeyPair.fromPrivate(PrivateKey.fromHexString("2602F4236B199B3DF762B2AAB46FC3B77D8DDB214F0B62538D3827576C46C111"));
    KeyPair vrfPrivateKey = KeyPair.fromPrivate(PrivateKey.fromHexString("2602F4236B199B3DF762B2AAB46FC3B77D8DDB214F0B62538D3827576C46C000"));
    KeyPair recipient = KeyPair.fromPrivate(PrivateKey.fromHexString("B72F2950498111BADF276D6D9D5E345F04E0D5C9B8342DA983C3395B4CF18F08"));
    TransferTransaction transferTransaction = TransferTransactionFactory.createPersistentDelegationRequestTransaction(networkType, Deadline.create(epochAdjustment), signingPrivateKey.getPrivateKey(), vrfPrivateKey.getPrivateKey(), recipient.getPublicKey()).build();
    assertEquals(networkType, transferTransaction.getNetworkType());
    assertEquals(1, (int) transferTransaction.getVersion());
    assertTrue(LocalDateTime.now().isBefore(transferTransaction.getDeadline().getLocalDateTime(epochAdjustment)));
    assertEquals(BigInteger.valueOf(0), transferTransaction.getMaxFee());
    assertEquals(Address.createFromPublicKey(recipient.getPublicKey().toHex(), networkType), transferTransaction.getRecipient());
    assertEquals(0, transferTransaction.getMosaics().size());
    assertNotNull(transferTransaction.getMessage());
    assertEquals(MessageType.PERSISTENT_HARVESTING_DELEGATION_MESSAGE, transferTransaction.getMessage().get().getType());
    assertNotNull(transferTransaction.getMessage().get().getText());
    PersistentHarvestingDelegationMessage message = (PersistentHarvestingDelegationMessage) transferTransaction.getMessage().get();
    HarvestingKeys decodedKeys = message.decryptPayload(recipient.getPrivateKey());
    Assertions.assertEquals(signingPrivateKey.getPrivateKey(), decodedKeys.getSigningPrivateKey());
    Assertions.assertEquals(vrfPrivateKey.getPrivateKey(), decodedKeys.getVrfPrivateKey());
    byte[] actual = transferTransaction.serialize();
    BinarySerialization serialization = new BinarySerializationImpl();
    TransferTransaction deserialized = (TransferTransaction) serialization.deserialize(actual);
    assertEquals(MessageType.PERSISTENT_HARVESTING_DELEGATION_MESSAGE, deserialized.getMessage().get().getType());
    PersistentHarvestingDelegationMessage deserializedMessage = (PersistentHarvestingDelegationMessage) deserialized.getMessage().get();
    HarvestingKeys decodedKeys2 = deserializedMessage.decryptPayload(recipient.getPrivateKey());
    Assertions.assertEquals(signingPrivateKey.getPrivateKey(), decodedKeys2.getSigningPrivateKey());
    Assertions.assertEquals(vrfPrivateKey.getPrivateKey(), decodedKeys2.getVrfPrivateKey());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) KeyPair(io.nem.symbol.core.crypto.KeyPair) PersistentHarvestingDelegationMessage(io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage) HarvestingKeys(io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage.HarvestingKeys) Duration(java.time.Duration) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Example 2 with PersistentHarvestingDelegationMessage

use of io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage in project nem2-sdk-java by nemtech.

the class TransferTransactionIntegrationTest method assertPersistentDelegationTransaction.

private void assertPersistentDelegationTransaction(KeyPair recipientKeyPair, KeyPair signingKeyPair, KeyPair vrfPrivateKey, TransferTransaction transaction) {
    Assertions.assertTrue(transaction.getMessage().get() instanceof PersistentHarvestingDelegationMessage);
    Assertions.assertEquals(MessageType.PERSISTENT_HARVESTING_DELEGATION_MESSAGE, transaction.getMessage().get().getType());
    HarvestingKeys decryptedMessage = ((PersistentHarvestingDelegationMessage) transaction.getMessage().get()).decryptPayload(recipientKeyPair.getPrivateKey());
    Assertions.assertEquals(vrfPrivateKey.getPrivateKey(), decryptedMessage.getVrfPrivateKey());
    Assertions.assertEquals(signingKeyPair.getPrivateKey(), decryptedMessage.getSigningPrivateKey());
}
Also used : PersistentHarvestingDelegationMessage(io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage) HarvestingKeys(io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage.HarvestingKeys)

Aggregations

PersistentHarvestingDelegationMessage (io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage)2 HarvestingKeys (io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage.HarvestingKeys)2 KeyPair (io.nem.symbol.core.crypto.KeyPair)1 BinarySerialization (io.nem.symbol.sdk.api.BinarySerialization)1 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1