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")
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
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
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(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")
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 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")
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
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
def test_invalid_params(self): k, _ = generate_key_pair(3) with self.assertRaises(InvalidParamsError): private_key = ServerIDPrivateKey( k, "sk32Tee5C4fCkbjbN4zc4VPkr9vX4xg8n53XQuWZx6xAKm2cAP7gv" ) # NOQA