Пример #1
0
        def get_specification(self,
                              ursula_pubkey,
                              alice_address,
                              blockhash,
                              ursula_identity_evidence=b''):
            ursula_pubkey = bytes(ursula_pubkey)
            ursula_identity_evidence = bytes(ursula_identity_evidence)
            alice_address = bytes(alice_address)
            blockhash = bytes(blockhash)

            expected_lengths = (
                (ursula_pubkey, 'ursula_pubkey',
                 UmbralPublicKey.expected_bytes_length()),
                (alice_address, 'alice_address', ETH_ADDRESS_BYTE_LENGTH),
                (blockhash, 'blockhash', ETH_HASH_BYTE_LENGTH),
                # TODO: Why does ursula_identity_evidence has a default value of b''? for federated, perhaps?
            )

            for parameter, name, expected_length in expected_lengths:
                if len(parameter) != expected_length:
                    raise ValueError(
                        f"{name} must be of length {expected_length}, but it's {len(parameter)}"
                    )

            task_specification = (bytes(self.capsule), ursula_pubkey,
                                  ursula_identity_evidence, alice_address,
                                  blockhash)
            return b''.join(task_specification)
Пример #2
0
def test_public_key_as_hex(random_ec_curvebn1):
    pubkey = UmbralPrivateKey(random_ec_curvebn1, default_params()).get_pubkey()
    hex_string = pubkey.hex()

    assert set(hex_string).issubset(set(string.hexdigits))
    assert len(hex_string) == 2 * UmbralPublicKey.expected_bytes_length()

    decoded_pubkey = UmbralPublicKey.from_hex(hex_string)

    assert pubkey == decoded_pubkey

    hex_string = pubkey.hex(is_compressed=False)

    assert set(hex_string).issubset(set(string.hexdigits))
    assert len(hex_string) == 2 * UmbralPublicKey.expected_bytes_length(is_compressed=False)

    decoded_pubkey = UmbralPublicKey.from_hex(hex_string)
    assert pubkey == decoded_pubkey