WOT API can now serialize identities

This commit is contained in:
Kevin F 2022-12-02 21:42:11 +00:00
parent 738fa0c361
commit 8e730cef98
3 changed files with 10 additions and 3 deletions

View File

@ -99,6 +99,8 @@ def on_init(api, data=None):
return return
logging.info('Loaded active identity: ' + iden.name) logging.info('Loaded active identity: ' + iden.name)
identities.add(iden)
def on_wot_cmd(api, data=None): def on_wot_cmd(api, data=None):
def _create_new_iden(): def _create_new_iden():

View File

@ -1,3 +1,5 @@
import base64
class IdentitySet(set): class IdentitySet(set):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -32,7 +34,7 @@ identities = IdentitySet()
def serialize_identity_set(): def serialize_identity_set():
serialized_idens = [] serialized_idens = []
for identity in list(identities): for identity in list(identities):
serialized_idens.append(identity.serialize()) serialized_idens.append(base64.b85encode(identity.serialize()).decode('utf-8'))
return serialized_idens return serialized_idens
serialize_identity_set.json_compatible = True serialize_identity_set.json_compatible = True

View File

@ -1,15 +1,18 @@
import base64 import base64
import keyring import keyring
import nacl.signing
import wot.identity import wot.identity
def get_identity_by_name(name: str) -> 'Identity': def get_identity_by_name(name: str) -> 'Identity':
iden_key = keyring.get_credential('onionr.wot', name) iden_key = keyring.get_credential('onionr.wot', name)
iden_key = base64.b85decode(iden_key)
if not iden_key: if not iden_key:
raise KeyError('Identity not found') raise KeyError('Identity not found')
iden_key = base64.b85decode(iden_key.password)
iden_key = nacl.signing.SigningKey(iden_key)
return wot.identity.Identity(iden_key, name) return wot.identity.Identity(iden_key, name)