Example #1
0
    def from_public_keys(cls,
                         powers_and_material: Dict,
                         federated_only=True,
                         *args,
                         **kwargs) -> 'Character':
        # TODO: Need to be federated only until we figure out the best way to get the checksum_address in here.
        """
        Sometimes we discover a Character and, at the same moment,
        learn the public parts of more of their powers. Here, we take a Dict
        (powers_and_key_bytes) in the following format:
        {CryptoPowerUp class: public_material_bytes}

        Each item in the collection will have the CryptoPowerUp instantiated
        with the public_material_bytes, and the resulting CryptoPowerUp instance
        consumed by the Character.
        """
        crypto_power = CryptoPower()

        for power_up, public_key in powers_and_material.items():
            try:
                umbral_key = UmbralPublicKey(public_key)
            except TypeError:
                umbral_key = public_key

            crypto_power.consume_power_up(power_up(pubkey=umbral_key))

        return cls(is_me=False,
                   federated_only=federated_only,
                   crypto_power=crypto_power,
                   *args,
                   **kwargs)
Example #2
0
def test_public_key_to_uncompressed_bytes(random_ec_curvebn1):
    priv_key = random_ec_curvebn1

    params = default_params()
    pub_key = priv_key * params.g

    umbral_key = UmbralPublicKey(pub_key, params)
    key_bytes = umbral_key.to_bytes(is_compressed=False)
    assert len(key_bytes) == Point.expected_bytes_length(is_compressed=False)
Example #3
0
def test_public_key_serialization(random_ec_curvebn1):
    priv_key = random_ec_curvebn1

    params = default_params()
    pub_key = priv_key * params.g

    umbral_key = UmbralPublicKey(pub_key, params)

    encoded_key = umbral_key.to_bytes()

    decoded_key = UmbralPublicKey.from_bytes(encoded_key)
    assert pub_key == decoded_key.point_key
Example #4
0
    def from_public_keys(cls, powers_and_keys: Dict, *args, **kwargs):
        """
        Sometimes we discover a Character and, at the same moment, learn one or
        more of their public keys. Here, we take a Dict
        (powers_and_key_bytes) in the following format:
        {CryptoPowerUp class: public_key_bytes}

        Each item in the collection will have the CryptoPowerUp instantiated
        with the public_key_bytes, and the resulting CryptoPowerUp instance
        consumed by the Character.
        """
        crypto_power = CryptoPower()

        for power_up, public_key in powers_and_keys.items():
            try:
                umbral_key = UmbralPublicKey(public_key)
            except TypeError:
                umbral_key = public_key

            crypto_power.consume_power_up(power_up(pubkey=umbral_key))

        return cls(is_me=False, crypto_power=crypto_power, *args, **kwargs)
Example #5
0
def test_pubkey_roundtrip(p):
    k = UmbralPublicKey(p, params)
    assert(k == UmbralPublicKey.from_bytes(k.to_bytes(), params=params))