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

chore: add default padding to base64 oracles response/queries #1937

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

sborrazas
Copy link
Contributor

refs #1931

@sborrazas sborrazas self-assigned this Sep 9, 2024
@vatanasov
Copy link
Contributor

I don't think this will solve the issue. I think the problem is, some of the responses are in Chinese/Japanese (e.g. in here: https://mainnet.aeternity.io/mdw/v3/oracles/ok_qJZPXvWPC7G9kFVEqNjj9NAmwMsQcpRu6E3SSCvCQuwfqpMtN/queries ) and if my findings are correct, aescan is using atob which doesn't decode directly encoded Chinese/Japanese correctly. It seems that a working solution would be to first use URI.encode and then Base.encode64 and in turn aescan could use decodeURIComponent(window.atob(<response>)) which seems to return the correct response. We could also do that for the query, so that everything is uniform.

@sborrazas
Copy link
Contributor Author

@vatanasov I'm pretty sure you don't need any of that, we don't even need the base64 padding. I simply added the padding because it works with all base64 libraries, but it works with atob regardless:
Screen Shot 2024-09-11 at 8 08 06 AM

@janmichek can you describe what you are using to decode base64 strings?

@janmichek
Copy link

janmichek commented Sep 11, 2024

image This is the frontend function depends if its server (nodejs) or browser rendered, that's what is the condition for

@sborrazas
Copy link
Contributor Author

image This is the frontend function depends if its server (nodejs) or browser rendered, that's what is the condition for

@janmichek can we switch to using decodeURIComponent(escape(atob(STRING))) in the browser and Buffer.from(STRING, "base64").toString("utf8") in the server? Works both with and without padding

console.log(Buffer.from("5oiQ5Yqf5LqGIQ==", "base64").toString('utf8')); // 成功了!
console.log(Buffer.from("5oiQ5Yqf5LqGIQ", "base64").toString('utf8')); // 成功了!

@janmichek
Copy link

decodeURIComponent

Yea I guess that should work in browser

@sborrazas sborrazas merged commit 1783f0d into master Sep 19, 2024
7 checks passed
@sborrazas sborrazas deleted the base64-oracles branch September 19, 2024 11:58
@janmichek
Copy link

@sborrazas
There seems to be some issue with it, can you check it please?

https://aescan.io/oracles/ok_2fVpBb8j58mNQcVjY7bwUVpBWZv6AySGDjqepNofU8XGGmEN53

image

The decoding you suggested says its a malformed string, or am I doing something wrong?

@sborrazas
Copy link
Contributor Author

@janmichek The response/query values for oracles are just binaries, meaning not all binaries have valid utf8 or ascii representations. Do you know what the utf8 representation for that example you gave should be?

@janmichek
Copy link

@janmichek The response/query values for oracles are just binaries, meaning not all binaries have valid utf8 or ascii representations. Do you know what the utf8 representation for that example you gave should be?

No, I don't know what the result should be.
In that case the current solution is ok, no? I will just sanitize the empty string for N/A.
The solution you suggested decodeURIComponent will cause error.

@sborrazas
Copy link
Contributor Author

That's right, I would display something for when the binary is not a UTF-8/ASCII representation

@janmichek
Copy link

It will be fixed in here
aeternity/aescan#948

You can close this PR

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.

3 participants