Beispiel #1
0
    def test_sign_message(self):
        message = b"test message"
        signature = (
            b'h\xc4\xcc,\xb0x\xe1\x80/C\xf5\xd2\xf7A\xc9B"\x9f\xd9 \xaf\xe0\x0e\x0c\x1f'
            b"\xe7S\xa0\xd6z\xfaD\xfa\xcb!\x8f\xb8\r\xf7\x8c\xb9\x19z\x19\xfd\xc3Sf\xf0"
            b"\xff\x1e\x15l\xf9M\xb8$H\t\xc61\x0cD\x08")
        private_string = "sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU"
        private_key = ServerIDPrivateKey(key_string=private_string)

        assert private_key.sign(message) == signature
 def setup(self):
     # These are throwaway private keys.
     self.chain_id = "145d5207a1ca2978e2a1cb43c97d538cd516d65cd5d14579549664bfecd80296"
     self.issuer_id = "8888883beff463483a56398545cd02832c74bcdd9c468d61a79d6928f6208291"
     self.issuer_signer = ServerIDPrivateKey(key_string="sk12hDMpMzcm9XEdvcy77XwxYU57hpLoCMY1kHtKnyjdGWUpsAvXD")
     self.ec_address = ECAddress(key_string="EC3cQ1QnsE5rKWR1B5mzVHdTkAReK5kJwaQn5meXzU9wANyk7Aej")
     self.ec_priv_key = ECPrivateKey(key_string="Es3w7m5KkGs97595YEiYouyjaJcsouHQr7cCLUrqKt6Y8LvWurAP")
Beispiel #3
0
 def server_priv_key(self, server_priv_key):
     if isinstance(server_priv_key, str):
         server_priv_key = ServerIDPrivateKey(key_string=server_priv_key)
     elif isinstance(server_priv_key, ServerIDPrivateKey):
         pass
     else:
         raise InvalidParam
     self._server_priv_key = server_priv_key
     return self
 def issuance(self) -> Issuance:
     issuance = Issuance()
     issuance.token_id = "test"
     issuance.issuer_id = "888888a37cbf303c0bfc8d0cc7e77885c42000b757bd4d9e659de994477a0904"
     issuance.supply = -1
     issuance.symbol = "test"
     issuance.ec_priv_key = ECPrivateKey(key_string="Es3w7m5KkGs97595YEiYouyjaJcsouHQr7cCLUrqKt6Y8LvWurAP")
     issuance.server_priv_key = ServerIDPrivateKey(
         key_string="sk12hDMpMzcm9XEdvcy77XwxYU57hpLoCMY1kHtKnyjdGWUpsAvXD")
     return issuance
Beispiel #5
0
    def test_key_string_validity_checkers(self):
        # All zeros private key
        private_keys = [
            "sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU",
            "sk229KM7j76STogyvuoDSWn8rvT6bRB1VoSMHgC5KD8W88E26iQM3",
            "sk32Tee5C4fCkbjbN4zc4VPkr9vX4xg8n53XQuWZx6xAKm2cAP7gv",
            "sk42myw2f2Dy3PnCoEBzgU1NqPPwYWBG4LehY8q4azmpXPqGY6Bqu",
        ]

        public_keys = [
            "id12HQxrj9A4ESYVWqKDx7UC1gJfXpUJDVWt6wHem4fjyNyUKVUx2",
            "id22bkFpC6ipXEb6wzWca65ozun61MyRVm84EAc9PxVQB1n9T9KhD",
            "id32v5Ymf4Hap2diP9i1C4hRz9FWUuUYn2jEMPve2rK4NeajXGoUh",
            "id43EQqj81rM6pgKpJuPp3K3yNivxSyg4JLQUdF8fk8iaHPTTdSdA",
        ]

        for k, p in zip(private_keys, public_keys):
            assert ServerIDPrivateKey.is_valid(k)
            assert ServerIDPublicKey.is_valid(p)

        # Bad prefixes
        private = "sk51pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU"
        public = "ie11qFJ7fe26N29hrY3f1gUQC7UYArUg2GEy1rpPp2ExbnJdSj3mN"
        assert not ServerIDPrivateKey.is_valid(private)
        assert not ServerIDPublicKey.is_valid(public)

        # Bad bodies
        private = "sk11pz4AG9XgB1eNVkbppYYYYgyg7sftDXqBASsagKJqvVRKYodCU"
        public = "id11qFJ7fe26N29hrY3f1gYYY7UYArUg2GEy1rpPp2ExbnJdSj3mN"
        assert not ServerIDPrivateKey.is_valid(private)
        assert not ServerIDPublicKey.is_valid(public)

        # Bad checksums
        private = "sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCT"
        public = "id11qFJ7fe26N29hrY3f1gUQC7UYArUg2GEy1rpPp2ExbnJdSj3mP"
        assert not ServerIDPrivateKey.is_valid(private)
        assert not ServerIDPublicKey.is_valid(public)

        # Bad base58
        private = "sk11pz4AG9XgB1eNVkbpp+++sgyg7sftDXqBASsagKJqvVRKYodCU"
        public = "id11qFJ7fe26N29hrY3f1g0007UYArUg2GEy1rpPp2ExbnJdSj3mN"
        assert not ServerIDPrivateKey.is_valid(private)
        assert not ServerIDPublicKey.is_valid(public)
