mirror of https://github.com/nucypher/nucypher.git
Update code to use newly named Session key objects in `nucypher-core`.
Modify ape-config to use `nucypher-contracts:main` now that associated PR was merged.pull/3134/head
parent
7c79a76296
commit
c2edb1ceb1
|
@ -8,7 +8,7 @@ from hexbytes import HexBytes
|
|||
from nucypher_core import (
|
||||
EncryptedThresholdDecryptionRequest,
|
||||
EncryptedThresholdDecryptionResponse,
|
||||
RequestPublicKey,
|
||||
SessionStaticKey,
|
||||
ThresholdDecryptionRequest,
|
||||
ThresholdDecryptionResponse,
|
||||
)
|
||||
|
@ -609,7 +609,7 @@ class Ritualist(BaseActor):
|
|||
def encrypt_threshold_decryption_response(
|
||||
self,
|
||||
decryption_response: ThresholdDecryptionResponse,
|
||||
requester_public_key: RequestPublicKey,
|
||||
requester_public_key: SessionStaticKey,
|
||||
) -> EncryptedThresholdDecryptionResponse:
|
||||
return self.threshold_request_power.encrypt_decryption_response(
|
||||
decryption_response=decryption_response,
|
||||
|
|
|
@ -10,8 +10,8 @@ from constant_sorrow.constants import CONTRACT_ATTRIBUTE # type: ignore
|
|||
from constant_sorrow.constants import CONTRACT_CALL, TRANSACTION
|
||||
from eth_typing.evm import ChecksumAddress
|
||||
from eth_utils.address import to_checksum_address
|
||||
from nucypher_core import SessionStaticKey
|
||||
from nucypher_core.ferveo import AggregatedTranscript, DkgPublicKey, Transcript
|
||||
from nucypher_core import RequestPublicKey
|
||||
from web3.contract.contract import Contract, ContractFunction
|
||||
from web3.types import Timestamp, TxParams, TxReceipt, Wei
|
||||
|
||||
|
@ -617,10 +617,10 @@ class CoordinatorAgent(EthereumContractAgent):
|
|||
return len(self.providers)
|
||||
|
||||
@property
|
||||
def participant_public_keys(self) -> Dict[ChecksumAddress, RequestPublicKey]:
|
||||
def participant_public_keys(self) -> Dict[ChecksumAddress, SessionStaticKey]:
|
||||
participant_public_keys = {}
|
||||
for p in self.participants:
|
||||
participant_public_keys[p.provider] = RequestPublicKey.from_bytes(
|
||||
participant_public_keys[p.provider] = SessionStaticKey.from_bytes(
|
||||
p.decryption_request_static_key
|
||||
)
|
||||
|
||||
|
@ -724,7 +724,7 @@ class CoordinatorAgent(EthereumContractAgent):
|
|||
ritual_id: int,
|
||||
aggregated_transcript: AggregatedTranscript,
|
||||
public_key: DkgPublicKey,
|
||||
participant_public_key: RequestPublicKey,
|
||||
participant_public_key: SessionStaticKey,
|
||||
transacting_power: TransactingPower,
|
||||
) -> TxReceipt:
|
||||
contract_function: ContractFunction = self.contract.functions.postAggregation(
|
||||
|
|
|
@ -40,8 +40,8 @@ from nucypher_core import (
|
|||
NodeMetadata,
|
||||
NodeMetadataPayload,
|
||||
ReencryptionResponse,
|
||||
RequestPublicKey,
|
||||
RequestSecretKey,
|
||||
SessionStaticKey,
|
||||
SessionStaticSecret,
|
||||
ThresholdDecryptionRequest,
|
||||
TreasureMap,
|
||||
)
|
||||
|
@ -588,7 +588,7 @@ class Bob(Character):
|
|||
def get_decryption_shares_using_existing_decryption_request(
|
||||
self,
|
||||
decryption_request: ThresholdDecryptionRequest,
|
||||
participant_public_keys: Dict[ChecksumAddress, RequestPublicKey],
|
||||
participant_public_keys: Dict[ChecksumAddress, SessionStaticKey],
|
||||
variant: FerveoVariant,
|
||||
cohort: List["Ursula"],
|
||||
threshold: int,
|
||||
|
@ -601,7 +601,7 @@ class Bob(Character):
|
|||
share_type = DecryptionShareSimple
|
||||
|
||||
# use ephemeral key for request
|
||||
requester_sk = RequestSecretKey.random()
|
||||
requester_sk = SessionStaticSecret.random()
|
||||
requester_public_key = requester_sk.public_key()
|
||||
|
||||
decryption_request_mapping = {}
|
||||
|
@ -648,7 +648,7 @@ class Bob(Character):
|
|||
lingo: LingoList,
|
||||
threshold: int,
|
||||
variant: FerveoVariant,
|
||||
participant_public_keys: Dict[ChecksumAddress, RequestPublicKey],
|
||||
participant_public_keys: Dict[ChecksumAddress, SessionStaticKey],
|
||||
context: Optional[dict] = None,
|
||||
) -> Dict[
|
||||
ChecksumAddress, Union[DecryptionShareSimple, DecryptionSharePrecomputed]
|
||||
|
|
|
@ -12,8 +12,8 @@ from typing import Callable, ClassVar, Dict, List, Optional, Tuple, Union
|
|||
import click
|
||||
from constant_sorrow.constants import KEYSTORE_LOCKED
|
||||
from mnemonic.mnemonic import Mnemonic
|
||||
from nucypher_core import SessionSecretFactory
|
||||
from nucypher_core.ferveo import Keypair
|
||||
from nucypher_core import RequestKeyFactory
|
||||
from nucypher_core.umbral import SecretKeyFactory
|
||||
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
|
||||
|
@ -436,10 +436,15 @@ class Keystore:
|
|||
power = power_class(keypair=keypair, *power_args, **power_kwargs)
|
||||
|
||||
elif issubclass(power_class, ThresholdRequestDecryptingPower):
|
||||
parent_skf = RequestKeyFactory.from_secure_randomness(self.__secret)
|
||||
child_skf = parent_skf.make_factory(_THRESHOLD_REQUEST_DECRYPTING_INFO)
|
||||
# TODO is this really how we want
|
||||
# to derive the session factory (similar to RitualisticPower)
|
||||
size = SessionSecretFactory.seed_size()
|
||||
secret = __skf.make_secret(info)[:size]
|
||||
session_secret_factory = SessionSecretFactory.from_secure_randomness(secret)
|
||||
power = power_class(
|
||||
request_key_factory=child_skf, *power_args, **power_kwargs
|
||||
session_secret_factory=session_secret_factory,
|
||||
*power_args,
|
||||
**power_kwargs,
|
||||
)
|
||||
|
||||
elif issubclass(power_class, DerivedKeyBasedPower):
|
||||
|
|
|
@ -7,11 +7,12 @@ from hexbytes import HexBytes
|
|||
from nucypher_core import (
|
||||
EncryptedThresholdDecryptionRequest,
|
||||
EncryptedThresholdDecryptionResponse,
|
||||
RequestKeyFactory,
|
||||
RequestPublicKey,
|
||||
RequestSecretKey,
|
||||
SessionSecretFactory,
|
||||
SessionStaticKey,
|
||||
SessionStaticSecret,
|
||||
ThresholdDecryptionRequest,
|
||||
ThresholdDecryptionResponse,
|
||||
ferveo,
|
||||
)
|
||||
from nucypher_core.ferveo import (
|
||||
AggregatedTranscript,
|
||||
|
@ -339,26 +340,26 @@ class ThresholdRequestDecryptingPower(DerivedKeyBasedPower):
|
|||
class ThresholdResponseEncryptionFailed(Exception):
|
||||
"""Raised when encryption of response to request fails."""
|
||||
|
||||
def __init__(self, request_key_factory: Optional[RequestKeyFactory] = None):
|
||||
if not request_key_factory:
|
||||
request_key_factory = RequestKeyFactory.random()
|
||||
self.__request_key_factory = request_key_factory
|
||||
def __init__(self, session_secret_factory: Optional[SessionSecretFactory] = None):
|
||||
if not session_secret_factory:
|
||||
session_secret_factory = SessionSecretFactory.random()
|
||||
self.__request_key_factory = session_secret_factory
|
||||
|
||||
def _get_secret_key_from_ritual_id(self, ritual_id: int) -> RequestSecretKey:
|
||||
def _get_static_secret_from_ritual_id(self, ritual_id: int) -> SessionStaticSecret:
|
||||
return self.__request_key_factory.make_key(bytes(ritual_id))
|
||||
|
||||
def get_pubkey_from_ritual_id(self, ritual_id: int) -> RequestPublicKey:
|
||||
return self._get_secret_key_from_ritual_id(ritual_id).public_key()
|
||||
def get_pubkey_from_ritual_id(self, ritual_id: int) -> SessionStaticKey:
|
||||
return self._get_static_secret_from_ritual_id(ritual_id).public_key()
|
||||
|
||||
def decrypt_encrypted_request(
|
||||
self, encrypted_request: EncryptedThresholdDecryptionRequest
|
||||
) -> ThresholdDecryptionRequest:
|
||||
try:
|
||||
secret_key = self._get_secret_key_from_ritual_id(
|
||||
static_secret = self._get_static_secret_from_ritual_id(
|
||||
encrypted_request.ritual_id
|
||||
)
|
||||
requester_public_key = encrypted_request.requester_public_key
|
||||
shared_secret = secret_key.derive_shared_secret(requester_public_key)
|
||||
shared_secret = static_secret.derive_shared_secret(requester_public_key)
|
||||
decrypted_request = encrypted_request.decrypt(shared_secret)
|
||||
return decrypted_request
|
||||
except Exception as e:
|
||||
|
@ -367,13 +368,13 @@ class ThresholdRequestDecryptingPower(DerivedKeyBasedPower):
|
|||
def encrypt_decryption_response(
|
||||
self,
|
||||
decryption_response: ThresholdDecryptionResponse,
|
||||
requester_public_key: RequestPublicKey,
|
||||
requester_public_key: SessionStaticKey,
|
||||
) -> EncryptedThresholdDecryptionResponse:
|
||||
try:
|
||||
secret_key = self._get_secret_key_from_ritual_id(
|
||||
static_secret = self._get_static_secret_from_ritual_id(
|
||||
decryption_response.ritual_id
|
||||
)
|
||||
shared_secret = secret_key.derive_shared_secret(requester_public_key)
|
||||
shared_secret = static_secret.derive_shared_secret(requester_public_key)
|
||||
encrypted_decryption_response = decryption_response.encrypt(shared_secret)
|
||||
return encrypted_decryption_response
|
||||
except Exception as e:
|
||||
|
|
|
@ -56,7 +56,7 @@ msgpack==1.0.5
|
|||
msgpack-python==0.5.6
|
||||
multidict==5.2.0 ; python_version >= '3.6'
|
||||
mypy-extensions==0.4.4 ; python_version >= '2.7'
|
||||
nucypher-core @ git+https://github.com/derekpierre/nucypher-core.git@9f86a761a5bdf10080535bbe9d3371ca3aae5b96#subdirectory=nucypher-core-python
|
||||
nucypher-core @ git+https://github.com/derekpierre/nucypher-core.git@253dfde60e6106ceeda696b86cb2f605ce3cd557#subdirectory=nucypher-core-python
|
||||
packaging==23.1 ; python_version >= '3.7'
|
||||
parsimonious==0.9.0
|
||||
pendulum==3.0.0a1 ; python_version >= '3.7' and python_version < '4.0'
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
|
||||
import pytest
|
||||
from eth_utils import keccak
|
||||
from nucypher_core import RequestSecretKey
|
||||
from nucypher_core import SessionStaticSecret
|
||||
|
||||
from nucypher.blockchain.eth.agents import (
|
||||
ContractAgency,
|
||||
|
@ -127,7 +127,7 @@ def test_post_aggregation(
|
|||
ritual_id = agent.number_of_rituals() - 1
|
||||
participant_public_keys = {}
|
||||
for i, transacting_power in enumerate(transacting_powers):
|
||||
participant_public_key = RequestSecretKey.random().public_key()
|
||||
participant_public_key = SessionStaticSecret.random().public_key()
|
||||
receipt = agent.post_aggregation(
|
||||
ritual_id=ritual_id,
|
||||
aggregated_transcript=aggregated_transcript,
|
||||
|
|
|
@ -6,8 +6,8 @@ plugins:
|
|||
dependencies:
|
||||
# TODO change back to nucypher/nucypher-contracts once https://github.com/nucypher/nucypher-contracts/pull/84 is merged
|
||||
- name: nucypher-contracts
|
||||
github: derekpierre/nucypher-contracts
|
||||
ref: 25519
|
||||
github: nucypher/nucypher-contracts
|
||||
ref: main
|
||||
- name: openzeppelin
|
||||
github: OpenZeppelin/openzeppelin-contracts
|
||||
version: 4.8.1
|
||||
|
|
|
@ -6,7 +6,7 @@ from cryptography.hazmat.primitives.serialization import Encoding
|
|||
from flask import Flask
|
||||
from nucypher_core import (
|
||||
Conditions,
|
||||
RequestSecretKey,
|
||||
SessionStaticSecret,
|
||||
ThresholdDecryptionRequest,
|
||||
ThresholdDecryptionResponse,
|
||||
)
|
||||
|
@ -187,7 +187,7 @@ def test_ritualist(temp_dir_path, testerchain, dkg_public_key):
|
|||
ursula.threshold_request_power.get_pubkey_from_ritual_id(ritual_id=ritual_id)
|
||||
)
|
||||
|
||||
requester_sk = RequestSecretKey.random()
|
||||
requester_sk = SessionStaticSecret.random()
|
||||
requester_public_key = requester_sk.public_key()
|
||||
shared_secret = requester_sk.derive_shared_secret(ursula_request_public_key)
|
||||
encrypted_decryption_request = decryption_request.encrypt(
|
||||
|
@ -204,7 +204,7 @@ def test_ritualist(temp_dir_path, testerchain, dkg_public_key):
|
|||
|
||||
# failed encryption - incorrect encrypting key used
|
||||
invalid_encrypted_decryption_request = decryption_request.encrypt(
|
||||
shared_secret=RequestSecretKey.random().derive_shared_secret(
|
||||
shared_secret=SessionStaticSecret.random().derive_shared_secret(
|
||||
ursula_request_public_key
|
||||
),
|
||||
requester_public_key=requester_public_key,
|
||||
|
|
|
@ -4,8 +4,8 @@ from typing import Dict, List
|
|||
|
||||
from eth_typing import ChecksumAddress
|
||||
from eth_utils import keccak
|
||||
from nucypher_core import SessionStaticKey
|
||||
from nucypher_core.ferveo import AggregatedTranscript, DkgPublicKey, Transcript
|
||||
from nucypher_core import RequestPublicKey
|
||||
from web3.types import TxReceipt
|
||||
|
||||
from nucypher.blockchain.eth.agents import CoordinatorAgent
|
||||
|
@ -112,7 +112,7 @@ class MockCoordinatorAgent(MockContractAgent):
|
|||
ritual_id: int,
|
||||
aggregated_transcript: AggregatedTranscript,
|
||||
public_key: DkgPublicKey,
|
||||
participant_public_key: RequestPublicKey,
|
||||
participant_public_key: SessionStaticKey,
|
||||
transacting_power: TransactingPower,
|
||||
) -> TxReceipt:
|
||||
ritual = self.rituals[ritual_id]
|
||||
|
|
|
@ -3,7 +3,7 @@ from unittest.mock import Mock
|
|||
|
||||
import pytest
|
||||
from eth_account import Account
|
||||
from nucypher_core import RequestSecretKey
|
||||
from nucypher_core import SessionStaticSecret
|
||||
|
||||
from tests.mock.coordinator import MockCoordinatorAgent
|
||||
from tests.mock.interfaces import MockBlockchain
|
||||
|
@ -109,7 +109,7 @@ def test_mock_coordinator_round_2(
|
|||
|
||||
participant_public_keys = []
|
||||
for index, node_address in enumerate(nodes_transacting_powers):
|
||||
participant_public_key = RequestSecretKey.random().public_key()
|
||||
participant_public_key = SessionStaticSecret.random().public_key()
|
||||
coordinator.post_aggregation(
|
||||
ritual_id=0,
|
||||
aggregated_transcript=aggregated_transcript,
|
||||
|
|
Loading…
Reference in New Issue