Skip to content

Commit

Permalink
added keystore that supports encryption so nsecs are no longer kept i…
Browse files Browse the repository at this point in the history
…n cleartext - this replaces alias.py which will be removed
  • Loading branch information
monty committed Jun 4, 2024
1 parent 66ee763 commit 3d44f86
Show file tree
Hide file tree
Showing 3 changed files with 431 additions and 2 deletions.
62 changes: 62 additions & 0 deletions my_scratch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import asyncio
import logging
from hashlib import sha256
from monstr.ident.keystore import NamedKeys, FileKeyStore, KeyDataEncrypter, SQLiteKeyStore
from monstr.ident.persist import MemoryProfileStore
from monstr.ident.profile import Profile

# logging.getLogger().setLevel(logging.DEBUG)


async def convert_store():
# load the old data as alias stores it
old_file = '/home/monty/.nostrpy/profiles.csv'

# create a new key store and copy name/key maps in
new_file = '/home/monty/.nostrpy/keystore.db'


async def get_key() -> str:
# will block, use aiconsole where it matters
return input('keystore key: ')

my_enc = KeyDataEncrypter(get_key=get_key)
new_store = SQLiteKeyStore(new_file,
encrypter=my_enc)

await new_store.convert_memstore(old_file)



async def test_store():
# create a new key store and copy name/key maps in
new_file = '/home/monty/.nostrpy/keystore.db'
async def get_key() -> str:
# will block, use aiconsole where it matters
return input('keystore key: ')

my_enc = KeyDataEncrypter(get_key=get_key)

new_store = SQLiteKeyStore(new_file,
encrypter=my_enc)

await new_store.add(NamedKeys('moobs'))

# print(await new_store.get('monty_test'))
#
# from monstr.encrypt import Keys
# await new_store.update(Keys(), 'monty_test')

asyncio.run(convert_store())



# nk = NamedKeys('shaun')
#
# print(nk)
#
# my_store = FileKeyStore('/home/monty/.nostrpy/profiles.csv')
# print(my_store.get('che'))
#
# k = NamedKeys(name='c')
# my_store.update(k)
4 changes: 2 additions & 2 deletions src/monstr/ident/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class ProfileFileAlias:
"""
in a file contains mappings between human usable alias and key pairs
so we don't always have to type out full keys
TODO: to be removed - replaced by keystore
use keystore.convert_memstore(old_filename) to update
"""
def __init__(self, file_name: str):
self._file_name = file_name
Expand Down
Loading

0 comments on commit 3d44f86

Please sign in to comment.