Skip to content

Implement Hashcash algorithm to fix 402 PaymentRequired errors on login#249

Merged
gpailler merged 10 commits intogpailler:masterfrom
tr4wzified:hashcash
Aug 14, 2025
Merged

Implement Hashcash algorithm to fix 402 PaymentRequired errors on login#249
gpailler merged 10 commits intogpailler:masterfrom
tr4wzified:hashcash

Conversation

@tr4wzified
Copy link
Copy Markdown
Contributor

Took inspiration from qgustavor/mega#239 (comment) and implemented the hashcash in this library which should fix #248

Copy link
Copy Markdown
Owner

@gpailler gpailler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!


if (BitConverter.IsLittleEndian)
{
hashPrefix = ReverseBytes(hashPrefix);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have not implemented this yet because it requires installing System.Memory, but let me know if you prefer this @gpailler

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bl4Cc4t @tr4wzified ? I'm just waiting for your feedback in order to merge this PR and deploy a first version on MyGet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check this out later today

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it, looks like everything's working here

@andrescirulo
Copy link
Copy Markdown

Hi, just to know, is there an estimation of when will this merge be done? Is it stall?
Thanks a lot

@tr4wzified
Copy link
Copy Markdown
Contributor Author

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.

@tr4wzified
Copy link
Copy Markdown
Contributor Author

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.

@gpailler gpailler merged commit 5820a58 into gpailler:master Aug 14, 2025
4 of 5 checks passed
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.

Error 402 "Payment Required" while login

4 participants