2020-11-21 14:38:38 +00:00
|
|
|
import base64
|
2023-02-05 16:30:58 +00:00
|
|
|
|
2020-11-21 11:04:31 +00:00
|
|
|
from nacl.encoding import Base64Encoder
|
2023-02-05 16:30:58 +00:00
|
|
|
from nacl.public import PrivateKey
|
|
|
|
|
2020-11-21 11:04:31 +00:00
|
|
|
from bundlewrap.utils import Fault
|
|
|
|
|
2023-02-05 16:30:58 +00:00
|
|
|
|
2020-11-21 14:38:38 +00:00
|
|
|
def gen_privkey(repo, identifier):
|
2020-11-21 11:04:31 +00:00
|
|
|
return repo.vault.random_bytes_as_base64_for(identifier)
|
|
|
|
|
2020-11-21 14:38:38 +00:00
|
|
|
def get_pubkey_from_privkey(repo, identifier, privkey):
|
2020-11-21 11:04:31 +00:00
|
|
|
# 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)
|