Implement Hashcash algorithm to fix 402 PaymentRequired errors on login#249
Implement Hashcash algorithm to fix 402 PaymentRequired errors on login#249gpailler merged 10 commits intogpailler:masterfrom
Conversation
gpailler
left a comment
There was a problem hiding this comment.
Thank you very much for your contribution. I’ve added a minor comment regarding some duplicated code.
Once this PR is merged, I’ll publish a version on MyGet. If everything works as expected, I’ll release an official version on NuGet.
Thanks again!
MegaApiClient/MegaApiClient.cs
Outdated
|
|
||
| if (BitConverter.IsLittleEndian) | ||
| { | ||
| hashPrefix = ReverseBytes(hashPrefix); |
There was a problem hiding this comment.
| hashPrefix = ReverseBytes(hashPrefix); | |
| hashPrefix = BinaryPrimitives.ReverseEndianness(hashPrefix); |
this part was failing for me, so I tried replaced it with the builtin function for reversing the endianess and it seems to work
There was a problem hiding this comment.
Have not implemented this yet because it requires installing System.Memory, but let me know if you prefer this @gpailler
There was a problem hiding this comment.
I prefer to not introduce a new dependency here.
@Bl4Cc4t Did you have a chance to investigate why the original code was failing?
@tr4wzified Maybe you can use the following instead
if (BitConverter.IsLittleEndian)
{
Array.Reverse(hash);
}
var hashPrefix = BitConverter.ToUInt32(hash, 0);There was a problem hiding this comment.
@Bl4Cc4t @tr4wzified ? I'm just waiting for your feedback in order to merge this PR and deploy a first version on MyGet.
There was a problem hiding this comment.
I'll check this out later today
There was a problem hiding this comment.
Changed it, looks like everything's working here
|
Hi, just to know, is there an estimation of when will this merge be done? Is it stall? |
|
Hey, sorry, I kind of forgot about this. I will have a look in a sec to adjust the PR based on the review and comments here. |
|
I replaced the functions with the existing ones found in the extensions, I had missed those. I haven't used BinaryPrimitives because it required installing another NuGet package, but let me know if that is the preferred way of handling it. |
Took inspiration from qgustavor/mega#239 (comment) and implemented the hashcash in this library which should fix #248