mirror of https://github.com/nucypher/nucypher.git
PublicKey class.
parent
e8cfed52e6
commit
098da6dc21
|
@ -8,7 +8,7 @@ from nkms.crypto import api as API
|
|||
from nkms.crypto.api import secure_random, keccak_digest
|
||||
from nkms.crypto.constants import NOT_SIGNED, NO_DECRYPTION_PERFORMED
|
||||
from nkms.crypto.powers import CryptoPower, SigningPower, EncryptingPower
|
||||
from nkms.keystore.keypairs import Keypair
|
||||
from nkms.keystore.keypairs import Keypair, PublicKey
|
||||
from nkms.network import blockchain_client
|
||||
from nkms.network.blockchain_client import list_all_ursulas
|
||||
from nkms.network.protocols import dht_value_splitter
|
||||
|
@ -175,7 +175,7 @@ class Alice(Character):
|
|||
:return: Tuple(kfrags, eph_key_data)
|
||||
"""
|
||||
kfrags, eph_key_data = API.ecies_ephemeral_split_rekey(
|
||||
alice_privkey, bytes(bob.seal), m, n)
|
||||
alice_privkey, bytes(bob.seal.without_metabytes()), m, n)
|
||||
return (kfrags, eph_key_data)
|
||||
|
||||
def publish_treasure_map(self, policy_group):
|
||||
|
@ -331,6 +331,9 @@ class Seal(object):
|
|||
def __len__(self):
|
||||
return len(bytes(self))
|
||||
|
||||
def without_metabytes(self):
|
||||
return self.character._crypto_power.pubkey_sig_bytes().without_metabytes()
|
||||
|
||||
|
||||
class StrangerSeal(Seal):
|
||||
"""
|
||||
|
|
|
@ -154,7 +154,7 @@ class SigningKeypair(Keypair):
|
|||
self._gen_pubkey()
|
||||
|
||||
def _gen_pubkey(self):
|
||||
self.pubkey = API.ecdsa_priv2pub(self.privkey)
|
||||
self.pubkey = PublicKey(API.ecdsa_priv2pub(self.privkey))
|
||||
|
||||
def sign(self, msghash: bytes) -> bytes:
|
||||
"""
|
||||
|
@ -177,7 +177,7 @@ class SigningKeypair(Keypair):
|
|||
:return: Boolean if the signature is valid
|
||||
"""
|
||||
v, r, s = API.ecdsa_load_sig(signature)
|
||||
return API.ecdsa_verify(v, r, s, msghash, self.pubkey)
|
||||
return API.ecdsa_verify(v, r, s, msghash, self.pubkey.without_metabytes())
|
||||
|
||||
def serialize_pubkey(self) -> bytes:
|
||||
"""
|
||||
|
@ -200,3 +200,11 @@ class SigningKeypair(Keypair):
|
|||
constants.PRIV_KEY_BYTE +
|
||||
self.privkey)
|
||||
return serialized_key
|
||||
|
||||
|
||||
class PublicKey(bytes):
|
||||
_EXPECTED_LENGTH = 66
|
||||
_METABYTES_LENGTH = 2
|
||||
|
||||
def without_metabytes(self):
|
||||
return self[self._METABYTES_LENGTH::]
|
Loading…
Reference in New Issue