Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk/python] Transfer transaction - support for message types #229

Closed
cryptoBeliever opened this issue May 20, 2022 · 2 comments · Fixed by #340
Closed

[sdk/python] Transfer transaction - support for message types #229

cryptoBeliever opened this issue May 20, 2022 · 2 comments · Fixed by #340
Assignees
Labels
sdk-python Related to the Python SDK. Status: WIP This issue or PR is a work in progress.

Comments

@cryptoBeliever
Copy link
Contributor

cryptoBeliever commented May 20, 2022

Current Behaviour

Old SDKs message specification defined four types of messages:

  • Plain Message (prefix 0)
  • Encrypted Message (prefix 1)
  • Persistent Delegated Message transaction (prefix 254)
  • Raw Message (no prefix or not recognized prefix)

Currently, the SDK user (developer) has only the option to put the message as raw text when creating the transfer transaction object. So SDK user has to:

  • remember (when sending and when reading from API transactions) which prefix is for which transaction type and how to decode messages
  • implement encryption and decryption of messages (in case of encrypted messages)
  • implement persistent delegating message creation

Expected Behaviour

It's desired that SDK users be released from the obligation to remember the specification for various types of messages.
For SDK developers would be very helpful if:

  • he could create objects representing a specific message type (constructor/factory methods)
  • when reading transactions from API provide a way to read messages without knowing the specification e.g. wrapping messages using a typed message object.

Corresponding issue for JS SDK: #228

@cryptoBeliever cryptoBeliever added Status: WIP This issue or PR is a work in progress. sdk-python Related to the Python SDK. labels May 20, 2022
@cryptoBeliever cryptoBeliever changed the title [sdk/javascript] Functionality to encrypt/decrypt message [sdk/python] Functionality to encrypt/decrypt message May 20, 2022
@cryptoBeliever cryptoBeliever changed the title [sdk/python] Functionality to encrypt/decrypt message [sdk/python] Transfer transaction - support for raw/plain/encrypted/persistent delegated message types May 27, 2022
@cryptoBeliever cryptoBeliever changed the title [sdk/python] Transfer transaction - support for raw/plain/encrypted/persistent delegated message types [sdk/python] Transfer transaction - support for message types May 27, 2022
@gimre-xymcity
Copy link
Member

this is currently done via MessageEncoder object,
however, currently in case of NEM it will throw an error if it's instantiated on non-encrypted message type.
additionally try_decode/tryDecocde might throw in some cases

@cryptoBeliever
Copy link
Contributor Author

cryptoBeliever commented Apr 11, 2023

Encrypting and decrypting message work correctly ✔️

encrypted = encoder.encode_deprecated(recipient_public_key, b'Some encrypted message')
print(encrypted.message)

# Create a transfer transaction
transfer = facade.transaction_factory.create({
	'type': 'transfer_transaction_v2',
	'signer_public_key': alicePubkey,
	'recipient_address': facade.network.public_key_to_address(bobKeyPair.public_key),
	'timestamp': networkTime.timestamp,
	'deadline': deadline,
	'fee': 200000,
	'amount': 1000000,
	'message': {
		'message_type': 'encrypted',
		'message': encrypted.message
	}
})

recipient_decoder = MessageEncoder(bobKeyPair)
decoded_message = recipient_decoder.try_decode(alicePubkey, encrypted)
print(decoded_message)
encrypted_message = message_encoder.encode(bobPubkey, b'message')
print(encrypted_message)

# Create a transfer transaction
transfer = facade.transaction_factory.create({
	'type': 'transfer_transaction_v1',
	'signer_public_key': alicePubkey,
	'recipient_address': facade.network.public_key_to_address(bobPubkey),
	'deadline': deadline,
	'fee': 100000,
	'mosaics': [],
	'message': b'\1' + bytes(encrypted_message[1::].hex(), 'utf-8') # workaround for old wallet (there is bug in old SDK that causes double encoding)
})

@cryptoBeliever cryptoBeliever linked a pull request Apr 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdk-python Related to the Python SDK. Status: WIP This issue or PR is a work in progress.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants