def test_hash_bytes(self):
     self.assertEqual(
         crypto.hash_bytes(sha256, b"some data"), b"\x13\x07\x99\x0ek\xa5\xca\x14^\xb3^\x99\x18*\x9b\xecFS\x1b\xc5M\xdfej`,x\x0f\xa0$\r\xee"
     )
     self.assertEqual(
         crypto.hash_bytes(sha3_256, b"some data"), b"Y3\xe9'1f\x93Jn\xba\xafX\x17\x10tG\x93\t\xa7\xde\x84`|E\x0b\x01\xc2e\xb3\x08\x17\x12"
     )
     self.assertEqual(
         crypto.hash_bytes(blake2b, b"some data"), b"\x10\x1e\x81\x93\x91x\xf8Jn\x89o\xe1\xc2c\x8fo\x9e\x16q\x1d\x94,N\xfe\xc6\xf2\x8du\x19\xc1{W"
     )
Example #2
0
 def make_binance_signature(self, content: bytes) -> str:
     """Make a generic signature for some bytes of data
     Args:
         content: json bytes to sign
     Returns:
         base64 encoded signature string
     Raises:
         RuntimeError when no private key is set
     """
     if self.priv is None:
         raise RuntimeError("No private key has been set for signing")
     message = crypto.hash_bytes(hash_type=crypto.SupportedHashes.sha256,
                                 bytes_param=content)
     return crypto.encrypt_secp256k1_message_compact(self.priv, message)
Example #3
0
def get_deadline_key(item_as_bytes: bytes) -> str:
    unique_id = crypto.hash_bytes(crypto.SupportedHashes.sha256, item_as_bytes)
    return f"dc:tx:deadline:{base64.b64encode(unique_id).decode('ascii')}"