Example #1
0
    def create_policy(self,
                      bob: "Bob",
                      label: bytes,
                      m: int,
                      n: int,
                      federated=False):
        """
        Create a Policy to share uri with bob.
        Generates KFrags and attaches them.
        """
        public_key, kfrags = self.generate_kfrags(bob, label, m, n)

        payload = dict(label=label,
                       bob=bob,
                       kfrags=kfrags,
                       public_key=public_key,
                       m=m)

        if self.federated_only is True or federated is True:
            from nucypher.policy.models import FederatedPolicy
            # We can't sample; we can only use known nodes.
            known_nodes = self.known_nodes.shuffled()
            policy = FederatedPolicy(alice=self,
                                     ursulas=known_nodes,
                                     **payload)
        else:
            from nucypher.blockchain.eth.policies import BlockchainPolicy
            policy = BlockchainPolicy(author=self, **payload)

        return policy
Example #2
0
    def create_policy(self, *args, **kwargs):
        """
        Hence the name, a PolicyAuthor can create
        a BlockchainPolicy with themself as the author.

        :return: Returns a newly authored BlockchainPolicy with n proposed arrangements.

        """
        from nucypher.blockchain.eth.policies import BlockchainPolicy
        blockchain_policy = BlockchainPolicy(alice=self, *args, **kwargs)
        return blockchain_policy
Example #3
0
    def create_policy(self,
                      bob: "Bob",
                      label: bytes,
                      m: int,
                      n: int,
                      federated: bool = False,
                      expiration: maya.MayaDT = None,
                      value: int = None,
                      handpicked_ursulas: set = None):
        """
        Create a Policy to share uri with bob.
        Generates KFrags and attaches them.
        """

        # Validate early
        if not federated and not (expiration and value):
            raise ValueError("expiration and value are required arguments when creating a blockchain policy")

        # Generate KFrags
        public_key, kfrags = self.generate_kfrags(bob, label, m, n)

        # Federated Payload
        payload = dict(label=label,
                       bob=bob,
                       kfrags=kfrags,
                       public_key=public_key,
                       m=m)

        if self.federated_only is True or federated is True:
            # Use known nodes.

            from nucypher.policy.models import FederatedPolicy
            known_nodes = self.known_nodes.shuffled()
            policy = FederatedPolicy(alice=self, ursulas=known_nodes, **payload)

        else:
            # Sample from blockchain via PolicyManager

            blockchain_payload = dict(expiration=expiration,
                                      value=value,
                                      handpicked_ursulas=handpicked_ursulas)

            payload.update(blockchain_payload)

            from nucypher.blockchain.eth.policies import BlockchainPolicy
            policy = BlockchainPolicy(alice=self, **payload)

        return policy