From 8e730cef981a9f842a2bcfcb8ebb7c173c5adc92 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Fri, 2 Dec 2022 21:42:11 +0000 Subject: [PATCH] WOT API can now serialize identities --- static-data/official-plugins/wot/main.py | 2 ++ .../official-plugins/wot/wot/identity/identityset.py | 4 +++- .../official-plugins/wot/wot/wotkeyring/__init__.py | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/static-data/official-plugins/wot/main.py b/static-data/official-plugins/wot/main.py index c5e0faed..26011361 100644 --- a/static-data/official-plugins/wot/main.py +++ b/static-data/official-plugins/wot/main.py @@ -99,6 +99,8 @@ def on_init(api, data=None): return logging.info('Loaded active identity: ' + iden.name) + identities.add(iden) + def on_wot_cmd(api, data=None): def _create_new_iden(): diff --git a/static-data/official-plugins/wot/wot/identity/identityset.py b/static-data/official-plugins/wot/wot/identity/identityset.py index b2a1cf45..7bd3c8d5 100644 --- a/static-data/official-plugins/wot/wot/identity/identityset.py +++ b/static-data/official-plugins/wot/wot/identity/identityset.py @@ -1,3 +1,5 @@ +import base64 + class IdentitySet(set): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -32,7 +34,7 @@ identities = IdentitySet() def serialize_identity_set(): serialized_idens = [] for identity in list(identities): - serialized_idens.append(identity.serialize()) + serialized_idens.append(base64.b85encode(identity.serialize()).decode('utf-8')) return serialized_idens serialize_identity_set.json_compatible = True \ No newline at end of file diff --git a/static-data/official-plugins/wot/wot/wotkeyring/__init__.py b/static-data/official-plugins/wot/wot/wotkeyring/__init__.py index 7177d7eb..a4483839 100644 --- a/static-data/official-plugins/wot/wot/wotkeyring/__init__.py +++ b/static-data/official-plugins/wot/wot/wotkeyring/__init__.py @@ -1,15 +1,18 @@ import base64 + import keyring +import nacl.signing import wot.identity def get_identity_by_name(name: str) -> 'Identity': iden_key = keyring.get_credential('onionr.wot', name) - iden_key = base64.b85decode(iden_key) - if not iden_key: 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)