mirror of https://github.com/nucypher/nucypher.git
Updates for umbral 0.3 API
parent
e71a6955c5
commit
55ef631673
|
@ -29,8 +29,8 @@ def generate_doctor_keys():
|
|||
sig_privkey = SecretKey.random()
|
||||
|
||||
doctor_privkeys = {
|
||||
'enc': bytes(enc_privkey).hex(),
|
||||
'sig': bytes(sig_privkey).hex(),
|
||||
'enc': enc_privkey.to_secret_bytes().hex(),
|
||||
'sig': sig_privkey.to_secret_bytes().hex(),
|
||||
}
|
||||
|
||||
with open(DOCTOR_PRIVATE_JSON, 'w') as f:
|
||||
|
|
|
@ -451,7 +451,7 @@ class Character(Learner):
|
|||
|
||||
signature_to_use = signature or signature_from_kit
|
||||
if signature_to_use:
|
||||
is_valid = signature_to_use.verify(message=message, verifying_key=sender_verifying_key)
|
||||
is_valid = signature_to_use.verify(message=message, verifying_pk=sender_verifying_key)
|
||||
if not is_valid:
|
||||
try:
|
||||
node_on_the_other_end = self.known_node_class.from_seednode_metadata(stranger.seed_node_metadata(),
|
||||
|
|
|
@ -50,11 +50,7 @@ from nucypher.crypto.powers import (
|
|||
TLSHostingPower,
|
||||
)
|
||||
from nucypher.crypto.tls import generate_self_signed_certificate
|
||||
from nucypher.crypto.umbral_adapter import (
|
||||
SecretKey,
|
||||
secret_key_factory_from_seed,
|
||||
secret_key_factory_from_secret_key_factory
|
||||
)
|
||||
from nucypher.crypto.umbral_adapter import SecretKey, SecretKeyFactory
|
||||
|
||||
# HKDF
|
||||
__INFO_BASE = b'NuCypher/'
|
||||
|
@ -284,8 +280,8 @@ class Keystore:
|
|||
raise InvalidPassword(''.join(failures))
|
||||
|
||||
# Derive verifying key (for use as ID)
|
||||
verifying_key = secret_key_factory_from_seed(secret).secret_key_by_label(_SIGNING_INFO)
|
||||
keystore_id = bytes(verifying_key.public_key()).hex()[:Keystore._ID_SIZE]
|
||||
signing_key = SecretKeyFactory.from_secure_randomness(secret).make_key(_SIGNING_INFO)
|
||||
keystore_id = bytes(signing_key.public_key()).hex()[:Keystore._ID_SIZE]
|
||||
|
||||
# Generate paths
|
||||
keystore_dir = keystore_dir or Keystore._DEFAULT_DIR
|
||||
|
@ -406,7 +402,7 @@ class Keystore:
|
|||
failure_message = f"{power_class.__name__} is an invalid type for deriving a CryptoPower"
|
||||
raise TypeError(failure_message)
|
||||
else:
|
||||
__private_key = secret_key_factory_from_seed(self.__secret).secret_key_by_label(info)
|
||||
__private_key = SecretKeyFactory.from_secure_randomness(self.__secret).make_key(info)
|
||||
|
||||
if power_class is TLSHostingPower: # TODO: something more elegant?
|
||||
power = _derive_hosting_power(private_key=__private_key, *power_args, **power_kwargs)
|
||||
|
@ -416,8 +412,8 @@ class Keystore:
|
|||
power = power_class(keypair=keypair, *power_args, **power_kwargs)
|
||||
|
||||
elif issubclass(power_class, DerivedKeyBasedPower):
|
||||
parent_skf = secret_key_factory_from_seed(self.__secret)
|
||||
child_skf = secret_key_factory_from_secret_key_factory(parent_skf, label=_DELEGATING_INFO)
|
||||
parent_skf = SecretKeyFactory.from_secure_randomness(self.__secret)
|
||||
child_skf = parent_skf.make_factory(_DELEGATING_INFO)
|
||||
power = power_class(secret_key_factory=child_skf, *power_args, **power_kwargs)
|
||||
|
||||
else:
|
||||
|
|
|
@ -252,7 +252,7 @@ class DelegatingPower(DerivedKeyBasedPower):
|
|||
self.__secret_key_factory = secret_key_factory
|
||||
|
||||
def _get_privkey_from_label(self, label):
|
||||
return self.__secret_key_factory.secret_key_by_label(label)
|
||||
return self.__secret_key_factory.make_key(label)
|
||||
|
||||
def get_pubkey_from_label(self, label):
|
||||
return self._get_privkey_from_label(label).public_key()
|
||||
|
@ -278,7 +278,7 @@ class DelegatingPower(DerivedKeyBasedPower):
|
|||
kfrags = generate_kfrags(delegating_sk=__private_key,
|
||||
receiving_pk=bob_pubkey_enc,
|
||||
threshold=threshold,
|
||||
num_kfrags=shares,
|
||||
shares=shares,
|
||||
signer=signer,
|
||||
sign_delegating_key=False,
|
||||
sign_receiving_key=False,
|
||||
|
|
|
@ -67,7 +67,7 @@ def generate_self_signed_certificate(host: str,
|
|||
) -> Tuple[Certificate, _EllipticCurvePrivateKey]:
|
||||
|
||||
if private_key:
|
||||
private_bn = int.from_bytes(bytes(private_key), 'big')
|
||||
private_bn = int.from_bytes(private_key.to_secret_bytes(), 'big')
|
||||
private_key = ec.derive_private_key(private_value=private_bn, curve=curve())
|
||||
else:
|
||||
private_key = ec.generate_private_key(curve(), default_backend())
|
||||
|
|
|
@ -37,18 +37,3 @@ from umbral import (
|
|||
reencrypt,
|
||||
decrypt_reencrypted,
|
||||
)
|
||||
|
||||
|
||||
def secret_key_factory_from_seed(entropy: bytes) -> SecretKeyFactory:
|
||||
"""TODO: Issue #57 in nucypher/rust-umbral"""
|
||||
if len(entropy) < 32:
|
||||
raise ValueError('Entropy must be at least 32 bytes.')
|
||||
material = entropy.zfill(SecretKeyFactory.serialized_size())
|
||||
instance = SecretKeyFactory.from_bytes(material)
|
||||
return instance
|
||||
|
||||
|
||||
def secret_key_factory_from_secret_key_factory(skf: SecretKeyFactory, label: bytes) -> SecretKeyFactory:
|
||||
"""TODO: Issue #59 in nucypher/rust-umbral"""
|
||||
secret_key = bytes(skf.secret_key_by_label(label)).zfill(SecretKeyFactory.serialized_size())
|
||||
return SecretKeyFactory.from_bytes(secret_key)
|
||||
|
|
|
@ -203,7 +203,7 @@ def test_verify_eip191(testerchain, signature_verifier):
|
|||
# Produce EIP191 signature (version E)
|
||||
signable_message = encode_defunct(primitive=message)
|
||||
signature = Account.sign_message(signable_message=signable_message,
|
||||
private_key=bytes(umbral_privkey))
|
||||
private_key=umbral_privkey.to_secret_bytes())
|
||||
signature = bytes(signature.signature)
|
||||
|
||||
# Off-chain verify, just in case
|
||||
|
@ -244,7 +244,7 @@ def test_verify_eip191(testerchain, signature_verifier):
|
|||
header=HexBytes(validator),
|
||||
body=HexBytes(message))
|
||||
signature = Account.sign_message(signable_message=signable_message,
|
||||
private_key=bytes(umbral_privkey))
|
||||
private_key=umbral_privkey.to_secret_bytes())
|
||||
signature = bytes(signature.signature)
|
||||
|
||||
# Off-chain verify, just in case
|
||||
|
|
|
@ -40,7 +40,7 @@ def fragments():
|
|||
signer=signer,
|
||||
receiving_pk=pub_key_bob,
|
||||
threshold=2,
|
||||
num_kfrags=4,
|
||||
shares=4,
|
||||
sign_delegating_key=False,
|
||||
sign_receiving_key=False)
|
||||
|
||||
|
|
|
@ -41,11 +41,7 @@ from nucypher.crypto.keystore import (
|
|||
_read_keystore
|
||||
)
|
||||
from nucypher.crypto.powers import DecryptingPower, SigningPower, DelegatingPower, TLSHostingPower
|
||||
from nucypher.crypto.umbral_adapter import SecretKey
|
||||
from nucypher.crypto.umbral_adapter import (
|
||||
secret_key_factory_from_seed,
|
||||
secret_key_factory_from_secret_key_factory
|
||||
)
|
||||
from nucypher.crypto.umbral_adapter import SecretKey, SecretKeyFactory
|
||||
from nucypher.utilities.networking import LOOPBACK_ADDRESS
|
||||
from tests.constants import INSECURE_DEVELOPMENT_PASSWORD
|
||||
|
||||
|
@ -295,9 +291,9 @@ def test_derive_delegating_power(tmpdir):
|
|||
keystore = Keystore.generate(INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=tmpdir)
|
||||
keystore.unlock(password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
delegating_power = keystore.derive_crypto_power(power_class=DelegatingPower)
|
||||
parent_skf = secret_key_factory_from_seed(keystore._Keystore__secret)
|
||||
child_skf = secret_key_factory_from_secret_key_factory(skf=parent_skf, label=_DELEGATING_INFO)
|
||||
assert bytes(delegating_power._DelegatingPower__secret_key_factory) == bytes(child_skf)
|
||||
parent_skf = SecretKeyFactory.from_secure_randomness(keystore._Keystore__secret)
|
||||
child_skf = parent_skf.make_factory(_DELEGATING_INFO)
|
||||
assert delegating_power._DelegatingPower__secret_key_factory.to_secret_bytes() == child_skf.to_secret_bytes()
|
||||
assert delegating_power._get_privkey_from_label(label=b'some-label')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue