nucypher.policy

Submodules

class Card(character_flag: Union[ALICE(b’?\xba\x93\xd8V\xb4G\x95’), BOB(b’\xfd(1@\x11\x98k\xd4’)], verifying_key: Union[umbral.keys.PublicKey, bytes], encrypting_key: Union[umbral.keys.PublicKey, bytes, None] = None, nickname: Union[bytes, str, None] = None)

Bases: object

” A simple serializable representation of a character’s public materials.

TRUNCATE = 16
CARD_DIR = PosixPath('/home/docs/.local/share/nucypher/cards')
exception InvalidCard

Bases: Exception

Raised when an invalid, corrupted, or otherwise unsable card is encountered

exception UnknownCard

Bases: Exception

Raised when a card cannot be found in storage

exception UnsignedCard

Bases: Exception

Raised when a card serialization cannot be handled due to the lack of a signature

property character
classmethod from_bytes(card_bytes: bytes)nucypher.policy.identity.Card
classmethod from_hex(hexdata: str)
to_hex()str
classmethod from_base64(b64data: str)
to_base64()str
to_qr_code()
classmethod from_dict(card: Dict)
to_dict() → Dict
describe(truncate: int = 16) → Dict
to_json(as_string: bool = True) → Union[dict, str]
classmethod from_character(character: nucypher.characters.base.Character, nickname: Optional[str] = None)nucypher.policy.identity.Card
property verifying_key
property encrypting_key
property id
set_nickname(nickname: str)None
property nickname
property filepath
property is_saved
save(encoder: Callable = <function b64encode>, overwrite: bool = False)pathlib.Path
classmethod lookup(identifier: str, card_dir: Optional[pathlib.Path] = PosixPath('/home/docs/.local/share/nucypher/cards'))pathlib.Path

Resolve a card ID or nickname into a Path object

classmethod load(filepath: Optional[pathlib.Path] = None, identifier: str = None, card_dir: Optional[pathlib.Path] = None, decoder: Callable = <function b64decode>)nucypher.policy.identity.Card
delete()None
class PolicyMessageKit(policy_key: umbral.keys.PublicKey, threshold: int, result: nucypher.policy.kits.RetrievalResult, message_kit: nucypher.core.MessageKit)

Bases: object

classmethod from_message_kit(message_kit: nucypher.core.MessageKit, policy_key: umbral.keys.PublicKey, threshold: int)nucypher.policy.kits.PolicyMessageKit
as_retrieval_kit()nucypher.core.RetrievalKit
decrypt(sk: umbral.keys.SecretKey)bytes
property capsule
property ciphertext
property sender_verifying_key
is_decryptable_by_receiver()bool
with_result(result: nucypher.policy.kits.RetrievalResult)nucypher.policy.kits.PolicyMessageKit
class RetrievalResult(cfrags: Dict[NewType.<locals>.new_type, umbral.capsule_frag.VerifiedCapsuleFrag])

Bases: object

An object representing retrieval results for a single capsule.

classmethod empty()
addresses() → Set[NewType.<locals>.new_type]
with_result(result: nucypher.policy.kits.RetrievalResult)nucypher.policy.kits.RetrievalResult

Joins two RetrievalResult objects.

If both objects contain cfrags from the same Ursula, the one from result will be kept.

class Policy(publisher: Alice, label: bytes, expiration: maya.core.MayaDT, bob: Bob, kfrags: Sequence[umbral.key_frag.VerifiedKeyFrag], public_key: umbral.keys.PublicKey, threshold: int)

Bases: abc.ABC

An edict by Alice, arranged with n Ursulas, to perform re-encryption for a specific Bob.

log

Drop-in replacement of Twisted’s Logger, patching the emit() method to tolerate inputs with curly braces, i.e., not compliant with PEP 3101.

See Issue #724 and, particularly, https://github.com/nucypher/nucypher/issues/724#issuecomment-600190455

exception PolicyException

Bases: Exception

Base exception for policy exceptions

exception NotEnoughUrsulas

Bases: nucypher.policy.policies.Policy.PolicyException

Raised when a Policy has been used to generate Arrangements with Ursulas insufficient number such that we don’t have enough KeyFrags to give to each Ursula.

exception EnactmentError

Bases: nucypher.policy.policies.Policy.PolicyException

Raised if one or more Ursulas failed to enact the policy.

exception Unpaid

Bases: nucypher.policy.policies.Policy.PolicyException

Raised when a worker expects policy payment but receives none.

exception Unknown

Bases: nucypher.policy.policies.Policy.PolicyException

Raised when a worker cannot find a published policy for a given policy ID

exception Inactive

Bases: nucypher.policy.policies.Policy.PolicyException

Raised when a worker is requested to perform re-encryption for a disabled policy

exception Expired

Bases: nucypher.policy.policies.Policy.PolicyException

Raised when a worker is requested to perform re-encryption for an expired policy

exception Unauthorized

Bases: nucypher.policy.policies.Policy.PolicyException

Raised when Bob is not authorized to request re-encryptions from Ursula..

exception Revoked

Bases: nucypher.policy.policies.Policy.Unauthorized

Raised when a policy is revoked has been revoked access

expiration = None

#180 - This attribute is hanging on for dear life. After 180 is closed, it can be completely deprecated.

The “hashed resource authentication code”.

A hash of: * Alice’s public key * Bob’s public key * the label

Alice and Bob have all the information they need to construct this. ‘Ursula’ does not, so we share it with her.

Type

# TODO

enact(network_middleware: nucypher.network.middleware.RestMiddleware, handpicked_ursulas: Optional[Iterable[Ursula]] = None) → EnactedPolicy

Attempts to enact the policy, returns an EnactedPolicy object on success.

class FederatedPolicy(publisher: Alice, label: bytes, expiration: maya.core.MayaDT, bob: Bob, kfrags: Sequence[umbral.key_frag.VerifiedKeyFrag], public_key: umbral.keys.PublicKey, threshold: int)

Bases: nucypher.policy.policies.Policy

class BlockchainPolicy(value: int, rate: int, payment_periods: int, *args, **kwargs)

Bases: nucypher.policy.policies.Policy

A collection of n Arrangements representing a single Policy

exception InvalidPolicyValue

Bases: ValueError

exception NotEnoughBlockchainUrsulas

Bases: nucypher.policy.policies.Policy.NotEnoughUrsulas

static generate_policy_parameters(shares: int, payment_periods: int, value: int = None, rate: int = None)dict
class EnactedPolicy(hrac: nucypher.core.HRAC, label: bytes, public_key: umbral.keys.PublicKey, threshold: int, treasure_map: EncryptedTreasureMap, revocation_kit: nucypher.policy.revocation.RevocationKit, publisher_verifying_key: umbral.keys.PublicKey)

Bases: object

make_federated_staker_reservoir(known_nodes: nucypher.acumen.perception.FleetSensor, exclude_addresses: Optional[Iterable[NewType.<locals>.new_type]] = None, include_addresses: Optional[Iterable[NewType.<locals>.new_type]] = None)

Get a sampler object containing the federated stakers.

make_decentralized_staker_reservoir(staking_agent: nucypher.blockchain.eth.agents.StakingEscrowAgent, duration_periods: int, exclude_addresses: Optional[Iterable[NewType.<locals>.new_type]] = None, include_addresses: Optional[Iterable[NewType.<locals>.new_type]] = None, pagination_size: int = None)

Get a sampler object containing the currently registered stakers.

class MergedReservoir(values: Iterable, reservoir: nucypher.blockchain.eth.agents.StakersReservoir)

Bases: object

A reservoir made of a list of addresses and a StakersReservoir. Draws the values from the list first, then from StakersReservoir, then returns None on subsequent calls.

class PrefetchStrategy(reservoir: nucypher.policy.reservoir.MergedReservoir, need_successes: int)

Bases: object

Encapsulates the batch draw strategy from a reservoir. Determines how many values to draw based on the number of values that have already led to successes.

class RevocationKit(treasure_map, signer: nucypher.crypto.signing.SignatureStamp)

Bases: object

property revokable_addresses

Returns a Set of revokable addresses in the checksum address formatting

add_confirmation(node_id, signed_receipt)

Adds a signed confirmation of Ursula’s ability to revoke the arrangement.