Skip to content

Commit

Permalink
- change docs workflow name
Browse files Browse the repository at this point in the history
- add verify method to Keypair class
  • Loading branch information
Snedashkovsky committed Feb 1, 2024
1 parent 2dd4fe4 commit c854429
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: website
name: python api doc

# build the documentation whenever there are new commits on main
on:
Expand Down
2 changes: 1 addition & 1 deletion cybertensor/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.requests import Request
from starlette.responses import Response
from substrateinterface import Keypair

import cybertensor
from cybertensor.keypair import Keypair

""" Create and init Axon, which services Forward and Backward requests from other neurons.
"""
Expand Down
34 changes: 34 additions & 0 deletions cybertensor/keypair.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@ def create_from_private_key(
prefix=prefix,
)

def verify(self, data: Union[bytes, str], signature: Union[bytes, str]) -> bool:
"""
Verifies data with specified signature
Parameters
----------
data: data to be verified in bytes or hex string format
signature: signature in bytes or hex string format
Returns
-------
True if data is signed with this Keypair, otherwise False
"""

if data[0:2] == "0x":
data = bytes.fromhex(data[2:])
elif type(data) is str:
data = data.encode()

if type(signature) is str and signature[0:2] == "0x":
signature = bytes.fromhex(signature[2:])

if type(signature) is not bytes:
raise TypeError("Signature should be of type bytes or a hex-string")

# TODO replace verify function to correct
verified = True
# verified = crypto_verify_fn(signature, data, self.public_key)
#
# if not verified:
# verified = crypto_verify_fn(signature, b'<Bytes>' + data + b'</Bytes>', self.public_key)
#
return verified

def __repr__(self):
if self.address:
return f"<Keypair (address={self.address})>"
Expand Down

0 comments on commit c854429

Please sign in to comment.