Add 'construct_policy_id' function to crypto.utils and store active

policies under policy ID
pull/900/head
tuxxy 2019-03-30 09:38:26 -06:00
parent 48150def7d
commit 204ab8d898
3 changed files with 14 additions and 9 deletions

View File

@ -6,6 +6,7 @@ from umbral.keys import UmbralPublicKey
from nucypher.characters.control.specifications import AliceSpecification, BobSpecification, EnricoSpecification
from nucypher.crypto.kits import UmbralMessageKit
from nucypher.crypto.powers import DecryptingPower, SigningPower
from nucypher.crypto.utils import construct_policy_id
from nucypher.network.middleware import NotFound

View File

@ -32,6 +32,14 @@ def fingerprint_from_key(public_key: Any):
return keccak_digest(bytes(public_key)).hex().encode()
def construct_policy_id(label: bytes, stamp: bytes) -> bytes:
"""
Forms an ID unique to the policy per label and Bob's signing pubkey via
a keccak hash of the two.
"""
return keccak_digest(label + stamp)
def canonical_address_from_umbral_key(public_key: UmbralPublicKey) -> bytes:
pubkey_raw_bytes = public_key.to_bytes(is_compressed=False)[1:]
eth_pubkey = EthKeyAPI.PublicKey(pubkey_raw_bytes)

View File

@ -41,9 +41,9 @@ from nucypher.crypto.api import keccak_digest, encrypt_and_sign, secure_random
from nucypher.crypto.constants import PUBLIC_ADDRESS_LENGTH, KECCAK_DIGEST_LENGTH
from nucypher.crypto.kits import UmbralMessageKit, RevocationKit
from nucypher.crypto.powers import SigningPower, DecryptingPower
from nucypher.crypto.signing import Signature, InvalidSignature, signature_splitter
from nucypher.crypto.splitters import capsule_splitter, key_splitter
from nucypher.crypto.utils import canonical_address_from_umbral_key, recover_pubkey_from_signature
from nucypher.crypto.signing import Signature, InvalidSignature
from nucypher.crypto.splitters import key_splitter
from nucypher.crypto.utils import canonical_address_from_umbral_key, recover_pubkey_from_signature, construct_policy_id
from nucypher.network.exceptions import NodeSeemsToBeDown
from nucypher.network.middleware import RestMiddleware, NotFound
@ -165,11 +165,7 @@ class Policy:
@property
def id(self) -> bytes:
"""
Forms an ID unique to the policy per label and Bob via a hash of the
label + bob's encrypting pubkey.
"""
return keccak_digest(self.label + bytes(self.bob.stamp))
return construct_policy_id(self.label, bytes(self.bob.stamp))
def hrac(self) -> bytes:
"""
@ -271,7 +267,7 @@ class Policy:
else: # ...After *all* the policies are enacted
# Create Alice's revocation kit
self.revocation_kit = RevocationKit(self, self.alice.stamp)
self.alice.active_policies[bytes(self.public_key).hex()] = self
self.alice.active_policies[self.id] = self
if publish is True:
return self.publish(network_middleware=network_middleware)