libs/keys: add gen_privkey() and get_pubkey_from_privkey()
All checks were successful
bundlewrap/pipeline/head This commit looks good
All checks were successful
bundlewrap/pipeline/head This commit looks good
This commit is contained in:
parent
70513c47fa
commit
4557ce2538
2 changed files with 15 additions and 0 deletions
14
libs/keys.py
Normal file
14
libs/keys.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from nacl.public import PrivateKey
|
||||
from nacl.encoding import Base64Encoder
|
||||
from bundlewrap.utils import Fault
|
||||
|
||||
def gen_privkey(identifier):
|
||||
return repo.vault.random_bytes_as_base64_for(identifier)
|
||||
|
||||
def get_pubkey_from_privkey(identifier, privkey):
|
||||
# FIXME this assumes the privkey is always a base64 encoded string
|
||||
def derive_pubkey():
|
||||
pub_key = PrivateKey(base64.b64decode(str(privkey))).public_key
|
||||
return pub_key.encode(encoder=Base64Encoder).decode('ascii')
|
||||
|
||||
return Fault(f'pubkey from privkey {identifier}', derive_pubkey)
|
|
@ -1 +1,2 @@
|
|||
bundlewrap>=4.2.0
|
||||
PyNaCl
|
||||
|
|
Loading…
Reference in a new issue