Separating creation of decryption request from the actual retrieval flow, so that pre-serialized decryption requests can be used.

pull/3128/head
jMyles 2023-05-11 17:12:52 -04:00
parent e1dcaab7fb
commit 469ffc3e1e
1 changed files with 41 additions and 17 deletions

View File

@ -562,23 +562,14 @@ class Bob(Character):
return cohort
def gather_decryption_shares(
def make_decryption_request(
self,
ritual_id: int,
cohort: List["Ursula"],
ciphertext: Ciphertext,
lingo: LingoList,
threshold: int,
variant: FerveoVariant,
context: Optional[dict] = None,
) -> Dict[
ChecksumAddress, Union[DecryptionShareSimple, DecryptionSharePrecomputed]
]:
if variant == FerveoVariant.PRECOMPUTED:
share_type = DecryptionSharePrecomputed
elif variant == FerveoVariant.SIMPLE:
share_type = DecryptionShareSimple
) -> ThresholdDecryptionRequest:
conditions = Conditions(json.dumps(lingo))
if context:
context = Context(json.dumps(context))
@ -589,6 +580,18 @@ class Bob(Character):
conditions=conditions,
context=context,
)
return decryption_request
def get_decryption_shares_using_existing_decryption_request(self,
decryption_request: ThresholdDecryptionRequest,
variant: FerveoVariant,
cohort: List["Ursula"],
threshold: int,
):
if variant == FerveoVariant.PRECOMPUTED:
share_type = DecryptionSharePrecomputed
elif variant == FerveoVariant.SIMPLE:
share_type = DecryptionShareSimple
decryption_request_mapping = {}
for ursula in cohort:
@ -614,6 +617,27 @@ class Bob(Character):
gathered_shares[provider_address] = decryption_share
return gathered_shares
def gather_decryption_shares(
self,
ritual_id: int,
cohort: List["Ursula"],
ciphertext: Ciphertext,
lingo: LingoList,
threshold: int,
variant: FerveoVariant,
context: Optional[dict] = None,
) -> Dict[
ChecksumAddress, Union[DecryptionShareSimple, DecryptionSharePrecomputed]
]:
decryption_request = self.make_decryption_request(ritual_id=ritual_id,
ciphertext=ciphertext,
lingo=lingo,
variant=variant,
context=context)
return self.get_decryption_shares_using_existing_decryption_request(decryption_request, variant, cohort,
threshold)
def threshold_decrypt(self,
ritual_id: int,
ciphertext: Ciphertext,