mirror of https://github.com/nucypher/nucypher.git
Merge pull request #2774 from fjarri/threshold-renaming
Rename `m` to `threshold` and `n` to `shares`pull/2742/head
commit
f50b743a64
|
@ -57,7 +57,7 @@ Alice Grants Access To Secret
|
|||
> --bob-encrypting-key 0202a6be8e400acdd50db42f8b4c62241b61461a08462731efc064b86d63c7cf6f \
|
||||
> --label <LABEL> \
|
||||
> --expiration 2019-12-20T10:07:50Z \
|
||||
> --m 1 --n 1 --value 1 --debug
|
||||
> -m 1 -n 1 --value 1 --debug
|
||||
|
||||
Output:
|
||||
|
||||
|
|
|
@ -230,8 +230,8 @@ Alice can grant access to Bob using his public keys:
|
|||
policy = alice.grant(
|
||||
bob,
|
||||
label=b'my-secret-stuff', # Send to Bob via side channel
|
||||
m=2, # Threshold shares for access
|
||||
n=3, # Total nodes with shares
|
||||
threshold=2, # Threshold shares for access
|
||||
shares=3, # Total nodes with shares
|
||||
rate=Web3.toWei(50, 'gwei'), # 50 Gwei is the minimum rate (per node per period)
|
||||
expiration= maya.now() + timedelta(days=5) # Five days from now
|
||||
)
|
||||
|
@ -281,8 +281,8 @@ software wallet and an existing keystore:
|
|||
policy = alice.grant(
|
||||
bob,
|
||||
label=b'my-secret-stuff', # Send to Bob via side channel
|
||||
m=2, # Threshold shares for access
|
||||
n=3, # Total nodes with shares
|
||||
threshold=2, # Threshold shares for access
|
||||
shares=3, # Total nodes with shares
|
||||
rate=Web3.toWei(50, 'gwei'), # 50 Gwei is the minimum rate (per node per period)
|
||||
expiration= maya.now() + timedelta(days=5) # Five days from now
|
||||
)
|
||||
|
|
|
@ -63,8 +63,8 @@ The character control API uses JSON for all its endpoints. A request may look li
|
|||
'bob_verifying_key': '02ce770f45fecbbee0630129cce0da4fffc0c4276093bdb3f83ecf1ed824e2696c',
|
||||
'bob_encrypting_key': '0324df67664e6ea40f2eea8037c994debd4caa42117fe86cdb8cab6ac7728751ad',
|
||||
'label': 'spın̈al-tap-covers',
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'threshold': 2,
|
||||
'shares': 3,
|
||||
'expiration': '2019-02-14T22:23:10.771093Z',
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ ursula = Ursula.from_seed_and_stake_info(seed_uri=SEEDNODE_URI, federated_only=T
|
|||
|
||||
# Here are our Policy details.
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=1)
|
||||
m, n = 2, 3
|
||||
threshold, shares = 2, 3
|
||||
label = b"secret/files/and/stuff"
|
||||
|
||||
|
||||
|
@ -90,7 +90,7 @@ policy_public_key = alice.get_policy_encrypting_key_from_label(label)
|
|||
|
||||
# Alice grant access to Bob. She already knows Bob's public keys from a side-channel.
|
||||
remote_bob = Bob.from_public_keys(encrypting_key=encrypting_key, verifying_key=verifying_key)
|
||||
policy = alice.grant(remote_bob, label, m=m, n=n, expiration=policy_end_datetime)
|
||||
policy = alice.grant(remote_bob, label, threshold=threshold, shares=shares, expiration=policy_end_datetime)
|
||||
|
||||
assert policy.public_key == policy_public_key
|
||||
policy.treasure_map_publisher.block_until_complete()
|
||||
|
|
|
@ -111,10 +111,10 @@ remote_bob = Bob.from_public_keys(encrypting_key=encrypting_key, verifying_key=v
|
|||
# trusting 2 of 3 nodes paying each of them 50 gwei per period.
|
||||
expiration = maya.now() + datetime.timedelta(days=1)
|
||||
rate = Web3.toWei(50, 'gwei')
|
||||
m, n = 2, 3
|
||||
threshold, shares = 2, 3
|
||||
|
||||
# Alice grants access to Bob...
|
||||
alice.grant(remote_bob, label, m=m, n=n, rate=rate, expiration=expiration)
|
||||
alice.grant(remote_bob, label, threshold=threshold, shares=shares, rate=rate, expiration=expiration)
|
||||
|
||||
# ...and then disappears from the internet.
|
||||
#
|
||||
|
|
|
@ -131,7 +131,7 @@ doctor_strange = Bob.from_public_keys(verifying_key=doctor_pubkeys['sig'],
|
|||
policy_end_datetime = maya.now() + datetime.timedelta(days=1)
|
||||
# - m-out-of-n: This means Alicia splits the re-encryption key in 5 pieces and
|
||||
# she requires Bob to seek collaboration of at least 3 Ursulas
|
||||
m, n = 2, 3
|
||||
threshold, shares = 2, 3
|
||||
|
||||
|
||||
# With this information, Alicia creates a policy granting access to Bob.
|
||||
|
@ -139,8 +139,8 @@ m, n = 2, 3
|
|||
print("Creating access policy for the Doctor...")
|
||||
policy = alicia.grant(bob=doctor_strange,
|
||||
label=label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=policy_end_datetime)
|
||||
policy.treasure_map_publisher.block_until_complete()
|
||||
print("Done!")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Changed the names of ``m`` and ``n`` parameters to ``threshold`` and ``shares`` throughout the API.
|
|
@ -0,0 +1 @@
|
|||
``m`` and ``n`` parameters can no longer be used in character control and Python API; ``--m`` and ``--n`` are no longer supported by the CLI (``-m`` and ``-n`` still are; the long versions are now ``--threshold`` and ``--shares``)
|
|
@ -1288,7 +1288,7 @@ class BlockchainPolicyAuthor(NucypherTokenActor):
|
|||
payment_periods += 1 # Number of all included periods
|
||||
|
||||
from nucypher.policy.policies import BlockchainPolicy
|
||||
blockchain_payload = BlockchainPolicy.generate_policy_parameters(n=number_of_ursulas,
|
||||
blockchain_payload = BlockchainPolicy.generate_policy_parameters(shares=number_of_ursulas,
|
||||
payment_periods=payment_periods,
|
||||
value=value,
|
||||
rate=rate)
|
||||
|
|
|
@ -43,8 +43,8 @@ class AliceInterface(CharacterPublicInterface):
|
|||
bob_encrypting_key: bytes,
|
||||
bob_verifying_key: bytes,
|
||||
label: bytes,
|
||||
m: int,
|
||||
n: int,
|
||||
threshold: int,
|
||||
shares: int,
|
||||
expiration: maya.MayaDT,
|
||||
value: int = None
|
||||
) -> dict:
|
||||
|
@ -56,8 +56,8 @@ class AliceInterface(CharacterPublicInterface):
|
|||
new_policy = self.implementer.create_policy(
|
||||
bob=bob,
|
||||
label=label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=expiration,
|
||||
value=value
|
||||
)
|
||||
|
@ -75,8 +75,8 @@ class AliceInterface(CharacterPublicInterface):
|
|||
bob_encrypting_key: bytes,
|
||||
bob_verifying_key: bytes,
|
||||
label: bytes,
|
||||
m: int,
|
||||
n: int,
|
||||
threshold: int,
|
||||
shares: int,
|
||||
expiration: maya.MayaDT,
|
||||
value: int = None,
|
||||
rate: int = None,
|
||||
|
@ -88,8 +88,8 @@ class AliceInterface(CharacterPublicInterface):
|
|||
|
||||
new_policy = self.implementer.grant(bob=bob,
|
||||
label=label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
value=value,
|
||||
rate=rate,
|
||||
expiration=expiration)
|
||||
|
@ -117,7 +117,7 @@ class AliceInterface(CharacterPublicInterface):
|
|||
revocation, fail_reason = attempt
|
||||
if fail_reason == RestMiddleware.NotFound:
|
||||
del (failed_revocations[node_id])
|
||||
if len(failed_revocations) <= (policy.n - policy.m + 1):
|
||||
if len(failed_revocations) <= (policy.shares - policy.threshold + 1):
|
||||
del (self.implementer.active_policies[policy_hrac])
|
||||
|
||||
response_data = {'failed_revocations': len(failed_revocations)}
|
||||
|
|
|
@ -42,12 +42,12 @@ class PolicyBaseSchema(BaseSchema):
|
|||
'-bvk',
|
||||
help="Bob's verifying key as a hexadecimal string",
|
||||
type=click.STRING, required=False))
|
||||
m = character_fields.M(
|
||||
threshold = character_fields.Threshold(
|
||||
required=True, load_only=True,
|
||||
click=options.option_m)
|
||||
n = character_fields.N(
|
||||
click=options.option_threshold)
|
||||
shares = character_fields.Shares(
|
||||
required=True, load_only=True,
|
||||
click=options.option_n)
|
||||
click=options.option_shares)
|
||||
expiration = character_fields.DateTime(
|
||||
required=True, load_only=True,
|
||||
click=click.option(
|
||||
|
@ -73,8 +73,8 @@ class PolicyBaseSchema(BaseSchema):
|
|||
@validates_schema
|
||||
def check_valid_n_and_m(self, data, **kwargs):
|
||||
# ensure that n is greater than or equal to m
|
||||
if not (0 < data['m'] <= data['n']):
|
||||
raise InvalidArgumentCombo(f"N and M must satisfy 0 < M ≤ N")
|
||||
if not (0 < data['threshold'] <= data['shares']):
|
||||
raise InvalidArgumentCombo(f"`shares` and `threshold` must satisfy 0 < threshold ≤ shares")
|
||||
|
||||
@validates_schema
|
||||
def check_rate_or_value_not_both(self, data, **kwargs):
|
||||
|
|
|
@ -19,11 +19,11 @@ from nucypher.control.specifications.fields.base import Integer, PositiveInteger
|
|||
from nucypher.cli import types
|
||||
|
||||
|
||||
class M(PositiveInteger):
|
||||
class Threshold(PositiveInteger):
|
||||
pass
|
||||
|
||||
|
||||
class N(PositiveInteger):
|
||||
class Shares(PositiveInteger):
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -132,8 +132,8 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
checksum_address: str = None,
|
||||
|
||||
# M of N
|
||||
m: int = None,
|
||||
n: int = None,
|
||||
threshold: Optional[int] = None,
|
||||
shares: Optional[int] = None,
|
||||
|
||||
# Policy Value
|
||||
rate: int = None,
|
||||
|
@ -157,14 +157,14 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
self.timeout = timeout
|
||||
|
||||
if is_me:
|
||||
self.m = m
|
||||
self.n = n
|
||||
self.threshold = threshold
|
||||
self.shares = shares
|
||||
|
||||
self._policy_queue = Queue()
|
||||
self._policy_queue.put(READY)
|
||||
else:
|
||||
self.m = STRANGER_ALICE
|
||||
self.n = STRANGER_ALICE
|
||||
self.threshold = STRANGER_ALICE
|
||||
self.shares = STRANGER_ALICE
|
||||
|
||||
Character.__init__(self,
|
||||
known_node_class=Ursula,
|
||||
|
@ -218,8 +218,8 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
def generate_kfrags(self,
|
||||
bob: 'Bob',
|
||||
label: bytes,
|
||||
m: int = None,
|
||||
n: int = None
|
||||
threshold: int = None,
|
||||
shares: int = None
|
||||
) -> List:
|
||||
"""
|
||||
Generates re-encryption key frags ("KFrags") and returns them.
|
||||
|
@ -237,8 +237,8 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
policy_key_and_kfrags = delegating_power.generate_kfrags(bob_pubkey_enc=bob_encrypting_key,
|
||||
signer=self.stamp.as_umbral_signer(),
|
||||
label=label,
|
||||
m=m or self.m,
|
||||
n=n or self.n)
|
||||
threshold=threshold or self.threshold,
|
||||
shares=shares or self.shares)
|
||||
return policy_key_and_kfrags
|
||||
|
||||
def create_policy(self, bob: "Bob", label: bytes, **policy_params):
|
||||
|
@ -248,19 +248,19 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
"""
|
||||
|
||||
policy_params = self.generate_policy_parameters(**policy_params)
|
||||
N = policy_params.pop('n')
|
||||
shares = policy_params.pop('shares')
|
||||
|
||||
# Generate KFrags
|
||||
public_key, kfrags = self.generate_kfrags(bob=bob,
|
||||
label=label,
|
||||
m=policy_params['m'],
|
||||
n=N)
|
||||
threshold=policy_params['threshold'],
|
||||
shares=shares)
|
||||
|
||||
payload = dict(label=label,
|
||||
bob=bob,
|
||||
kfrags=kfrags,
|
||||
public_key=public_key,
|
||||
m=policy_params['m'],
|
||||
threshold=policy_params['threshold'],
|
||||
expiration=policy_params['expiration'])
|
||||
|
||||
if self.federated_only:
|
||||
|
@ -276,8 +276,8 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
return policy
|
||||
|
||||
def generate_policy_parameters(self,
|
||||
m: int = None,
|
||||
n: int = None,
|
||||
threshold: int = None,
|
||||
shares: int = None,
|
||||
payment_periods: int = None,
|
||||
expiration: maya.MayaDT = None,
|
||||
*args, **kwargs
|
||||
|
@ -290,9 +290,9 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
raise ValueError("Policy end time must be specified as 'expiration' or 'payment_periods', got neither.")
|
||||
|
||||
# Merge injected and default params.
|
||||
m = m or self.m
|
||||
n = n or self.n
|
||||
base_payload = dict(m=m, n=n, expiration=expiration)
|
||||
threshold = threshold or self.threshold
|
||||
shares = shares or self.shares
|
||||
base_payload = dict(threshold=threshold, shares=shares, expiration=expiration)
|
||||
|
||||
if self.federated_only:
|
||||
if not expiration:
|
||||
|
@ -305,7 +305,7 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
raise ValueError(f'Expiration must be in the future ({expiration} is earlier than blocktime {blocktime}).')
|
||||
|
||||
# Calculate Policy Rate and Value
|
||||
payload = super().generate_policy_parameters(number_of_ursulas=n,
|
||||
payload = super().generate_policy_parameters(number_of_ursulas=shares,
|
||||
payment_periods=payment_periods,
|
||||
expiration=expiration,
|
||||
*args, **kwargs)
|
||||
|
@ -352,8 +352,8 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
#
|
||||
|
||||
# If we're federated only, we need to block to make sure we have enough nodes.
|
||||
if self.federated_only and len(self.known_nodes) < policy.n:
|
||||
good_to_go = self.block_until_number_of_known_nodes_is(number_of_nodes_to_know=policy.n,
|
||||
if self.federated_only and len(self.known_nodes) < policy.shares:
|
||||
good_to_go = self.block_until_number_of_known_nodes_is(number_of_nodes_to_know=policy.shares,
|
||||
learn_on_this_thread=True,
|
||||
timeout=timeout)
|
||||
if not good_to_go:
|
||||
|
@ -361,7 +361,7 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
"To make a Policy in federated mode, you need to know about "
|
||||
"all the Ursulas you need (in this case, {}); there's no other way to "
|
||||
"know which nodes to use. Either pass them here or when you make the Policy, "
|
||||
"or run the learning loop on a network with enough Ursulas.".format(policy.n))
|
||||
"or run the learning loop on a network with enough Ursulas.".format(policy.shares))
|
||||
|
||||
self.log.debug(f"Enacting {policy} ... ")
|
||||
# TODO: Make it optional to publish to blockchain? Or is this presumptive based on the `Policy` type?
|
||||
|
@ -404,10 +404,10 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
"""
|
||||
try:
|
||||
# Wait for a revocation threshold of nodes to be known ((n - m) + 1)
|
||||
revocation_threshold = ((policy.n - policy.m) + 1)
|
||||
revocation_threshold = ((policy.shares - policy.threshold) + 1)
|
||||
self.block_until_specific_nodes_are_known(
|
||||
policy.revocation_kit.revokable_addresses,
|
||||
allow_missing=(policy.n - revocation_threshold))
|
||||
allow_missing=(policy.shares - revocation_threshold))
|
||||
except self.NotEnoughTeachers:
|
||||
raise # TODO NRN
|
||||
|
||||
|
@ -622,7 +622,7 @@ class Bob(Character):
|
|||
allow_missing=allow_missing,
|
||||
learn_on_this_thread=True)
|
||||
|
||||
return unknown_ursulas, known_ursulas, treasure_map.m
|
||||
return unknown_ursulas, known_ursulas, treasure_map.threshold
|
||||
|
||||
def _decrypt_treasure_map(self,
|
||||
encrypted_treasure_map: EncryptedTreasureMap,
|
||||
|
@ -736,10 +736,10 @@ class Bob(Character):
|
|||
def _filter_work_orders_and_capsules(self,
|
||||
work_orders: Dict[ChecksumAddress, 'WorkOrder'],
|
||||
message_kits: Sequence['UmbralMessageKit'],
|
||||
m: int,
|
||||
threshold: int,
|
||||
) -> Tuple[List['WorkOrder'], Set['Capsule']]:
|
||||
remaining_work_orders = []
|
||||
remaining_capsules = {mk.capsule for mk in message_kits if len(mk) < m}
|
||||
remaining_capsules = {mk.capsule for mk in message_kits if len(mk) < threshold}
|
||||
for work_order in work_orders.values():
|
||||
if not work_order.tasks.keys().isdisjoint(remaining_capsules):
|
||||
remaining_work_orders.append(work_order)
|
||||
|
@ -863,7 +863,7 @@ class Bob(Character):
|
|||
*message_kits,
|
||||
message_kits_map: Dict[Capsule, UmbralMessageKit],
|
||||
new_work_orders: Sequence['WorkOrder'],
|
||||
m: int,
|
||||
threshold: int,
|
||||
retain_cfrags: bool
|
||||
) -> List[bytes]:
|
||||
|
||||
|
@ -875,7 +875,7 @@ class Bob(Character):
|
|||
# TODO Optimization: Block here (or maybe even later) until map is done being followed (instead of blocking above). #1114
|
||||
the_airing_of_grievances = []
|
||||
|
||||
remaining_work_orders, capsules_to_activate = self._filter_work_orders_and_capsules(new_work_orders, message_kits, m)
|
||||
remaining_work_orders, capsules_to_activate = self._filter_work_orders_and_capsules(new_work_orders, message_kits, threshold)
|
||||
|
||||
# If all the capsules are now activated, we can stop here.
|
||||
if capsules_to_activate and remaining_work_orders:
|
||||
|
@ -894,14 +894,14 @@ class Bob(Character):
|
|||
for capsule, pre_task in work_order.tasks.items():
|
||||
message_kit = message_kits_map[capsule]
|
||||
message_kit.attach_cfrag(pre_task.cfrag)
|
||||
if len(message_kit) >= m:
|
||||
if len(message_kit) >= threshold:
|
||||
capsules_to_activate.discard(capsule)
|
||||
|
||||
# If all the capsules are now activated, we can stop here.
|
||||
if not capsules_to_activate:
|
||||
break
|
||||
else:
|
||||
raise Ursula.NotEnoughUrsulas("Unable to reach m Ursulas. See the logs for which Ursulas are down or noncompliant.")
|
||||
raise Ursula.NotEnoughUrsulas(f"Unable to reach {threshold} Ursulas. See the logs for which Ursulas are down or noncompliant.")
|
||||
|
||||
if the_airing_of_grievances:
|
||||
# ... and now you're gonna hear about it!
|
||||
|
@ -940,8 +940,8 @@ class Bob(Character):
|
|||
self.join_policy(label=label, publisher_verifying_key=publisher_verifying_key)
|
||||
treasure_map = self.treasure_maps[hrac]
|
||||
|
||||
_unknown_ursulas, _known_ursulas, m = self.follow_treasure_map(treasure_map=treasure_map, block=True)
|
||||
return treasure_map, m
|
||||
_unknown_ursulas, _known_ursulas, threshold = self.follow_treasure_map(treasure_map=treasure_map, block=True)
|
||||
return treasure_map, threshold
|
||||
|
||||
def retrieve(self,
|
||||
|
||||
|
@ -967,9 +967,9 @@ class Bob(Character):
|
|||
# If a policy publisher's verifying key is not passed, use Alice's by default.
|
||||
publisher_verifying_key = alice_verifying_key
|
||||
|
||||
treasure_map, m = self._handle_treasure_map(encrypted_treasure_map=encrypted_treasure_map,
|
||||
publisher_verifying_key=publisher_verifying_key,
|
||||
label=label)
|
||||
treasure_map, threshold = self._handle_treasure_map(encrypted_treasure_map=encrypted_treasure_map,
|
||||
publisher_verifying_key=publisher_verifying_key,
|
||||
label=label)
|
||||
|
||||
work_orders, message_kits_map = self._assemble_work_orders(
|
||||
*message_kits,
|
||||
|
@ -987,7 +987,7 @@ class Bob(Character):
|
|||
message_kits_map=message_kits_map,
|
||||
new_work_orders=work_orders.new,
|
||||
retain_cfrags=retain_cfrags,
|
||||
m=m)
|
||||
threshold=threshold)
|
||||
|
||||
return cleartexts
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ from nucypher.cli.types import GWEI
|
|||
from nucypher.policy.identity import Card
|
||||
|
||||
PublicKeys = namedtuple('PublicKeys', 'encrypting_key verifying_key')
|
||||
PolicyParameters = namedtuple('PolicyParameters', 'label m n expiration value rate')
|
||||
PolicyParameters = namedtuple('PolicyParameters', 'label threshold shares expiration value rate')
|
||||
|
||||
|
||||
def collect_keys_from_card(emitter: StdoutEmitter, card_identifier: str, force: bool):
|
||||
|
@ -95,20 +95,20 @@ def collect_expiration(alice: Alice, expiration: maya.MayaDT, force: bool) -> ma
|
|||
return expiration
|
||||
|
||||
|
||||
def collect_m_and_n(alice: Alice, m: int, n: int, force: bool) -> Tuple[int, int]:
|
||||
def collect_redundancy_ratio(alice: Alice, threshold: int, shares: int, force: bool) -> Tuple[int, int]:
|
||||
# Policy Threshold and Shares
|
||||
if not n:
|
||||
n = alice.n
|
||||
if not force and not click.confirm(f'Use default value for N ({n})?', default=True):
|
||||
n = click.prompt('Enter total number of shares (N)', type=click.INT)
|
||||
if not m:
|
||||
m = alice.m
|
||||
if not force and not click.confirm(f'Use default value for M ({m})?', default=True):
|
||||
m = click.prompt('Enter threshold (M)', type=click.IntRange(1, n))
|
||||
return m, n
|
||||
if not shares:
|
||||
shares = alice.shares
|
||||
if not force and not click.confirm(f'Use default value for N ({shares})?', default=True):
|
||||
shares = click.prompt('Enter total number of shares (N)', type=click.INT)
|
||||
if not threshold:
|
||||
threshold = alice.threshold
|
||||
if not force and not click.confirm(f'Use default value for M ({threshold})?', default=True):
|
||||
threshold = click.prompt('Enter threshold (M)', type=click.IntRange(1, shares))
|
||||
return threshold, shares
|
||||
|
||||
|
||||
def collect_policy_rate_and_value(alice: Alice, rate: int, value: int, n: int, force: bool) -> Tuple[int, int]:
|
||||
def collect_policy_rate_and_value(alice: Alice, rate: int, value: int, shares: int, force: bool) -> Tuple[int, int]:
|
||||
|
||||
policy_value_provided = bool(value) or bool(rate)
|
||||
if not policy_value_provided:
|
||||
|
@ -118,12 +118,12 @@ def collect_policy_rate_and_value(alice: Alice, rate: int, value: int, n: int, f
|
|||
|
||||
if not force:
|
||||
default_gwei = Web3.fromWei(rate, 'gwei') # wei -> gwei
|
||||
prompt = "Confirm rate of {node_rate} gwei * {n} nodes ({period_rate} gwei per period)?"
|
||||
prompt = "Confirm rate of {node_rate} gwei * {shares} nodes ({period_rate} gwei per period)?"
|
||||
|
||||
if not click.confirm(prompt.format(node_rate=default_gwei, period_rate=default_gwei * n, n=n), default=True):
|
||||
if not click.confirm(prompt.format(node_rate=default_gwei, period_rate=default_gwei * shares, n=shares), default=True):
|
||||
interactive_rate = click.prompt('Enter rate per period in gwei', type=GWEI)
|
||||
# TODO: Interactive rate sampling & validation (#1709)
|
||||
interactive_prompt = prompt.format(node_rate=interactive_rate, period_rate=interactive_rate * n, n=n)
|
||||
interactive_prompt = prompt.format(node_rate=interactive_rate, period_rate=interactive_rate * shares, n=shares)
|
||||
click.confirm(interactive_prompt, default=True, abort=True)
|
||||
rate = Web3.toWei(interactive_rate, 'gwei') # gwei -> wei
|
||||
|
||||
|
@ -136,8 +136,8 @@ def collect_policy_parameters(
|
|||
force: bool,
|
||||
bob_identifier: str,
|
||||
label: str,
|
||||
m: int,
|
||||
n: int,
|
||||
threshold: int,
|
||||
shares: int,
|
||||
value: int,
|
||||
rate: int,
|
||||
expiration: maya.MayaDT
|
||||
|
@ -157,7 +157,7 @@ def collect_policy_parameters(
|
|||
expiration = collect_expiration(alice=alice, expiration=expiration, force=force)
|
||||
enforce_probationary_period(emitter=emitter, expiration=expiration)
|
||||
|
||||
m, n = collect_m_and_n(alice=alice, m=m, n=n, force=force)
|
||||
threshold, shares = collect_redundancy_ratio(alice=alice, threshold=threshold, shares=shares, force=force)
|
||||
if alice.federated_only:
|
||||
rate, value = FEDERATED, FEDERATED
|
||||
else:
|
||||
|
@ -165,13 +165,13 @@ def collect_policy_parameters(
|
|||
alice=alice,
|
||||
rate=rate,
|
||||
value=value,
|
||||
n=n,
|
||||
shares=shares,
|
||||
force=force)
|
||||
|
||||
policy_parameters = PolicyParameters(
|
||||
label=label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=expiration,
|
||||
rate=rate,
|
||||
value=value
|
||||
|
|
|
@ -155,7 +155,7 @@ def confirm_staged_grant(emitter, grant_request: Dict, federated: bool, seconds_
|
|||
emitter.echo(tabulate(table, tablefmt="simple"))
|
||||
return
|
||||
|
||||
period_rate = Web3.fromWei(pretty_request['n'] * pretty_request['rate'], 'gwei')
|
||||
period_rate = Web3.fromWei(pretty_request['shares'] * pretty_request['rate'], 'gwei')
|
||||
pretty_request['rate'] = f"{pretty_request['rate']} wei/period * {pretty_request['n']} nodes"
|
||||
|
||||
expiration = pretty_request['expiration']
|
||||
|
@ -165,9 +165,9 @@ def confirm_staged_grant(emitter, grant_request: Dict, federated: bool, seconds_
|
|||
pretty_request['expiration'] = f"{pretty_request['expiration']} ({periods} periods)"
|
||||
|
||||
# M of N
|
||||
pretty_request['Threshold Shares'] = f"{pretty_request['m']} of {pretty_request['n']}"
|
||||
del pretty_request['m']
|
||||
del pretty_request['n']
|
||||
pretty_request['Threshold Shares'] = f"{pretty_request['threshold']} of {pretty_request['shares']}"
|
||||
del pretty_request['threshold']
|
||||
del pretty_request['shares']
|
||||
|
||||
def prettify_field(field):
|
||||
field_words = [word.capitalize() for word in field.split('_')]
|
||||
|
|
|
@ -44,16 +44,16 @@ from nucypher.cli.options import (
|
|||
option_force,
|
||||
option_hw_wallet,
|
||||
option_light,
|
||||
option_m,
|
||||
option_middleware,
|
||||
option_min_stake,
|
||||
option_n,
|
||||
option_network,
|
||||
option_shares,
|
||||
option_poa,
|
||||
option_provider_uri,
|
||||
option_registry_filepath,
|
||||
option_signer_uri,
|
||||
option_teacher_uri,
|
||||
option_threshold,
|
||||
option_lonely,
|
||||
option_max_gas_price
|
||||
)
|
||||
|
@ -177,12 +177,12 @@ class AliceFullConfigOptions:
|
|||
|
||||
__option_name__ = 'full_config_options'
|
||||
|
||||
def __init__(self, config_options, poa: bool, light: bool, m: int, n: int, payment_periods: int):
|
||||
def __init__(self, config_options, poa: bool, light: bool, threshold: int, shares: int, payment_periods: int):
|
||||
self.config_options = config_options
|
||||
self.poa = poa
|
||||
self.light = light
|
||||
self.m = m
|
||||
self.n = n
|
||||
self.threshold = threshold
|
||||
self.shares = shares
|
||||
self.payment_periods = payment_periods
|
||||
|
||||
def generate_config(self, emitter: StdoutEmitter, config_root: Path) -> AliceConfiguration:
|
||||
|
@ -216,8 +216,8 @@ class AliceFullConfigOptions:
|
|||
registry_filepath=opts.registry_filepath,
|
||||
poa=self.poa,
|
||||
light=self.light,
|
||||
m=self.m,
|
||||
n=self.n,
|
||||
threshold=self.threshold,
|
||||
shares=self.shares,
|
||||
payment_periods=self.payment_periods)
|
||||
|
||||
def get_updates(self) -> dict:
|
||||
|
@ -230,8 +230,8 @@ class AliceFullConfigOptions:
|
|||
registry_filepath=opts.registry_filepath,
|
||||
poa=self.poa,
|
||||
light=self.light,
|
||||
m=self.m,
|
||||
n=self.n,
|
||||
threshold=self.threshold,
|
||||
shares=self.shares,
|
||||
payment_periods=self.payment_periods)
|
||||
# Depends on defaults being set on Configuration classes, filtrates None values
|
||||
updates = {k: v for k, v in payload.items() if v is not None}
|
||||
|
@ -243,8 +243,8 @@ group_full_config_options = group_options(
|
|||
config_options=group_config_options,
|
||||
poa=option_poa,
|
||||
light=option_light,
|
||||
m=option_m,
|
||||
n=option_n,
|
||||
threshold=option_threshold,
|
||||
shares=option_shares,
|
||||
payment_periods=option_payment_periods
|
||||
)
|
||||
|
||||
|
@ -434,7 +434,8 @@ def grant(general_config,
|
|||
value,
|
||||
rate,
|
||||
expiration,
|
||||
m, n,
|
||||
threshold,
|
||||
shares,
|
||||
character_options,
|
||||
config_file,
|
||||
force):
|
||||
|
@ -475,8 +476,8 @@ def grant(general_config,
|
|||
force=force,
|
||||
bob_identifier=bob_public_keys.verifying_key[:8],
|
||||
label=label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
rate=rate,
|
||||
value=value,
|
||||
expiration=expiration
|
||||
|
@ -486,8 +487,8 @@ def grant(general_config,
|
|||
'bob_encrypting_key': bob_public_keys.encrypting_key,
|
||||
'bob_verifying_key': bob_public_keys.verifying_key,
|
||||
'label': policy.label,
|
||||
'm': policy.m,
|
||||
'n': policy.n,
|
||||
'threshold': policy.threshold,
|
||||
'shares': policy.shares,
|
||||
'expiration': policy.expiration,
|
||||
}
|
||||
if not ALICE.federated_only:
|
||||
|
|
|
@ -53,16 +53,16 @@ option_max_gas_price = click.option('--max-gas-price', help="Maximum acceptable
|
|||
option_hw_wallet = click.option('--hw-wallet/--no-hw-wallet')
|
||||
option_light = click.option('--light', help="Indicate that node is light", is_flag=True, default=None)
|
||||
option_lonely = click.option('--lonely', help="Do not connect to seednodes", is_flag=True)
|
||||
option_m = click.option('--m', help="M-Threshold KFrags", type=click.INT)
|
||||
option_min_stake = click.option('--min-stake', help="The minimum stake the teacher must have to be locally accepted.", type=STAKED_TOKENS_RANGE, default=MIN_ALLOWED_LOCKED_TOKENS)
|
||||
option_n = click.option('--n', help="N-Total KFrags", type=click.INT)
|
||||
option_parameters = click.option('--parameters', help="Filepath to a JSON file containing additional parameters", type=EXISTING_READABLE_FILE)
|
||||
option_participant_address = click.option('--participant-address', help="Participant's checksum address.", type=EIP55_CHECKSUM_ADDRESS)
|
||||
option_poa = click.option('--poa/--disable-poa', help="Inject POA middleware", is_flag=True, default=None)
|
||||
option_registry_filepath = click.option('--registry-filepath', help="Custom contract registry filepath", type=EXISTING_READABLE_FILE)
|
||||
option_shares = click.option('--shares', '-n', help="N-Total shares", type=click.INT)
|
||||
option_signer_uri = click.option('--signer', 'signer_uri', '-S', default=None, type=str)
|
||||
option_staking_address = click.option('--staking-address', help="Address of a NuCypher staker", type=EIP55_CHECKSUM_ADDRESS)
|
||||
option_teacher_uri = click.option('--teacher', 'teacher_uri', help="An Ursula URI to start learning from (seednode)", type=click.STRING)
|
||||
option_threshold = click.option('--threshold', '-m', help="M-Threshold KFrags", type=click.INT)
|
||||
_option_middleware = click.option('-Z', '--mock-networking', help="Use in-memory transport instead of networking", count=True)
|
||||
|
||||
# Avoid circular input
|
||||
|
|
|
@ -164,8 +164,8 @@ class AliceConfiguration(CharacterConfiguration):
|
|||
DEFAULT_CONTROLLER_PORT = 8151
|
||||
|
||||
# TODO: Best (Sane) Defaults
|
||||
DEFAULT_M = 2
|
||||
DEFAULT_N = 3
|
||||
DEFAULT_THRESHOLD = 2
|
||||
DEFAULT_SHARES = 3
|
||||
|
||||
DEFAULT_STORE_POLICIES = True
|
||||
DEFAULT_STORE_CARDS = True
|
||||
|
@ -179,8 +179,8 @@ class AliceConfiguration(CharacterConfiguration):
|
|||
)
|
||||
|
||||
def __init__(self,
|
||||
m: int = None,
|
||||
n: int = None,
|
||||
threshold: int = None,
|
||||
shares: int = None,
|
||||
rate: int = None,
|
||||
payment_periods: int = None,
|
||||
store_policies: bool = DEFAULT_STORE_POLICIES,
|
||||
|
@ -188,8 +188,8 @@ class AliceConfiguration(CharacterConfiguration):
|
|||
*args, **kwargs):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
self.m = m or self.DEFAULT_M
|
||||
self.n = n or self.DEFAULT_N
|
||||
self.threshold = threshold or self.DEFAULT_THRESHOLD
|
||||
self.shares = shares or self.DEFAULT_SHARES
|
||||
|
||||
# if not self.federated_only: # TODO: why not?
|
||||
self.rate = rate
|
||||
|
@ -200,8 +200,8 @@ class AliceConfiguration(CharacterConfiguration):
|
|||
|
||||
def static_payload(self) -> dict:
|
||||
payload = dict(
|
||||
m=self.m,
|
||||
n=self.n,
|
||||
threshold=self.threshold,
|
||||
shares=self.shares,
|
||||
store_policies=self.store_policies,
|
||||
store_cards=self.store_cards
|
||||
)
|
||||
|
|
|
@ -261,8 +261,8 @@ class DelegatingPower(DerivedKeyBasedPower):
|
|||
bob_pubkey_enc,
|
||||
signer,
|
||||
label: bytes,
|
||||
m: int,
|
||||
n: int
|
||||
threshold: int,
|
||||
shares: int
|
||||
) -> Tuple[PublicKey, List]:
|
||||
"""
|
||||
Generates re-encryption key frags ("KFrags") and returns them.
|
||||
|
@ -270,15 +270,15 @@ class DelegatingPower(DerivedKeyBasedPower):
|
|||
These KFrags can be used by Ursula to re-encrypt a Capsule for Bob so
|
||||
that he can activate the Capsule.
|
||||
:param bob_pubkey_enc: Bob's public key
|
||||
:param m: Minimum number of KFrags needed to rebuild ciphertext
|
||||
:param n: Total number of KFrags to generate
|
||||
:param threshold: Minimum number of KFrags needed to rebuild ciphertext
|
||||
:param shares: Total number of KFrags to generate
|
||||
"""
|
||||
|
||||
__private_key = self._get_privkey_from_label(label)
|
||||
kfrags = generate_kfrags(delegating_sk=__private_key,
|
||||
receiving_pk=bob_pubkey_enc,
|
||||
threshold=m,
|
||||
num_kfrags=n,
|
||||
threshold=threshold,
|
||||
num_kfrags=shares,
|
||||
signer=signer,
|
||||
sign_delegating_key=False,
|
||||
sign_receiving_key=False,
|
||||
|
|
|
@ -64,17 +64,17 @@ class TreasureMap:
|
|||
bob: 'Bob',
|
||||
ursulas: Sequence['Ursula'],
|
||||
verified_kfrags: Sequence[VerifiedKeyFrag],
|
||||
m: int,
|
||||
threshold: int,
|
||||
) -> 'TreasureMap':
|
||||
"""Create a new treasure map for a collection of ursulas and kfrags."""
|
||||
|
||||
if m < 1 or m > 255:
|
||||
if threshold < 1 or threshold > 255:
|
||||
raise ValueError("The threshold must be between 1 and 255.")
|
||||
|
||||
if len(ursulas) < m:
|
||||
if len(ursulas) < threshold:
|
||||
raise ValueError(
|
||||
f"The number of destinations ({len(ursulas)}) "
|
||||
f"must be equal or greater than the threshold ({m})")
|
||||
f"must be equal or greater than the threshold ({threshold})")
|
||||
|
||||
# Encrypt each kfrag for an Ursula.
|
||||
destinations = {}
|
||||
|
@ -88,14 +88,14 @@ class TreasureMap:
|
|||
|
||||
destinations[ursula.checksum_address] = encrypted_kfrag
|
||||
|
||||
return cls(m=m, hrac=hrac, destinations=destinations)
|
||||
return cls(threshold=threshold, hrac=hrac, destinations=destinations)
|
||||
|
||||
def __init__(self,
|
||||
m: int,
|
||||
threshold: int,
|
||||
hrac: HRAC,
|
||||
destinations: Dict[ChecksumAddress, bytes],
|
||||
):
|
||||
self.m = m
|
||||
self.threshold = threshold
|
||||
self.destinations = destinations
|
||||
self.hrac = hrac
|
||||
|
||||
|
@ -118,17 +118,17 @@ class TreasureMap:
|
|||
return nodes_as_bytes
|
||||
|
||||
def __bytes__(self):
|
||||
return self.m.to_bytes(1, "big") + bytes(self.hrac) + self._nodes_as_bytes()
|
||||
return self.threshold.to_bytes(1, "big") + bytes(self.hrac) + self._nodes_as_bytes()
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes):
|
||||
try:
|
||||
m, hrac, remainder = cls.main_splitter(data, return_remainder=True)
|
||||
threshold, hrac, remainder = cls.main_splitter(data, return_remainder=True)
|
||||
ursula_and_kfrags = cls.ursula_and_kfrag_payload_splitter.repeat(remainder)
|
||||
except BytestringSplittingError as e:
|
||||
raise ValueError('Invalid treasure map contents.') from e
|
||||
destinations = {u: k for u, k in ursula_and_kfrags}
|
||||
return cls(m, hrac, destinations)
|
||||
return cls(threshold, hrac, destinations)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.destinations.items())
|
||||
|
|
|
@ -195,7 +195,7 @@ class Policy(ABC):
|
|||
bob: 'Bob',
|
||||
kfrags: Sequence[VerifiedKeyFrag],
|
||||
public_key: PublicKey,
|
||||
m: int,
|
||||
threshold: int,
|
||||
):
|
||||
|
||||
"""
|
||||
|
@ -203,8 +203,8 @@ class Policy(ABC):
|
|||
:param label: The identity of the resource to which Bob is granted access.
|
||||
"""
|
||||
|
||||
self.m = m
|
||||
self.n = len(kfrags)
|
||||
self.threshold = threshold
|
||||
self.shares = len(kfrags)
|
||||
self.publisher = publisher
|
||||
self.label = label
|
||||
self.bob = bob
|
||||
|
@ -287,7 +287,7 @@ class Policy(ABC):
|
|||
) -> Dict['Ursula', Arrangement]:
|
||||
"""
|
||||
Pick some Ursula addresses and send them arrangement proposals.
|
||||
Returns a dictionary of Ursulas to Arrangements if it managed to get `n` responses.
|
||||
Returns a dictionary of Ursulas to Arrangements if it managed to get `shares` responses.
|
||||
"""
|
||||
|
||||
if handpicked_ursulas is None:
|
||||
|
@ -295,19 +295,19 @@ class Policy(ABC):
|
|||
handpicked_addresses = [ChecksumAddress(ursula.checksum_address) for ursula in handpicked_ursulas]
|
||||
|
||||
reservoir = self._make_reservoir(handpicked_addresses)
|
||||
value_factory = PrefetchStrategy(reservoir, self.n)
|
||||
value_factory = PrefetchStrategy(reservoir, self.shares)
|
||||
|
||||
def worker(address):
|
||||
return self._propose_arrangement(address, network_middleware)
|
||||
|
||||
self.publisher.block_until_number_of_known_nodes_is(self.n, learn_on_this_thread=True, eager=True)
|
||||
self.publisher.block_until_number_of_known_nodes_is(self.shares, learn_on_this_thread=True, eager=True)
|
||||
|
||||
worker_pool = WorkerPool(worker=worker,
|
||||
value_factory=value_factory,
|
||||
target_successes=self.n,
|
||||
target_successes=self.shares,
|
||||
timeout=timeout,
|
||||
stagger_timeout=1,
|
||||
threadpool_size=self.n)
|
||||
threadpool_size=self.shares)
|
||||
worker_pool.start()
|
||||
try:
|
||||
successes = worker_pool.block_until_target_successes()
|
||||
|
@ -324,7 +324,7 @@ class Policy(ABC):
|
|||
|
||||
accepted_addresses = ", ".join(ursula.checksum_address for ursula in accepted_arrangements)
|
||||
|
||||
if len(accepted_arrangements) < self.n:
|
||||
if len(accepted_arrangements) < self.shares:
|
||||
|
||||
rejected_proposals = "\n".join(f"{address}: {value}" for address, (type_, value, traceback) in failures.items())
|
||||
|
||||
|
@ -380,7 +380,7 @@ class Policy(ABC):
|
|||
bob=self.bob,
|
||||
ursulas=list(arrangements),
|
||||
verified_kfrags=self.kfrags,
|
||||
m=self.m)
|
||||
threshold=self.threshold)
|
||||
|
||||
enc_treasure_map = self._encrypt_treasure_map(treasure_map)
|
||||
|
||||
|
@ -393,7 +393,7 @@ class Policy(ABC):
|
|||
enacted_policy = EnactedPolicy(self.hrac,
|
||||
self.label,
|
||||
self.public_key,
|
||||
treasure_map.m,
|
||||
treasure_map.threshold,
|
||||
enc_treasure_map,
|
||||
treasure_map_publisher,
|
||||
revocation_kit,
|
||||
|
@ -463,21 +463,21 @@ class BlockchainPolicy(Policy):
|
|||
return BlockchainPolicy.NotEnoughBlockchainUrsulas
|
||||
|
||||
def _validate_fee_value(self) -> None:
|
||||
rate_per_period = self.value // self.n // self.payment_periods # wei
|
||||
recalculated_value = self.payment_periods * rate_per_period * self.n
|
||||
rate_per_period = self.value // self.shares // self.payment_periods # wei
|
||||
recalculated_value = self.payment_periods * rate_per_period * self.shares
|
||||
if recalculated_value != self.value:
|
||||
raise ValueError(f"Invalid policy value calculation - "
|
||||
f"{self.value} can't be divided into {self.n} staker payments per period "
|
||||
f"{self.value} can't be divided into {self.shares} staker payments per period "
|
||||
f"for {self.payment_periods} periods without a remainder")
|
||||
|
||||
@staticmethod
|
||||
def generate_policy_parameters(n: int,
|
||||
def generate_policy_parameters(shares: int,
|
||||
payment_periods: int,
|
||||
value: int = None,
|
||||
rate: int = None) -> dict:
|
||||
|
||||
# Check for negative inputs
|
||||
if sum(True for i in (n, payment_periods, value, rate) if i is not None and i < 0) > 0:
|
||||
if sum(True for i in (shares, payment_periods, value, rate) if i is not None and i < 0) > 0:
|
||||
raise BlockchainPolicy.InvalidPolicyValue(f"Negative policy parameters are not allowed. Be positive.")
|
||||
|
||||
# Check for policy params
|
||||
|
@ -487,13 +487,13 @@ class BlockchainPolicy(Policy):
|
|||
f"Got value: {value} and rate: {rate}")
|
||||
|
||||
if value is None:
|
||||
value = rate * payment_periods * n
|
||||
value = rate * payment_periods * shares
|
||||
|
||||
else:
|
||||
value_per_node = value // n
|
||||
if value_per_node * n != value:
|
||||
value_per_node = value // shares
|
||||
if value_per_node * shares != value:
|
||||
raise BlockchainPolicy.InvalidPolicyValue(f"Policy value of ({value} wei) cannot be"
|
||||
f" divided by N ({n}) without a remainder.")
|
||||
f" divided by N ({shares}) without a remainder.")
|
||||
|
||||
rate = value_per_node // payment_periods
|
||||
if rate * payment_periods != value_per_node:
|
||||
|
@ -545,7 +545,7 @@ class EnactedPolicy:
|
|||
hrac: HRAC,
|
||||
label: bytes,
|
||||
public_key: PublicKey,
|
||||
m: int,
|
||||
threshold: int,
|
||||
treasure_map: 'EncryptedTreasureMap',
|
||||
treasure_map_publisher: TreasureMapPublisher,
|
||||
revocation_kit: RevocationKit,
|
||||
|
@ -558,8 +558,8 @@ class EnactedPolicy:
|
|||
self.treasure_map = treasure_map
|
||||
self.treasure_map_publisher = treasure_map_publisher
|
||||
self.revocation_kit = revocation_kit
|
||||
self.m = m
|
||||
self.n = len(self.revocation_kit)
|
||||
self.threshold = threshold
|
||||
self.shares = len(self.revocation_kit)
|
||||
self.publisher_verifying_key = publisher_verifying_key
|
||||
|
||||
def publish_treasure_map(self):
|
||||
|
|
|
@ -93,8 +93,8 @@ def create_policy_control_request(blockchain_bob):
|
|||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(blockchain_bob.stamp).hex(),
|
||||
'label': b64encode(bytes(b'test')).decode(),
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'threshold': 2,
|
||||
'shares': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=35)).iso8601(),
|
||||
'value': 3 * 3 * 10 ** 16
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ def grant_control_request(blockchain_bob):
|
|||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(blockchain_bob.stamp).hex(),
|
||||
'label': 'test',
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'threshold': 2,
|
||||
'shares': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=35)).iso8601(),
|
||||
'value': 3 * 3 * 10 ** 16
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ def test_alice_web_character_control_grant_error_messages(alice_web_controller_t
|
|||
method_name, params = grant_control_request
|
||||
endpoint = f'/{method_name}'
|
||||
|
||||
params['m'] = params['n'] + 1
|
||||
params['threshold'] = params['shares'] + 1
|
||||
|
||||
response = alice_web_controller_test_client.put(endpoint, data=json.dumps(params))
|
||||
assert response.status_code == 400
|
||||
|
@ -121,8 +121,8 @@ def test_alice_character_control_revoke(alice_web_controller_test_client, blockc
|
|||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(blockchain_bob.stamp).hex(),
|
||||
'label': 'test-revoke',
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'threshold': 2,
|
||||
'shares': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=35)).iso8601(),
|
||||
'value': 100500 * 3 * 3,
|
||||
}
|
||||
|
@ -290,8 +290,8 @@ def test_web_character_control_lifecycle(alice_web_controller_test_client,
|
|||
alice_request_data = {
|
||||
'bob_encrypting_key': bob_encrypting_key_hex,
|
||||
'bob_verifying_key': bob_verifying_key_hex,
|
||||
'm': 1,
|
||||
'n': 1,
|
||||
'threshold': 1,
|
||||
'shares': 1,
|
||||
'label': random_label,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=35)).iso8601(),
|
||||
'value': 3 * 10 ** 10
|
||||
|
|
|
@ -29,23 +29,23 @@ from nucypher.policy.maps import EncryptedTreasureMap
|
|||
|
||||
def test_decentralized_grant(blockchain_alice, blockchain_bob, blockchain_ursulas):
|
||||
# Setup the policy details
|
||||
n = 3
|
||||
shares = 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
||||
label = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
|
||||
# Create the Policy, Granting access to Bob
|
||||
policy = blockchain_alice.grant(bob=blockchain_bob,
|
||||
label=label,
|
||||
m=2,
|
||||
n=n,
|
||||
threshold=2,
|
||||
shares=shares,
|
||||
rate=int(1e18), # one ether
|
||||
expiration=policy_end_datetime)
|
||||
|
||||
treasure_map = blockchain_bob._decrypt_treasure_map(policy.treasure_map,
|
||||
policy.publisher_verifying_key)
|
||||
|
||||
# The number of actually enacted arrangements is exactly equal to n.
|
||||
assert len(treasure_map.destinations) == n
|
||||
# The number of actually enacted arrangements is exactly equal to shares.
|
||||
assert len(treasure_map.destinations) == shares
|
||||
|
||||
# Let's look at the enacted arrangements.
|
||||
for ursula in blockchain_ursulas:
|
||||
|
|
|
@ -33,15 +33,15 @@ def test_policy_simple_sinpa(blockchain_ursulas, blockchain_alice, blockchain_bo
|
|||
"""
|
||||
amonia = Amonia.from_lawful_alice(blockchain_alice)
|
||||
# Setup the policy details
|
||||
n = 3
|
||||
shares = 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
||||
label = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
|
||||
with pytest.raises(Policy.Unpaid):
|
||||
_bupkiss_policy = amonia.grant_without_paying(bob=blockchain_bob,
|
||||
label=label,
|
||||
m=2,
|
||||
n=n,
|
||||
threshold=2,
|
||||
shares=shares,
|
||||
rate=int(1e18), # one ether
|
||||
expiration=policy_end_datetime)
|
||||
|
||||
|
@ -66,14 +66,14 @@ def test_try_to_post_free_arrangement_by_hacking_enact(blockchain_ursulas, block
|
|||
"""
|
||||
amonia = Amonia.from_lawful_alice(blockchain_alice)
|
||||
# Setup the policy details
|
||||
n = 3
|
||||
shares = 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
||||
label = b"another_path"
|
||||
|
||||
bupkiss_policy = amonia.circumvent_safegaurds_and_grant_without_paying(bob=blockchain_bob,
|
||||
label=label,
|
||||
m=2,
|
||||
n=n,
|
||||
threshold=2,
|
||||
shares=shares,
|
||||
rate=int(1e18), # one ether
|
||||
expiration=policy_end_datetime,
|
||||
publish_treasure_map=False)
|
||||
|
@ -108,7 +108,7 @@ def test_pay_a_flunky_instead_of_the_arranged_ursula(blockchain_alice, blockchai
|
|||
flunkies = [blockchain_ursulas[5], blockchain_ursulas[6], blockchain_ursulas[7]]
|
||||
|
||||
# Setup the policy details
|
||||
n = 3
|
||||
shares = 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
||||
label = b"back_and_forth_forever"
|
||||
|
||||
|
@ -116,8 +116,8 @@ def test_pay_a_flunky_instead_of_the_arranged_ursula(blockchain_alice, blockchai
|
|||
ursulas_to_pay_instead=flunkies,
|
||||
bob=blockchain_bob,
|
||||
label=label,
|
||||
m=2,
|
||||
n=n,
|
||||
threshold=2,
|
||||
shares=shares,
|
||||
rate=int(1e18), # one ether
|
||||
expiration=policy_end_datetime,
|
||||
publish_treasure_map=False)
|
||||
|
@ -148,14 +148,14 @@ def test_pay_a_flunky_instead_of_the_arranged_ursula(blockchain_alice, blockchai
|
|||
def test_put_additional_treasure_map_on_network(blockchain_ursulas, blockchain_alice, blockchain_bob, agency, testerchain):
|
||||
amonia = Amonia.from_lawful_alice(blockchain_alice)
|
||||
# Setup the policy details
|
||||
n = 3
|
||||
shares = 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
||||
label = b"this_is_another_path_to_which_access_is_being_granted"
|
||||
|
||||
policy = amonia.grant(bob=blockchain_bob,
|
||||
label=label,
|
||||
m=2,
|
||||
n=n,
|
||||
threshold=2,
|
||||
shares=shares,
|
||||
rate=int(1e18), # one ether
|
||||
expiration=policy_end_datetime)
|
||||
sucker = blockchain_ursulas[0]
|
||||
|
|
|
@ -138,13 +138,13 @@ def test_blockchain_ursulas_reencrypt(blockchain_ursulas, blockchain_alice, bloc
|
|||
label = b'bbo'
|
||||
|
||||
# TODO: Make sample selection buffer configurable - #1061
|
||||
m = n = 10
|
||||
threshold = shares = 10
|
||||
expiration = maya.now() + datetime.timedelta(days=35)
|
||||
|
||||
_policy = blockchain_alice.grant(bob=blockchain_bob,
|
||||
label=label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=expiration,
|
||||
value=policy_value)
|
||||
|
||||
|
@ -170,7 +170,7 @@ def test_blockchain_ursulas_reencrypt(blockchain_ursulas, blockchain_alice, bloc
|
|||
with pytest.raises(BlockchainPolicy.NotEnoughBlockchainUrsulas):
|
||||
_policy = blockchain_alice.grant(bob=blockchain_bob,
|
||||
label=b'another-label',
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=expiration,
|
||||
value=policy_value)
|
||||
|
|
|
@ -311,8 +311,8 @@ def run_entire_cli_lifecycle(click_runner,
|
|||
'--network', TEMPORARY_DOMAIN,
|
||||
'--teacher', teacher_uri,
|
||||
'--config-file', str(alice_configuration_file_location.absolute()),
|
||||
'--m', 2,
|
||||
'--n', 3,
|
||||
'-m', 2,
|
||||
'-n', 3,
|
||||
'--expiration', expiration,
|
||||
'--label', random_label,
|
||||
'--bob-encrypting-key', bob_encrypting_key,
|
||||
|
|
|
@ -606,14 +606,15 @@ def test_collect_rewards_integration(click_runner,
|
|||
# Alice creates a policy and grants Bob access
|
||||
blockchain_alice.selection_buffer = 1
|
||||
|
||||
M, N = 1, 1
|
||||
threshold, shares = 1, 1
|
||||
duration_in_periods = 3
|
||||
days = (duration_in_periods - 1) * (token_economics.hours_per_period // 24)
|
||||
now = testerchain.w3.eth.getBlock('latest').timestamp
|
||||
expiration = maya.MayaDT(now).add(days=days)
|
||||
blockchain_policy = blockchain_alice.grant(bob=blockchain_bob,
|
||||
label=random_policy_label,
|
||||
m=M, n=N,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
value=policy_value,
|
||||
expiration=expiration,
|
||||
handpicked_ursulas={ursula})
|
||||
|
|
|
@ -61,15 +61,15 @@ def test_blockchain_alice_finds_ursula_via_rest(blockchain_alice, blockchain_urs
|
|||
@pytest.mark.skip(reason="Consider removal of this test pursuant to PR #2565")
|
||||
def test_treasure_map_cannot_be_duplicated(blockchain_ursulas, blockchain_alice, blockchain_bob, agency):
|
||||
# Setup the policy details
|
||||
n = 3
|
||||
shares = 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
||||
label = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
|
||||
# Create the Policy, Granting access to Bob
|
||||
policy = blockchain_alice.grant(bob=blockchain_bob,
|
||||
label=label,
|
||||
m=2,
|
||||
n=n,
|
||||
threshold=2,
|
||||
shares=shares,
|
||||
rate=int(1e18), # one ether
|
||||
expiration=policy_end_datetime)
|
||||
|
||||
|
@ -159,15 +159,15 @@ def test_treasure_map_cannot_be_duplicated_again(blockchain_ursulas,
|
|||
blockchain_bob,
|
||||
agency):
|
||||
# Setup the policy details
|
||||
n = 3
|
||||
shares = 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
||||
label = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
|
||||
# Create the Policy, Granting access to Bob
|
||||
policy = blockchain_alice.grant(bob=blockchain_bob,
|
||||
label=label,
|
||||
m=2,
|
||||
n=n,
|
||||
threshold=2,
|
||||
shares=shares,
|
||||
rate=int(1e18), # one ether
|
||||
expiration=policy_end_datetime)
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ MOCK_PROVIDER_URI = 'tester://mock'
|
|||
# Node Configuration
|
||||
#
|
||||
|
||||
MOCK_POLICY_DEFAULT_M = 3
|
||||
MOCK_POLICY_DEFAULT_THRESHOLD = 3
|
||||
|
||||
# These IP addresses are reserved for usage in documentation
|
||||
# https://tools.ietf.org/html/rfc5737
|
||||
|
|
|
@ -77,7 +77,7 @@ from tests.constants import (
|
|||
MIN_STAKE_FOR_TESTS,
|
||||
MOCK_CUSTOM_INSTALLATION_PATH,
|
||||
MOCK_CUSTOM_INSTALLATION_PATH_2,
|
||||
MOCK_POLICY_DEFAULT_M,
|
||||
MOCK_POLICY_DEFAULT_THRESHOLD,
|
||||
MOCK_REGISTRY_FILEPATH,
|
||||
NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK,
|
||||
TEST_GAS_LIMIT,
|
||||
|
@ -220,13 +220,13 @@ def idle_federated_policy(federated_alice, federated_bob):
|
|||
"""
|
||||
Creates a Policy, in a manner typical of how Alice might do it, with a unique label
|
||||
"""
|
||||
m = MOCK_POLICY_DEFAULT_M
|
||||
n = NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK
|
||||
threshold = MOCK_POLICY_DEFAULT_THRESHOLD
|
||||
shares = NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK
|
||||
random_label = generate_random_label()
|
||||
policy = federated_alice.create_policy(federated_bob,
|
||||
label=random_label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=maya.now() + timedelta(days=5))
|
||||
return policy
|
||||
|
||||
|
@ -263,12 +263,13 @@ def idle_blockchain_policy(testerchain, blockchain_alice, blockchain_bob, token_
|
|||
days = periods * (token_economics.hours_per_period // 24)
|
||||
now = testerchain.w3.eth.getBlock('latest').timestamp
|
||||
expiration = maya.MayaDT(now).add(days=days - 1)
|
||||
n = 3
|
||||
m = 2
|
||||
shares = 3
|
||||
threshold = 2
|
||||
policy = blockchain_alice.create_policy(blockchain_bob,
|
||||
label=random_label,
|
||||
m=m, n=n,
|
||||
value=n * periods * 100,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
value=shares * periods * 100,
|
||||
expiration=expiration)
|
||||
return policy
|
||||
|
||||
|
@ -306,12 +307,13 @@ def random_blockchain_policy(testerchain, blockchain_alice, blockchain_bob, toke
|
|||
days = periods * (token_economics.hours_per_period // 24)
|
||||
now = testerchain.w3.eth.getBlock('latest').timestamp
|
||||
expiration = maya.MayaDT(now).add(days=days - 1)
|
||||
n = 3
|
||||
m = 2
|
||||
shares = 3
|
||||
threshold = 2
|
||||
policy = blockchain_alice.create_policy(blockchain_bob,
|
||||
label=random_label,
|
||||
m=m, n=n,
|
||||
value=n * periods * 100,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
value=shares * periods * 100,
|
||||
expiration=expiration)
|
||||
return policy
|
||||
|
||||
|
|
|
@ -93,8 +93,8 @@ def create_policy_control_request(federated_bob):
|
|||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(federated_bob.stamp).hex(),
|
||||
'label': b64encode(bytes(b'test')).decode(),
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'threshold': 2,
|
||||
'shares': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=3)).iso8601(),
|
||||
}
|
||||
return method_name, params
|
||||
|
@ -108,8 +108,8 @@ def grant_control_request(federated_bob):
|
|||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(federated_bob.stamp).hex(),
|
||||
'label': 'test',
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'threshold': 2,
|
||||
'shares': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=3)).iso8601(),
|
||||
}
|
||||
return method_name, params
|
||||
|
|
|
@ -115,8 +115,8 @@ def test_alice_character_control_revoke(alice_web_controller_test_client, federa
|
|||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(federated_bob.stamp).hex(),
|
||||
'label': 'test-revoke',
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'threshold': 2,
|
||||
'shares': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=3)).iso8601(),
|
||||
}
|
||||
response = alice_web_controller_test_client.put('/grant', data=json.dumps(grant_request_data))
|
||||
|
@ -286,8 +286,8 @@ def test_web_character_control_lifecycle(alice_web_controller_test_client,
|
|||
alice_request_data = {
|
||||
'bob_encrypting_key': bob_encrypting_key_hex,
|
||||
'bob_verifying_key': bob_verifying_key_hex,
|
||||
'm': 1,
|
||||
'n': 1,
|
||||
'threshold': 1,
|
||||
'shares': 1,
|
||||
'label': random_label,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=3)).iso8601(), # TODO
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ def test_bob_already_knows_all_nodes_in_treasure_map(enacted_federated_policy,
|
|||
assert len(unknown) == 0
|
||||
|
||||
# ...because he already knew of all the Ursulas on the map.
|
||||
assert len(known) == enacted_federated_policy.n
|
||||
assert len(known) == enacted_federated_policy.shares
|
||||
|
||||
|
||||
@pytest_twisted.inlineCallbacks
|
||||
|
@ -333,13 +333,13 @@ def test_bob_gathers_and_combines(enacted_federated_policy, federated_treasure_m
|
|||
assert len(federated_bob._completed_work_orders) == 2
|
||||
|
||||
# ...but the policy requires us to collect more cfrags.
|
||||
assert len(federated_bob._completed_work_orders) < federated_treasure_map.m
|
||||
assert len(federated_bob._completed_work_orders) < federated_treasure_map.threshold
|
||||
|
||||
# Bob can't decrypt yet with just two CFrags. He needs to gather at least m.
|
||||
# Bob can't decrypt yet with just two CFrags. He needs to gather at least `threshold`.
|
||||
with pytest.raises(DecryptingKeypair.DecryptionFailed):
|
||||
federated_bob.decrypt(the_message_kit)
|
||||
|
||||
number_left_to_collect = federated_treasure_map.m - len(federated_bob._completed_work_orders)
|
||||
number_left_to_collect = federated_treasure_map.threshold - len(federated_bob._completed_work_orders)
|
||||
|
||||
the_message_kit.set_correctness_keys(
|
||||
delegating=the_data_source.policy_pubkey,
|
||||
|
|
|
@ -27,7 +27,7 @@ from twisted.internet.task import Clock
|
|||
from nucypher.characters.lawful import Bob, Enrico, Ursula
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN
|
||||
from nucypher.policy.maps import TreasureMap
|
||||
from tests.constants import (MOCK_POLICY_DEFAULT_M, NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK)
|
||||
from tests.constants import NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK
|
||||
from tests.utils.middleware import MockRestMiddleware
|
||||
|
||||
|
||||
|
@ -80,13 +80,13 @@ def test_bob_joins_policy_and_retrieves(federated_alice,
|
|||
|
||||
# Alice creates a policy granting access to Bob
|
||||
# Just for fun, let's assume she distributes KFrags among Ursulas unknown to Bob
|
||||
n = NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK - 2
|
||||
shares = NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK - 2
|
||||
label = b'label://' + os.urandom(32)
|
||||
contract_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
policy = federated_alice.grant(bob=bob,
|
||||
label=label,
|
||||
m=3,
|
||||
n=n,
|
||||
threshold=3,
|
||||
shares=shares,
|
||||
expiration=contract_end_datetime,
|
||||
handpicked_ursulas=set(rest_of_ursulas),
|
||||
)
|
||||
|
|
|
@ -29,12 +29,12 @@ from nucypher.policy.orders import Revocation
|
|||
|
||||
def test_federated_grant(federated_alice, federated_bob, federated_ursulas):
|
||||
# Setup the policy details
|
||||
m, n = 2, 3
|
||||
threshold, shares = 2, 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
label = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
|
||||
# Create the Policy, granting access to Bob
|
||||
policy = federated_alice.grant(federated_bob, label, m=m, n=n, expiration=policy_end_datetime)
|
||||
policy = federated_alice.grant(federated_bob, label, threshold=threshold, shares=shares, expiration=policy_end_datetime)
|
||||
|
||||
# Check Alice's active policies
|
||||
assert policy.hrac in federated_alice.active_policies
|
||||
|
@ -43,8 +43,8 @@ def test_federated_grant(federated_alice, federated_bob, federated_ursulas):
|
|||
treasure_map = federated_bob._decrypt_treasure_map(policy.treasure_map,
|
||||
policy.publisher_verifying_key)
|
||||
|
||||
# The number of actually enacted arrangements is exactly equal to n.
|
||||
assert len(treasure_map.destinations) == n
|
||||
# The number of actually enacted arrangements is exactly equal to shares.
|
||||
assert len(treasure_map.destinations) == shares
|
||||
|
||||
# Let's look at the enacted arrangements.
|
||||
for ursula in federated_ursulas:
|
||||
|
@ -63,15 +63,15 @@ def test_federated_alice_can_decrypt(federated_alice, federated_bob):
|
|||
"""
|
||||
|
||||
# Setup the policy details
|
||||
m, n = 2, 3
|
||||
threshold, shares = 2, 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
label = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
|
||||
policy = federated_alice.create_policy(
|
||||
bob=federated_bob,
|
||||
label=label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=policy_end_datetime,
|
||||
)
|
||||
|
||||
|
@ -99,11 +99,11 @@ def test_federated_alice_can_decrypt(federated_alice, federated_bob):
|
|||
@pytest.mark.skip("Needs rework post-TMcKF") # TODO
|
||||
@pytest.mark.usefixtures('federated_ursulas')
|
||||
def test_revocation(federated_alice, federated_bob):
|
||||
m, n = 2, 3
|
||||
threshold, shares = 2, 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
label = b"revocation test"
|
||||
|
||||
policy = federated_alice.grant(federated_bob, label, m=m, n=n, expiration=policy_end_datetime)
|
||||
policy = federated_alice.grant(federated_bob, label, threshold=threshold, shares=shares, expiration=policy_end_datetime)
|
||||
|
||||
for node_id, encrypted_kfrag in policy.treasure_map:
|
||||
assert policy.revocation_kit[node_id]
|
||||
|
|
|
@ -41,8 +41,8 @@ def test_various_field_validations_by_way_of_alice_grant(federated_bob):
|
|||
data = {
|
||||
'bob_encrypting_key': bytes(bob_encrypting_key).hex(),
|
||||
'bob_verifying_key': bytes(federated_bob.stamp).hex(),
|
||||
'm': 5,
|
||||
'n': 6,
|
||||
'threshold': 5,
|
||||
'shares': 6,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=3)).iso8601(),
|
||||
'label': 'cats the animal',
|
||||
'rate': 1000,
|
||||
|
@ -59,12 +59,12 @@ def test_various_field_validations_by_way_of_alice_grant(federated_bob):
|
|||
assert result['label'] == b'cats the animal'
|
||||
|
||||
# validate that negative "m" value fails
|
||||
data['m'] = -5
|
||||
data['threshold'] = -5
|
||||
with pytest.raises(SpecificationError) as e:
|
||||
GrantPolicy().load(data)
|
||||
|
||||
# validate that m > n fails validation
|
||||
data['m'] = data['n'] + 19
|
||||
data['threshold'] = data['shares'] + 19
|
||||
with pytest.raises(SpecificationError) as e:
|
||||
GrantPolicy().load(data)
|
||||
|
||||
|
|
|
@ -64,14 +64,14 @@ def test_alices_powers_are_persistent(federated_ursulas, temp_dir_path):
|
|||
policy_pubkey = alice.get_policy_encrypting_key_from_label(label)
|
||||
|
||||
# Now, let's create a policy for some Bob.
|
||||
m, n = 3, 4
|
||||
threshold, shares = 3, 4
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
|
||||
bob = Bob(federated_only=True,
|
||||
start_learning_now=False,
|
||||
network_middleware=MockRestMiddleware())
|
||||
|
||||
bob_policy = alice.grant(bob, label, m=m, n=n, expiration=policy_end_datetime)
|
||||
bob_policy = alice.grant(bob, label, threshold=threshold, shares=shares, expiration=policy_end_datetime)
|
||||
|
||||
assert policy_pubkey == bob_policy.public_key
|
||||
|
||||
|
@ -113,9 +113,9 @@ def test_alices_powers_are_persistent(federated_ursulas, temp_dir_path):
|
|||
# Alice creates a new policy for Roberto. Note how all the parameters
|
||||
# except for the label (i.e., recipient, m, n, policy_end) are different
|
||||
# from previous policy
|
||||
m, n = 2, 5
|
||||
threshold, shares = 2, 5
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=3)
|
||||
roberto_policy = new_alice.grant(roberto, label, m=m, n=n, expiration=policy_end_datetime)
|
||||
roberto_policy = new_alice.grant(roberto, label, threshold=threshold, shares=shares, expiration=policy_end_datetime)
|
||||
|
||||
# Both policies must share the same public key (i.e., the policy public key)
|
||||
assert policy_pubkey == roberto_policy.public_key
|
||||
|
|
|
@ -57,7 +57,7 @@ def test_generate_alice_keystore(temp_dir_path):
|
|||
bob_pubkey = SecretKey.random().public_key()
|
||||
signer = Signer(SecretKey.random())
|
||||
delegating_pubkey_again, _kfrags = delegating_power.generate_kfrags(
|
||||
bob_pubkey, signer, label, m=2, n=3
|
||||
bob_pubkey, signer, label, threshold=2, shares=3
|
||||
)
|
||||
|
||||
assert delegating_pubkey == delegating_pubkey_again
|
||||
|
|
|
@ -133,7 +133,7 @@ def test_alice_verifies_ursula_just_in_time(fleet_of_highperf_mocked_ursulas,
|
|||
stack.enter_context(mock)
|
||||
|
||||
policy = highperf_mocked_alice.grant(
|
||||
highperf_mocked_bob, b"any label", m=20, n=30,
|
||||
highperf_mocked_bob, b"any label", threshold=20, shares=30,
|
||||
expiration=maya.when('next week'),
|
||||
publish_treasure_map=False)
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ from tests.utils.ursula import make_federated_ursulas
|
|||
|
||||
|
||||
def test_alice_can_grant_even_when_the_first_nodes_she_tries_are_down(federated_alice, federated_bob, federated_ursulas):
|
||||
m, n = 2, 3
|
||||
threshold, shares = 2, 3
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
label = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
federated_alice.known_nodes.current_state._nodes = {}
|
||||
|
@ -47,8 +47,8 @@ def test_alice_can_grant_even_when_the_first_nodes_she_tries_are_down(federated_
|
|||
alice_grant_action = partial(federated_alice.grant,
|
||||
federated_bob,
|
||||
label,
|
||||
m=m,
|
||||
n=n,
|
||||
threshold=threshold,
|
||||
shares=shares,
|
||||
expiration=policy_end_datetime,
|
||||
timeout=.1)
|
||||
|
||||
|
@ -87,7 +87,7 @@ def test_alice_can_grant_even_when_the_first_nodes_she_tries_are_down(federated_
|
|||
# policy = alice_grant_action()
|
||||
|
||||
# The number of actually enacted arrangements is exactly equal to n.
|
||||
assert policy.n == n
|
||||
assert policy.shares == shares
|
||||
|
||||
|
||||
def test_node_has_changed_cert(federated_alice, federated_ursulas):
|
||||
|
|
|
@ -28,17 +28,17 @@ def random_federated_treasure_map_data(federated_alice, federated_bob, federated
|
|||
|
||||
label = b'policy label'
|
||||
threshold = 2
|
||||
num_kfrags = threshold + 1
|
||||
_policy_key, kfrags = federated_alice.generate_kfrags(bob=federated_bob, label=label, m=threshold, n=num_kfrags)
|
||||
shares = threshold + 1
|
||||
_policy_key, kfrags = federated_alice.generate_kfrags(bob=federated_bob, label=label, threshold=threshold, shares=shares)
|
||||
hrac = HRAC.derive(publisher_verifying_key=federated_alice.stamp.as_umbral_pubkey(),
|
||||
bob_verifying_key=federated_bob.stamp.as_umbral_pubkey(),
|
||||
label=label)
|
||||
random_treasure_map = TreasureMap.construct_by_publisher(hrac=hrac,
|
||||
publisher=federated_alice,
|
||||
bob=federated_bob,
|
||||
ursulas=list(federated_ursulas)[:num_kfrags],
|
||||
ursulas=list(federated_ursulas)[:shares],
|
||||
verified_kfrags=kfrags,
|
||||
m=threshold)
|
||||
threshold=threshold)
|
||||
|
||||
enc_treasure_map = random_treasure_map.encrypt(publisher=federated_alice,
|
||||
bob=federated_bob)
|
||||
|
|
|
@ -75,8 +75,8 @@ INSECURE_PASSWORD: str = "METRICS_INSECURE_DEVELOPMENT_PASSWORD"
|
|||
TEMP_ALICE_DIR: Path = Path('/', 'tmp', 'grant-metrics')
|
||||
|
||||
# Policy Parameters
|
||||
M: int = 1
|
||||
N: int = 1
|
||||
THRESHOLD: int = 1
|
||||
SHARES: int = 1
|
||||
RATE: Wei = Web3.toWei(50, 'gwei')
|
||||
DURATION: datetime.timedelta = datetime.timedelta(days=1)
|
||||
|
||||
|
@ -112,7 +112,8 @@ def metric_grant(alice, handpicked_ursulas: Optional[Set[Ursula]] = None) -> Pol
|
|||
"""Perform a granting operation for metrics collection."""
|
||||
label = f'{LABEL_PREFIX}{LABEL_SUFFIXER()}'.encode()
|
||||
policy_end_datetime = maya.now() + DURATION
|
||||
policy = alice.grant(m=M, n=N,
|
||||
policy = alice.grant(threshold=THRESHOLD,
|
||||
shares=SHARES,
|
||||
handpicked_ursulas=handpicked_ursulas,
|
||||
expiration=policy_end_datetime,
|
||||
bob=BOB,
|
||||
|
|
|
@ -40,7 +40,7 @@ def test_complete_treasure_map_journey(federated_alice, federated_bob, federated
|
|||
bob=federated_bob,
|
||||
ursulas=ursulas,
|
||||
verified_kfrags=kfrags,
|
||||
m=1)
|
||||
threshold=1)
|
||||
|
||||
ursula_rolodex = {u.checksum_address: u for u in ursulas}
|
||||
for ursula_address, encrypted_kfrag in treasure_map.destinations.items():
|
||||
|
@ -71,7 +71,7 @@ def test_complete_treasure_map_journey(federated_alice, federated_bob, federated
|
|||
decrypted_map = federated_bob._decrypt_treasure_map(enc_deserialized_map,
|
||||
federated_alice.stamp.as_umbral_pubkey())
|
||||
|
||||
assert treasure_map.m == decrypted_map.m == 1
|
||||
assert treasure_map.threshold == decrypted_map.threshold == 1
|
||||
assert treasure_map.destinations == decrypted_map.destinations
|
||||
assert treasure_map.hrac == decrypted_map.hrac
|
||||
|
||||
|
@ -93,7 +93,7 @@ def test_treasure_map_versioning(mocker, federated_alice, federated_bob, federat
|
|||
label=b'still Bill',
|
||||
ursulas=list(federated_ursulas)[:len(kfrags)],
|
||||
verified_kfrags=kfrags,
|
||||
m=2)
|
||||
threshold=2)
|
||||
|
||||
# Good version (baseline)
|
||||
serialized_map = bytes(treasure_map)
|
||||
|
|
Loading…
Reference in New Issue