Beispiel #6
0
 def setup(cls):
     # These are throwaway private keys.
     cls.chain_id = "1e5037be95e108c34220d724763444098528e88d08ec30bc15204c98525c3f7d"
     cls.coinbase_address = "FA1zT4aFpEvcnPqPCigB3fvGu4Q4mTXY22iiuV69DqE1pNhdF2MC"
     cls.address1 = FactoidAddress(address_string="FA2gCmih3PaSYRVMt1jLkdG4Xpo2koebUpQ6FpRRnqw5FfTSN2vW")
     cls._private_fct_key1 = FactoidPrivateKey(key_string="Fs1fR4dMNdyp1a6qYfkLFPJZUyRg1uFW3b6NEK9VaRELD4qALstq")
     cls.address2 = FactoidAddress(address_string="FA3j68XNwKwvHXV2TKndxPpyCK3KrWTDyyfxzi8LwuM5XRuEmhy6")
     cls._private_fct_key2 = FactoidPrivateKey(key_string="Fs2jSmXgaysrqiADPmAvvb71NfAa9MqvXvRemozTE8LRc64hLqtf")
     cls.address3 = FactoidAddress(address_string="FA3rsxWx4WSN5Egj2ZxPoju1mzwfjBivTDMcEvoC1JSsqkddZPCB")
     cls._private_fct_key3 = FactoidPrivateKey(key_string="Fs2EDKpBA4QQgarTUhJnZeZ4HeymT5U6RSWGsoTtkt1ezGCmNdSo")
     cls._issuer_signer = ServerIDPrivateKey(key_string="sk12hDMpMzcm9XEdvcy77XwxYU57hpLoCMY1kHtKnyjdGWUpsAvXD")
Beispiel #7
0
    def test_key_imports_and_exports(self):
        private_bytes = b"\x00" * 32
        private_string = "sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU"
        public_string = "id12HQxrj9A4ESYVWqKDx7UC1gJfXpUJDVWt6wHem4fjyNyUKVUx2"

        private_from_bytes = ServerIDPrivateKey(seed_bytes=private_bytes)
        private_from_bytes.key_level = 1
        private_from_string = ServerIDPrivateKey(key_string=private_string)
        assert private_from_bytes.key_bytes == private_bytes
        assert private_from_string.key_bytes == private_bytes
        assert private_from_bytes.to_string() == private_string
        assert private_from_string.to_string() == private_string

        public_from_private = private_from_string.get_public_key()
        public_from_string = ServerIDPublicKey(key_string=public_string)
        assert public_from_private.key_bytes == public_from_string.key_bytes
        assert public_from_private.to_string() == public_string
        assert public_from_string.to_string() == public_string
