-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bf2af5
commit 6643d99
Showing
14 changed files
with
791 additions
and
737 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Publish release to PyPi | ||
|
||
on: | ||
release: | ||
types: [ created ] | ||
|
||
jobs: | ||
pypi-publish: | ||
name: Publish release to PyPI | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: pypi | ||
url: https://pypi.org/project/libertai-utils | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install poetry | ||
run: pipx install poetry | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version-file: 'pyproject.toml' | ||
cache: 'poetry' | ||
- name: Install dependencies | ||
run: poetry install | ||
- name: Build package | ||
run: poetry build | ||
- name: Publish package distributions to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# libertai-utils | ||
Libertai python Utilities | ||
|
||
LibertAI internal types and functions |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from libertai_utils.blockchains.ethereum import is_eth_signature_valid, format_eth_address | ||
from libertai_utils.blockchains.solana import is_solana_signature_valid | ||
from libertai_utils.interfaces.subscription import SubscriptionChain | ||
|
||
|
||
def is_signature_valid(chain: SubscriptionChain, message: str, signature: str, address: str) -> bool: | ||
valid = False | ||
|
||
if chain == SubscriptionChain.base: | ||
valid = is_eth_signature_valid(message, signature, address) | ||
elif chain == SubscriptionChain.solana: | ||
valid = is_solana_signature_valid(message, signature, address) | ||
|
||
return valid | ||
|
||
|
||
def format_address(address: str, chain: SubscriptionChain) -> str: | ||
if chain == SubscriptionChain.base: | ||
return format_eth_address(address) | ||
return address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import base64 | ||
|
||
from nacl.exceptions import BadSignatureError | ||
from nacl.signing import VerifyKey | ||
from solders.pubkey import Pubkey | ||
|
||
|
||
def is_solana_signature_valid(message: str, signature: str, address: str) -> bool: | ||
"""Check if a message signature with a Solana wallet is valid | ||
Args: | ||
message: Message that was signed | ||
signature: base64-encoded message signature | ||
address: base58-encoded public key | ||
""" | ||
public_key = Pubkey.from_string(address) | ||
bytes_message = bytes(message, encoding="utf-8") | ||
bytes_signature = bytes(signature, "utf-8") | ||
|
||
try: | ||
retrieved_message = VerifyKey(public_key.__bytes__()).verify( | ||
smessage=bytes_message, signature=base64.b64decode(bytes_signature) | ||
) | ||
return bytes_message == retrieved_message | ||
except BadSignatureError: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.