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

Add support for wasm32-pyodide #190

Merged
merged 30 commits into from
Feb 22, 2025
Merged

Add support for wasm32-pyodide #190

merged 30 commits into from
Feb 22, 2025

Conversation

alarmfox
Copy link
Contributor

Summary

I was trying to use this library in Pyodide WASM runtime but it was not supported.

I added the required packages according to their guidelines. There are issues in Threading so I added a check for parallelism != 1 based on the platform.machine().

Pyodide patch
diff --git a/packages/argon2-cffi-bindings/meta.yaml b/packages/argon2-cffi-bindings/meta.yaml
new file mode 100644
index 00000000..45d4e75f
--- /dev/null
+++ b/packages/argon2-cffi-bindings/meta.yaml
@@ -0,0 +1,21 @@
+package:
+  name: argon2-cffi-bindings
+  version: 21.2.0
+  top-level:
+    - _argon2_cffi_bindings
+source:
+  url: https://files.pythonhosted.org/packages/b9/e9/184b8ccce6683b0aa2fbb7ba5683ea4b9c5763f1356347f1312c32e3c66e/argon2-cffi-bindings-21.2.0.tar.gz
+  sha256: bb89ceffa6c791807d1305ceb77dbfacc5aa499891d2c55661c6459651fc39e3
+about:
+  home: https://github.com/hynek/argon2-cffi-bindings
+  PyPI: https://pypi.org/project/argon2-cffi-bindings
+  summary: Low-level CFFI bindings for Argon2
+  license: MIT
+extra:
+  recipe-maintainers:
+    - alarmfox
+requirements:
+  run:
+    - cffi
+build:
+  cflags: -msimd128
diff --git a/packages/argon2-cffi/meta.yaml b/packages/argon2-cffi/meta.yaml
new file mode 100644
index 00000000..e4e8f760
--- /dev/null
+++ b/packages/argon2-cffi/meta.yaml
@@ -0,0 +1,19 @@
+package:
+  name: argon2-cffi
+  version: 23.1.0
+  top-level:
+    - argon2
+source:
+  url: https://files.pythonhosted.org/packages/a4/6a/e8a041599e78b6b3752da48000b14c8d1e8a04ded09c88c714ba047f34f5/argon2_cffi-23.1.0-py3-none-any.whl
+  sha256: c670642b78ba29641818ab2e68bd4e6a78ba53b7eff7b4c3815ae16abf91c7ea
+about:
+  home: ""
+  PyPI: https://pypi.org/project/argon2-cffi
+  summary: Argon2 for Python
+  license: ""
+extra:
+  recipe-maintainers:
+    - alarmfox
+requirements:
+  run:
+    - cffi
diff --git a/packages/argon2-cffi/test_argon2-cffi.py b/packages/argon2-cffi/test_argon2-cffi.py
new file mode 100644
index 00000000..c914cda8
--- /dev/null
+++ b/packages/argon2-cffi/test_argon2-cffi.py
@@ -0,0 +1,9 @@
+from pytest_pyodide import run_in_pyodide
+
+@run_in_pyodide(packages=["argon2-cffi"])
+def test_argon2_cffi():
+    import argon2
+    ph = argon2.PasswordHasher(parallelism=1)
+    hash = ph.hash("test")
+
+    assert ph.verify(hash, "test") == True

Alternative solution

Pyodide supports patching: instead of providing wheel one could provide the source code and this patch, but there will need to build everything from scratch.

Can we work this out?

@alarmfox
Copy link
Contributor Author

Hello, thanks for the response!
I added a few functions in utils.py and profiles.py cleaning up the PasswordHasher class.
Let me know if this fits your idea.

Copy link
Contributor

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Of course, not a maintainer here – but I agree with the idea. Thanks, @alarmfox!

@@ -46,6 +46,23 @@ class InvalidHashError(ValueError):
"""


class UnsupportedParamsError(ValueError):
Copy link
Owner

Choose a reason for hiding this comment

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

This class needs to be added to the API docs.

"""
Should fail if on wasm and parallelism > 1
"""
for machine in ["wasm32", "wasm64"]:
Copy link
Owner

Choose a reason for hiding this comment

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

let's make this a parametrization

@hynek
Copy link
Owner

hynek commented Feb 22, 2025

I was trying to fix it up locally, but unfortunately you opened the PR from your main branch so I couldn't push my changes. There's a reason I beg people to not do that in the PR template, so it would be nice if you could follow that advice in the future.

edit: i have just noticed that this repo was lacking said template and have added it now in 8041a04

@hynek hynek merged commit 52db639 into hynek:main Feb 22, 2025
20 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.

3 participants