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

decode hex encoded memo data #1429

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

decode hex encoded memo data #1429

wants to merge 5 commits into from

Conversation

AdamREQ
Copy link

@AdamREQ AdamREQ commented Apr 30, 2020

There are a few conversions happening when paying with a memo: In our example we use the memo 0xc8b21e166f0d1604

During the encoding we have the following process:

We go from a string to UTF8 encoded (which gives the same result) 0xc8b21e166f0d1604 -> 0xc8b21e166f0d1604

We then send it to a method called toRlp -

const dataBuffer = rlp.encode(data);
which encodes it again (this here is the issue)

Utf8 encoded result gets converted to hex (less the 0x at the start) -

const hexstring = Encoding.toHex(input);
c8b21e166f0d1604 -> 63386232316531363666306431363034
It then gets broadcasted on the blockchain as the result of 2 + 0x = 0x63386232316531363666306431363034

However, at step 2 there is a small issue with the encoding. See below

toUtf8 = 48,120,99,56,98,50,49,101,49,54,54,102,48,100,49,54,48,52
toRlp = 146,48,120,99,56,98,50,49,101,49,54,54,102,48,100,49,54,48,52

The Utf8 encoding is fine, however the toRlp adds a non-ascii character during the encoding process. In turn this results in step 3 encoding as a hex which should not be happening.

Due to the incorrect character during the toRlp encoding it causes the exception to be thrown here:

return Encoding.fromUtf8(input);

This fix decodes the data prior to running the Encoding.fromUtf8(decodedRlp); line, this removes the non-ascii character which stops the Exception being thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant