Пример #1
0
 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")
Пример #2
0
 def ec_priv_key(self, ec_priv_key):
     if isinstance(ec_priv_key, str):
         ec_priv_key = ECPrivateKey(key_string=ec_priv_key)
     elif isinstance(ec_priv_key, ECPrivateKey):
         pass
     else:
         raise InvalidParam
     self._ec_priv_key = ec_priv_key
     return self
Пример #3
0
 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
Пример #4
0
    def test_key_string_validity_checkers(self):
        # Valid pair. All zeros private key
        private = 'Es2Rf7iM6PdsqfYCo3D1tnAR65SkLENyWJG1deUzpRMQmbh9F3eG'
        public = 'EC2DKSYyRcNWf7RS963VFYgMExoHRYLHVeCfQ9PGPmNzwrcmgm2r'
        assert ECPrivateKey.is_valid(private)
        assert ECAddress.is_valid(public)

        # Bad prefix
        private = 'Xs2Rf7iM6PdsqfYCo3D1tnAR65SkLENyWJG1deUzpRMQmbh9F3eG'
        public = 'XC2DKSYyRcNWf7RS963VFYgMExoHRYLHVeCfQ9PGPmNzwrcmgm2r'
        assert not ECPrivateKey.is_valid(private)
        assert not ECAddress.is_valid(public)

        # Bad body
        private = 'Es2Rf7iM6PdsqfXXX3D1tnAR65SkLENyWJG1deUzpRMQmbh9F3eG'
        public = 'EC2DKSYyRcNWf7RXXX3VFYgMExoHRYLHVeCfQ9PGPmNzwrcmgm2r'
        assert not ECPrivateKey.is_valid(private)
        assert not ECAddress.is_valid(public)

        # Bad checksums
        private = 'Es2Rf7iM6PdsqfYCo3D1tnAR65SkLENyWJG1deUzpRMQmbh9F3eX'
        public = 'EC2DKSYyRcNWf7RS963VFYgMExoHRYLHVeCfQ9PGPmNzwrcmgm2X'
        assert not ECPrivateKey.is_valid(private)
        assert not ECAddress.is_valid(public)
Пример #5
0
    def test_issuance_set_ec_priv_key(self):
        issuance = Issuance()

        # Not a ECPrivateKey
        with raises(InvalidParam):
            issuance.ec_priv_key = 1110

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

        with raises(BadKeyEC):
            issuance.ec_priv_key = "not a ServerID key"

        ec_priv_key = ECPrivateKey(key_string="Es3w7m5KkGs97595YEiYouyjaJcsouHQr7cCLUrqKt6Y8LvWurAP")
        issuance.ec_priv_key = ec_priv_key
        assert issuance.ec_priv_key == ec_priv_key
Пример #6
0
    def test_key_imports_and_exports(self):
        private_bytes = b'\0' * 32
        private_string = 'Es2Rf7iM6PdsqfYCo3D1tnAR65SkLENyWJG1deUzpRMQmbh9F3eG'
        public_string = 'EC2DKSYyRcNWf7RS963VFYgMExoHRYLHVeCfQ9PGPmNzwrcmgm2r'

        private_from_bytes = ECPrivateKey(seed_bytes=private_bytes)
        private_from_string = ECPrivateKey(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_ec_address()
        public_from_string = ECAddress(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