本文整理汇总了Python中eth_utils.keccak方法的典型用法代码示例。如果您正苦于以下问题:Python eth_utils.keccak方法的具体用法?Python eth_utils.keccak怎么用?Python eth_utils.keccak使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eth_utils
的用法示例。
在下文中一共展示了eth_utils.keccak方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sha3_256
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def sha3_256(x):
if isinstance(x, bytearray):
x = bytes(x)
if not isinstance(x, bytes):
raise RuntimeError("sha3_256 only accepts bytes or bytearray")
# TODO: keccak accepts more types than bytes
return keccak(x)
示例2: encrypt_string
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def encrypt_string(raw_string):
import base64
from cryptography.fernet import Fernet
from eth_utils import keccak
fernet_encryption_key = base64.b64encode(keccak(text=config.SECRET_KEY))
cipher_suite = Fernet(fernet_encryption_key)
return cipher_suite.encrypt(raw_string.encode('utf-8')).decode('utf-8')
示例3: decrypt_string
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def decrypt_string(encryped_string):
fernet_encryption_key = base64.b64encode(keccak(text=current_app.config['SECRET_KEY']))
cipher_suite = Fernet(fernet_encryption_key)
return cipher_suite.decrypt(encryped_string.encode('utf-8')).decode('utf-8')
示例4: encrypt_string
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def encrypt_string(raw_string):
fernet_encryption_key = base64.b64encode(keccak(text=current_app.config['SECRET_KEY']))
cipher_suite = Fernet(fernet_encryption_key)
return cipher_suite.encrypt(raw_string.encode('utf-8')).decode('utf-8')
示例5: decrypted_private_key
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def decrypted_private_key(self):
fernet_encryption_key = base64.b64encode(keccak(text=current_app.config['SECRET_KEY']))
cipher_suite = Fernet(fernet_encryption_key)
return cipher_suite.decrypt(self.encoded_private_key.encode('utf-8')).decode('utf-8')
示例6: encrypt_private_key
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def encrypt_private_key(self, unencoded_private_key):
fernet_encryption_key = base64.b64encode(keccak(text=current_app.config['SECRET_KEY']))
cipher_suite = Fernet(fernet_encryption_key)
return cipher_suite.encrypt(unencoded_private_key.encode('utf-8')).decode('utf-8')
示例7: _cipher_suite
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def _cipher_suite():
fernet_encryption_key = base64.b64encode(keccak(text=config.SECRET_KEY))
return Fernet(fernet_encryption_key)
示例8: __init__
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def __init__(self, private_key=None, wei_target_balance=None, wei_topup_threshold=None):
if private_key:
self.private_key = private_key
else:
self.private_key = Web3.toHex(keccak(os.urandom(4096)))
self.wei_target_balance = wei_target_balance
self.wei_topup_threshold = wei_topup_threshold
# https://stackoverflow.com/questions/20830118/creating-a-self-referencing-m2m-relationship-in-sqlalchemy-flask
示例9: _make_tx
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def _make_tx(w3, address, signature, values):
# helper function to broadcast transactions that fail clamping check
sig = keccak(signature.encode()).hex()[:8]
data = "".join(int(i).to_bytes(32, "big", signed=i < 0).hex() for i in values)
w3.eth.sendTransaction({"to": address, "data": f"0x{sig}{data}"})
示例10: factory
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def factory(get_contract):
with open("examples/factory/Exchange.vy") as f:
code = f.read()
exchange_interface = vyper.compile_code(code, output_formats=["bytecode_runtime"])
exchange_deployed_bytecode = exchange_interface["bytecode_runtime"]
with open("examples/factory/Factory.vy") as f:
code = f.read()
# NOTE: We deploy the factory with the hash of the exchange's expected deployment bytecode
return get_contract(code, keccak(hexstr=exchange_deployed_bytecode))
示例11: public_key_to_address
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def public_key_to_address(public_key: PublicKey) -> Address:
""" Converts a public key to an Ethereum address. """
key_bytes = public_key.format(compressed=False)
return Address(keccak(key_bytes[1:])[-20:])
示例12: private_keys
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def private_keys() -> List[PrivateKey]:
offset = 14789632
return [PrivateKey(keccak(offset + i)) for i in range(NUMBER_OF_NODES)]
示例13: get_pending_transfers_tree
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def get_pending_transfers_tree(
web3: Web3,
unlockable_amounts: Collection[int],
expired_amounts: Collection[int],
min_expiration_delta: Optional[int] = None,
max_expiration_delta: Optional[int] = None,
) -> PendingTransfersTree:
types = ["uint256", "uint256", "bytes32"]
packed_transfers = b""
(unlockable_locks, expired_locks) = get_pending_transfers(
web3=web3,
unlockable_amounts=unlockable_amounts,
expired_amounts=expired_amounts,
min_expiration_delta=min_expiration_delta,
max_expiration_delta=max_expiration_delta,
)
pending_transfers = unlockable_locks + expired_locks
hashed_pending_transfers = [
Web3.solidityKeccak(types, transfer_data[:-1]) # pylint: disable=E1120
for transfer_data in pending_transfers
]
if len(pending_transfers) > 0:
hashed_pending_transfers, pending_transfers = zip(
*sorted(zip(hashed_pending_transfers, pending_transfers))
)
pending_transfers = list(pending_transfers)
packed_transfers = get_packed_transfers(pending_transfers=pending_transfers, types=types)
locked_amount = get_locked_amount(pending_transfers)
return PendingTransfersTree(
transfers=pending_transfers,
unlockable=unlockable_locks,
expired=expired_locks,
packed_transfers=packed_transfers,
hash_of_packed_transfers=keccak(packed_transfers),
locked_amount=locked_amount,
)
示例14: get_participants_hash
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def get_participants_hash(A: HexAddress, B: HexAddress) -> bytes:
A_canonical = to_canonical_address(A)
B_canonical = to_canonical_address(B)
if A_canonical == B_canonical:
raise ValueError("get_participants_hash got the same address twice")
return (
keccak(A_canonical + B_canonical)
if A_canonical < B_canonical
else keccak(B_canonical + A_canonical)
)
示例15: hash
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import keccak [as 别名]
def hash(x): return keccak(x)