Beispiel #8
0
 def setup(cls):
     # These are throwaway private keys.
     cls.chain_id = "145d5207a1ca2978e2a1cb43c97d538cd516d65cd5d14579549664bfecd80296"
     cls.address1 = FactoidAddress(
         address_string=
         "FA2gCmih3PaSYRVMt1jLkdG4Xpo2koebUpQ6FpRRnqw5FfTSN2vW")
     cls._private_fct_key1 = FactoidPrivateKey(
         key_string="Fs1fR4dMNdyp1a6qYfkLFPJZUyRg1uFW3b6NEK9VaRELD4qALstq")
     cls.address2 = FactoidAddress(
         address_string=
         "FA3j68XNwKwvHXV2TKndxPpyCK3KrWTDyyfxzi8LwuM5XRuEmhy6")
     cls._private_fct_key2 = FactoidPrivateKey(
         key_string="Fs2jSmXgaysrqiADPmAvvb71NfAa9MqvXvRemozTE8LRc64hLqtf")
     cls.address3 = FactoidAddress(
         address_string=
         "FA3rsxWx4WSN5Egj2ZxPoju1mzwfjBivTDMcEvoC1JSsqkddZPCB")
     cls._private_fct_key3 = FactoidPrivateKey(
         key_string="Fs2EDKpBA4QQgarTUhJnZeZ4HeymT5U6RSWGsoTtkt1ezGCmNdSo")
     cls._issue_signer = ServerIDPrivateKey(
         key_string="sk12hDMpMzcm9XEdvcy77XwxYU57hpLoCMY1kHtKnyjdGWUpsAvXD")
Beispiel #9
0
    def test_key_level(self):
        # Level 3 key
        private_key = ServerIDPrivateKey(
            key_string="sk32Tee5C4fCkbjbN4zc4VPkr9vX4xg8n53XQuWZx6xAKm2cAP7gv")
        assert private_key.key_level == 3
        public_key = private_key.get_public_key()
        assert public_key.key_level == 3
        private_key.key_level = 4
        assert private_key.key_level == 4 and public_key.key_level == 3

        with self.assertRaises(InvalidKeyLevelError):
            private_key.key_level = 5

        with self.assertRaises(InvalidKeyLevelError):
            private_key.key_level = -1
    def test_issuance_set_server_priv_key(self):
        issuance = Issuance()

        # Not a ServerIDPrivateKey or str
        with raises(InvalidParam):
            issuance.server_priv_key = 1110

        with raises(InvalidParam):
            issuance.server_priv_key = b"1010101"

        with raises(BadKeyID):
            issuance.server_priv_key = "not a ServerID key"

        server_priv_key = "sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU"
        issuance.server_priv_key = server_priv_key
        assert isinstance(issuance.server_priv_key, ServerIDPrivateKey)
        assert issuance.server_priv_key.to_string() == "sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU"

        server_priv_key = ServerIDPrivateKey(key_string="sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU")
        issuance.server_priv_key = server_priv_key
        assert issuance.server_priv_key == server_priv_key
Beispiel #11
0
    def validate_signer(
        self, signer: Union[FactoidPrivateKey, ServerIDPrivateKey, str]
    ) -> Union[FactoidPrivateKey, ServerIDPrivateKey]:
        """
        Validate a privatekey and convert it to a str.

        :param signer: a signing key as a FactoidPrivateKey, ServerIDPrivateKey or a str
        """

        if self.is_mint():
            if isinstance(signer, str):
                signer = ServerIDPrivateKey(signer)
            elif isinstance(signer, ServerIDPrivateKey):
                pass
            else:
                raise InvalidParam("Invalid signer key for transaction type!")
        else:
            if isinstance(signer, str):
                signer = FactoidPrivateKey(signer)
            elif isinstance(signer, FactoidPrivateKey):
                pass
            else:
                raise InvalidParam("Invalid signer key for transaction type!")
        return signer
Beispiel #12
0
 def test_invalid_params(self):
     k, _ = generate_key_pair(3)
     with self.assertRaises(InvalidParamsError):
         private_key = ServerIDPrivateKey(
             k, "sk32Tee5C4fCkbjbN4zc4VPkr9vX4xg8n53XQuWZx6xAKm2cAP7gv"
         )  # NOQA