From e6f5aac5bfd2484fd431de0e95d31e4c7396de00 Mon Sep 17 00:00:00 2001 From: Bibo Hao Date: Thu, 7 May 2026 20:00:10 +0800 Subject: [PATCH 1/3] feat: new hash func --- src/aloha/encrypt/hash.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/aloha/encrypt/hash.py b/src/aloha/encrypt/hash.py index 3eecaa8..b990bf7 100644 --- a/src/aloha/encrypt/hash.py +++ b/src/aloha/encrypt/hash.py @@ -24,3 +24,18 @@ def hash_obj(obj): """Hash an arbitrary JSON-serializable object.""" s = json.dumps(obj, sort_keys=True, ensure_ascii=False, default=str) return hashlib.md5(s.encode()).hexdigest() + + +def hash_base62(s: str, length: int = 6) -> str: + """Return a Base62-encoded hash of a string with specified length.""" + assert length > 0 and length <= 11, "Length must be between 1 and 11 for Base62 encoding." + + CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + digest = hashlib.sha256(s.encode()).digest() # 32 bytes = 256 bits + # Convert the digest to an integer and then to Base62 + num = int.from_bytes(digest, "big") + result = [] + for _ in range(length): + result.append(CHARS[num % 62]) + num //= 62 + return "".join(reversed(result)) From 8f6143413f3b19f247513d8420b22da51246d2a3 Mon Sep 17 00:00:00 2001 From: Bibo Hao Date: Tue, 23 Jun 2026 19:28:57 +0800 Subject: [PATCH 2/3] update code --- src/aloha/encrypt/jwt.py | 4 ++-- src/aloha/encrypt/rsa.py | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/aloha/encrypt/jwt.py b/src/aloha/encrypt/jwt.py index 5de4ebb..d732cde 100644 --- a/src/aloha/encrypt/jwt.py +++ b/src/aloha/encrypt/jwt.py @@ -4,10 +4,10 @@ from ..logger import LOG -LOG.debug("Using pyjwt == %s" % jwt.__version__.__str__()) +LOG.debug("Using pyjwt == %s" % str(jwt.__version__)) -def encode(secret_key: str, payload: dict, headers: dict = None, **kwargs): +def encode(secret_key: str, payload: dict, headers: dict | None = None, **kwargs): """Encode a payload into a JWT token.""" token = jwt.encode(payload=payload, key=secret_key, headers=headers, **kwargs) return token diff --git a/src/aloha/encrypt/rsa.py b/src/aloha/encrypt/rsa.py index 5d37847..8c95953 100644 --- a/src/aloha/encrypt/rsa.py +++ b/src/aloha/encrypt/rsa.py @@ -176,8 +176,7 @@ def main(): y_dec = rsa_dec.decrypt_with_private_key(y_bin, key_private=key_pri) y_txt = y_dec.decode("UTF-8") - print( - "[test {i_case} success = {status}] {src} -> {enc}".format( - i_case=i, status=(y_txt == str_src), src=y_txt, enc=x_txt - ) + msg = "[test {i_case} success = {status}] {src} -> {enc}".format( + i_case=i, status=(y_txt == str_src), src=y_txt, enc=x_txt ) + print(msg) From 0e4391579d86e0160a440edd214e7121cbc8694f Mon Sep 17 00:00:00 2001 From: Bibo Hao Date: Tue, 23 Jun 2026 19:35:06 +0800 Subject: [PATCH 3/3] update docs --- .github/workflows/build.yml | 6 +++--- README.md | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1ef8b9..cd68bc9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: job-ruff: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - uses: actions/setup-python@v6 with: python-version: "3.13" @@ -36,7 +36,7 @@ jobs: continue-on-error: true if: (github.actor != 'dependabot[bot]') steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - run: | semgrep ci --verbose \ --config p/ci \ @@ -51,7 +51,7 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it # sudo python setup.py install clean --all - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - name: pip-install-test run: | diff --git a/README.md b/README.md index 9ccc21d..c21c755 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![License](https://img.shields.io/github/license/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/blob/main/LICENSE) [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/LabNow-ai/aloha-python/build.yml?branch=main)](https://github.com/LabNow-ai/aloha-python/actions) -[![Join the Gitter Chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/LabNow-ai/) [![PyPI version](https://img.shields.io/pypi/v/aloha)](https://pypi.python.org/pypi/aloha/) [![PyPI Downloads](https://img.shields.io/pypi/dm/aloha)](https://pepy.tech/badge/aloha/) [![Code Activity](https://img.shields.io/github/commit-activity/m/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/pulse) @@ -15,7 +14,10 @@ Please generously STAR★ our project or donate to us! [![GitHub Starts](https://img.shields.io/github/stars/LabNow-ai/aloha-python.svg?label=Stars&style=social)](https://github.com/LabNow-ai/aloha-python/stargazers) -- To contribute or talk to a human: [![Open an Issue on GitHub](https://img.shields.io/github/issues/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/issues) [![Join the Discord Chat](https://img.shields.io/badge/Discuss_on-Discord-green)](https://discord.gg/kHUzgQxgbJ) +- To understand the package, read the [📚docs](https://aloha-python.readthedocs.io/) or [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/LabNow-ai/lab-foundation) + +- To contribute or talk to a human: [![Open an Issue on GitHub](https://img.shields.io/github/issues/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/issues) [![Join the Discord Chat](https://img.shields.io/badge/Discuss_on-Discord-green)](https://discord.gg/kHUzgQxgbJ) [![Join the Gitter Chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/LabNow-ai/) + ## Getting started