Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def hex_seed(self):
if hasattr(self, 'seed'):
return libnacl.encode.hex_encode(self.seed)
def hex_pk(self):
if hasattr(self, 'pk'):
return libnacl.encode.hex_encode(self.pk)
def __init__(self, binarykey="", pk=None, hex_vk=None):
if binarykey:
pk, vk = binarykey[:libnacl.crypto_box_SECRETKEYBYTES], binarykey[libnacl.crypto_box_SECRETKEYBYTES: libnacl.crypto_box_SECRETKEYBYTES + libnacl.crypto_sign_SEEDBYTES]
hex_vk = hex_encode(vk)
self.key = libnacl.public.PublicKey(pk)
self.veri = libnacl.sign.Verifier(hex_vk)
def hex_vk(self):
if hasattr(self, 'vk'):
return libnacl.encode.hex_encode(self.vk)
def __init__(self, binarykey="", pk=None, hex_vk=None):
"""
Create a new LibNaCL public key. Optionally load it from a string representation or
using a public key and verification key.
:param binarykey: load the pk from this string (see key_to_bin())
:param pk: the libnacl public key to use in byte format
:param hex_vk: a verification key in hex format
"""
# Load the key, if specified
if binarykey:
pk, vk = (binarykey[:libnacl.crypto_box_SECRETKEYBYTES],
binarykey[libnacl.crypto_box_SECRETKEYBYTES: libnacl.crypto_box_SECRETKEYBYTES
+ libnacl.crypto_sign_SEEDBYTES])
hex_vk = libnacl.encode.hex_encode(vk)
# Construct the public key and verifier objects
self.key = libnacl.public.PublicKey(pk)
self.veri = libnacl.sign.Verifier(hex_vk)
Encode a key.
Arguments:
- `libnacl_key`: An instance of either a
:class:`libnacl.public.SecretKey` or a
:class:`libnacl.public.PublicKey`.
Return the encoded key.
"""
# Detect key type and hexlify
if isinstance(libnacl_key, libnacl.public.SecretKey):
type_ = Key.Type.private
key = libnacl_key.hex_sk()
elif isinstance(libnacl_key, libnacl.public.PublicKey):
type_ = Key.Type.public
key = libnacl.encode.hex_encode(libnacl_key.pk)
else:
raise GatewayKeyError('Unknown key type: {}'.format(libnacl_key))
# Encode key
return Key.separator.join((type_.value, key.decode('utf-8')))
def convert_seed_to_seedhex(seed: bytes) -> str:
"""
Convert seed to seedhex
:param seed: seed
:rtype str:
"""
return hex_encode(seed).decode("utf-8")
def hex_sk(self):
if hasattr(self, 'sk'):
return libnacl.encode.hex_encode(self.sk)
else:
return ''