Call to sendMessage with encrypted message

Hello team!

I am trying to make a call to sendMessage with the following fields:

messageToEncrypt: message,
messageToEncryptIsText: true,
encryptedMessageIsPrunable: true,

The problem is that it doesn't return unsignedTransactionBytes to be able to sign it.

What am I doing wrong?

If I try sending a message in plain text it does return unsignedTransactionBytes and everything works correctly.

Thank you very much for your time.

Are you providing a secretPhrase? The secret phrase is needed to do the encryption.

Thank you for your response.

Currently we always use the publicKey to sign messages, we never use the passPhrase.

Could this be the problem?
Isn't it insecure to send requests with the key in plain text?

I guess you mean that you create the transaction bytes with pubic key? You cannot sign with pubic key :slight_smile:

Encryption also cannot be done without pubic key, so the API returns the best it can.

Yes, it is insecure to provide your privateKey/secretPhrase in plain text or to a node you don't own. I'm not sure what is your setup and where the signing happens. Wherever it is, you can do the encryption there and then provide the encrypted data via encryptedMessageData and encryptedMessageNonce

Yes, it is just as you say. I explained myself wrong, my mistake.

I am trying to generate the transationBytes to sign it locally.

The problem is that the request does not return unsignedTransactionBytes.

What kind of encryption does the message have? I will encrypt it locally and send it via encryptedMessageData and encryptedMessageNonce.

I am not sure how to do this encryption.
Checking the API I can only see encryptTo which also asks for the passPhrase.

Any solution?

Of course no API can do the encryption without a private key.

We use AES where the shared key is calculated from the sender's private, recipient public and the nonce. See Crypto.getSharedKey for more details. If you use java locally, you can depend on ardor.jar (here we provide it as gradle project which can be included in your project Bitbucket ) and call e.g. EncryptedData.encrypt or Account.encryptTo. This should be available in javascript too. Not sure for other languages.

how do you sign it locally - this is the main question. Easiest thing is to do the encryption there.

I am using ReactJS + ArdorJS.

I'm checking and there is the encryptMessage function, I think it could be ideal.

The problem is that when calling the function the library generates an error.

It seems that the problem is with the curve25519_ library. (Start on line 380)

I am trying to replicate the same operation on my own.

The process is as follows:

  • I get the public key from the receiver

  • I encrypt the message

Here it already generates a failure, but the path would follow:

  • Calculate the fees

  • I generate unsignedTransactionBytes and sign it

  • Broadcast it

UPDATE

It was a typo. When exporting a single package there is no need to place the braces ({})

In the file ardorjs/util/curve25519_.js in the last line:
export default { curve25519_ }; to export default curve25519_;

Now I can encrypt and send the message.
Everything is solved!

Thank you very much!

OK, I pushed your fix and one more fix of the verification tests, which was preventing me to test your stuff. I pushed to my fork of the repo (GitHub - petko-petkov-jelurida/ardorjs: Transaction signing for ardor transactions, and ardor address creations) and created a pull request to GitHub - mrv777/ardorjs: Transaction signing for ardor transactions, and ardor address creations.

I didn't test your fix, maybe check it.

Thanks!

For me, the solution is fully functional.

In addition I have found other errors, you can see them in:

You are welcome, we are here to build! :beers: