Skip to content

Commit

Permalink
feat: Function to convert program hash to base32
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Nov 28, 2024
1 parent 8fb387d commit df7554d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions libertai_utils/aleph/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
hash_base32 = vm_hash_to_base32(item_hash)
return f"https://{hash_base32}.aleph.sh"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit df7554d

Please sign in to comment.