Skip to content

Commit

Permalink
vali subspace fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 18, 2024
2 parents 652909b + e88c1f3 commit daf423c
Show file tree
Hide file tree
Showing 25 changed files with 509 additions and 560 deletions.
9 changes: 0 additions & 9 deletions bounty/bounty.py

This file was deleted.

2 changes: 0 additions & 2 deletions bounty/bounty.yaml

This file was deleted.

39 changes: 39 additions & 0 deletions commune/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,45 @@ def forward(self,*args,return_future:bool=False, timeout:str=4, **kwargs):
else:
return self.loop.run_until_complete(forward_future)





@classmethod
def call_search(cls,
search : str, *args,
timeout : int = 10,
network:str = 'local',
key:str = None,
kwargs = None,
return_future:bool = False,
**extra_kwargs) -> None:
if '/' in search:
search, fn = search.split('/')
namespace = c.namespace(search=search, network=network)
future2module = {}
for module, address in namespace.items():
c.print(args, kwargs, extra_kwargs)
future = c.submit(c.call,

kwargs = { 'module': module, 'fn': fn, 'timeout': timeout,
'network': network, 'key': key,
'args' : args,
'kwargs': kwargs, 'return_future': return_future,
**extra_kwargs} )
future2module[future] = module
futures = list(future2module.keys())
result = {}
progress_bar = c.tqdm(len(futures))
for future in c.as_completed(futures):
module = future2module.pop(future)
futures.remove(future)
progress_bar.update(1)
result[module] = future.result()

return result



__call__ = forward

Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions commune/key/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def add_key(cls, path:str, mnemonic:str = None, password:str=None, refresh:bool=
if cls.key_exists(path) and not refresh :
c.print(f'key already exists at {path}', color='red')
return json.loads(cls.get(path))
c.print(f'generating key {path}')
key = cls.new_key(mnemonic=mnemonic, private_key=private_key, **kwargs)
key.path = path
key_json = key.to_json()
Expand Down Expand Up @@ -903,15 +904,14 @@ def export_to_encrypted_json(self, passphrase: str, name: str = None) -> dict:

return json_data

seperator = "<DATA::SIGNATURE>"



def sign(self,
data: Union[ScaleBytes, bytes, str],
return_json:bool=False,
return_str = False,
seperator = None
seperator = "<DATA::SIGNATURE>"
) -> bytes:
"""
Creates a signature for given data
Expand All @@ -925,7 +925,6 @@ def sign(self,
signature in bytes
"""
seperator = seperator or self.seperator
if not isinstance(data, str):
data = c.python2str(data)
if type(data) is ScaleBytes:
Expand Down Expand Up @@ -964,11 +963,16 @@ def sign(self,

def ticket2address(self, ticket, **kwargs):
return self.verify(ticket, **kwargs)

def signature2address(self, sig, **kwargs):
return self.verify(sig, return_address=True, **kwargs)
sig2addy = signature2address

def verify(self, data: Union[ScaleBytes, bytes, str, dict],
signature: Union[bytes, str] = None,
public_key:Optional[str]= None,
return_address = False,
seperator = "<DATA::SIGNATURE>",
ss58_format = 42,
**kwargs
) -> bool:
Expand All @@ -987,8 +991,8 @@ def verify(self, data: Union[ScaleBytes, bytes, str, dict],
-------
True if data is signed with this Keypair, otherwise False
"""
if isinstance(data, str) and self.seperator in data:
data, signature = data.split(self.seperator)
if isinstance(data, str) and seperator in data:
data, signature = data.split(seperator)

data = c.copy(data)

Expand Down Expand Up @@ -1512,13 +1516,9 @@ def test_str_signing(self):
return {'success':True}

def ticket(self, key=None, **kwargs):
if key != None:
self = c.get_key(key)
data = str(c.timestamp())
return self.sign(data, return_str=True, **kwargs)
return c.module('key.ticket')().create(key=self.key, **kwargs)

def verify_ticket(self, ticket=None, max_age=1, seperator = None, **kwargs):
seperator = seperator or self.seperator
def verify_ticket(self, ticket=None, max_age=1, seperator = "<DATA::SIGNATURE>", **kwargs):
if c.exists(ticket):
ticket = c.get_text(ticket)
data = int(ticket.split(seperator)[0])
Expand Down
29 changes: 29 additions & 0 deletions commune/key/ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import commune as c

class Ticket(c.Module):

seperator='::ticket::'

def create(self, key, seperator=seperator):
timestamp = str(c.time())
key = c.get_key(key)
return key.sign(timestamp, return_str=True, seperator=seperator)

def verify(self, ticket, key, seperator=seperator):
timestamp, signature = ticket.split(seperator)
key = c.get_key(key)
return key.verify(data=timestamp, signature=signature, seperator=seperator)


def test(self):
key = c.get_key('test')
ticket = self.create(key)
c.print(ticket)
assert self.verify(ticket, key, seperator=self.seperator)
return {'ticket': ticket, 'key': str(key)}






Loading

0 comments on commit daf423c

Please sign in to comment.