From df7554d944becc2181f1723c44ad33b5d7188209 Mon Sep 17 00:00:00 2001 From: Reza Rahemtola Date: Thu, 28 Nov 2024 18:12:26 +0900 Subject: [PATCH] feat: Function to convert program hash to base32 --- libertai_utils/aleph/program.py | 10 ++++++++-- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libertai_utils/aleph/program.py b/libertai_utils/aleph/program.py index 16a90bf..369f831 100644 --- a/libertai_utils/aleph/program.py +++ b/libertai_utils/aleph/program.py @@ -3,10 +3,16 @@ from typing_extensions import Literal +def vm_hash_to_base32(item_hash: str) -> str: + # From aleph-client + hash_base32 = b32encode(b16decode(item_hash.upper())).strip(b"=").lower().decode() + return hash_base32 + + def get_vm_url(item_hash: str, url_type: Literal["host", "path"] = "host") -> str: if url_type == "path": return f"https://aleph.sh/vm/{item_hash}" # From aleph-client - hash_base32 = b32encode(b16decode(item_hash.upper())).strip(b"=").lower().decode() - return f"https://{hash_base32}.aleph.sh" \ No newline at end of file + hash_base32 = vm_hash_to_base32(item_hash) + return f"https://{hash_base32}.aleph.sh" diff --git a/pyproject.toml b/pyproject.toml index c085392..7d04238 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "libertai-utils" -version = "0.0.7" +version = "0.0.8" description = "LibertAI internal types and functions" authors = ["LibertAI.io team "] readme = "README.md"