本文整理汇总了Python中sha3.sha3_256方法的典型用法代码示例。如果您正苦于以下问题:Python sha3.sha3_256方法的具体用法?Python sha3.sha3_256怎么用?Python sha3.sha3_256使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sha3
的用法示例。
在下文中一共展示了sha3.sha3_256方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sha3
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def sha3(seed):
return sha3_256(to_string(seed))
# assert encode_hex(sha3(b'')) == b'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
#def normalize_address(x, allow_blank=False):
# if is_numeric(x):
# return int_to_addr(x)
# if allow_blank and x in {'', b''}:
# return b''
# if len(x) in (42, 50) and x[:2] in {'0x', b'0x'}:
# x = x[2:]
# if len(x) in (40, 48):
# x = decode_hex(x)
# if len(x) == 24:
# assert len(x) == 24 and sha3(x[:20])[:4] == x[-4:]
# x = x[:20]
# if len(x) != 20:
# raise Exception("Invalid address format: %r" % x)
# return x
示例2: test_validate_tx_simple_create_signature
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def test_validate_tx_simple_create_signature(user_input, user_output, user_priv,
asset_definition):
from bigchaindb.common.transaction import Transaction
from .utils import validate_transaction_model
tx = Transaction(Transaction.CREATE, asset_definition, [user_input], [user_output])
expected = deepcopy(user_output)
tx_dict = tx.to_dict()
tx_dict['inputs'][0]['fulfillment'] = None
serialized_tx = json.dumps(tx_dict, sort_keys=True,
separators=(',', ':'), ensure_ascii=True)
message = sha3_256(serialized_tx.encode()).digest()
expected.fulfillment.sign(message, b58decode(user_priv))
tx.sign([user_priv])
assert tx.inputs[0].to_dict()['fulfillment'] == \
expected.fulfillment.serialize_uri()
assert tx.inputs_valid() is True
validate_transaction_model(tx)
示例3: test_fulfill_transaction
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def test_fulfill_transaction(alice_transaction, alice_sk):
from bigchaindb_driver.offchain import fulfill_transaction
fulfilled_transaction = fulfill_transaction(
alice_transaction, private_keys=alice_sk)
inputs = fulfilled_transaction['inputs']
assert len(inputs) == 1
alice_transaction['inputs'][0]['fulfillment'] = None
message = rapidjson.dumps(
alice_transaction,
skipkeys=False,
ensure_ascii=False,
sort_keys=True,
)
message = sha3_256(message.encode())
fulfillment_uri = inputs[0]['fulfillment']
assert Fulfillment.from_uri(fulfillment_uri).\
validate(message=message.digest())
示例4: has_sha3
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def has_sha3():
return 'sha3_256' in hashlib.algorithms_available
示例5: sha3_256_mod
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def sha3_256_mod():
if has_sha3():
return hashlib.sha3_256
else:
try:
import sha3
except ModuleNotFoundError:
cmd = "python3 -m pip install --user pysha3"
print("try to install pysha3 with following command:")
print(cmd)
subprocess.run(cmd.split(), check=True)
import sha3
return sha3.sha3_256
示例6: _sha3_256
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def _sha3_256(x):
return _sha3.sha3_256(x).digest()
示例7: sha3_256
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def sha3_256(x):
return hash_words(lambda v: sha3.sha3_256(v).digest(), 32, x)
示例8: hashimoto
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def hashimoto(header, nonce, full_size, dataset_lookup):
n = full_size / HASH_BYTES
w = MIX_BYTES // WORD_BYTES
mixhashes = MIX_BYTES / HASH_BYTES
# combine header+nonce into a 64 byte seed
s = sha3_512(header + nonce[::-1])
# start the mix with replicated s
mix = []
for _ in range(MIX_BYTES / HASH_BYTES):
mix.extend(s)
# mix in random dataset nodes
for i in range(ACCESSES):
p = fnv(i ^ s[0], mix[i % w]) % (n // mixhashes) * mixhashes
newdata = []
for j in range(MIX_BYTES / HASH_BYTES):
newdata.extend(dataset_lookup(p + j))
mix = list(map(fnv, mix, newdata))
# compress mix
cmix = []
for i in range(0, len(mix), 4):
cmix.append(fnv(fnv(fnv(mix[i], mix[i + 1]), mix[i + 2]), mix[i + 3]))
return {
"mix digest": serialize_hash(cmix),
"result": serialize_hash(sha3_256(s + cmix)),
}
# light-way to hash the header. Mainly used to verify a hash of data is
# correct when a new block is announced
示例9: get_seedhash
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def get_seedhash(block):
s = "\x00" * 32
for i in range(block.number // EPOCH_LENGTH):
s = serialize_hash(sha3_256(s))
return s
示例10: sha3_256
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def sha3_256(x):
return hashlib.sha3_256(x).digest()
示例11: sha3
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def sha3(seed):
return sha3_256(seed).digest()
示例12: web3_sha3
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def web3_sha3(self, value, encoding='hex'):
logger.info('web3_sha3')
if encoding == 'hex':
value = decode_hex(value)
else:
value = force_bytes(value)
return encode_32bytes(keccak_256(value).digest())
示例13: test_tx_serialization_hash_function
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def test_tx_serialization_hash_function(signed_create_tx):
tx = signed_create_tx.to_dict()
tx['id'] = None
payload = json.dumps(tx, skipkeys=False, sort_keys=True,
separators=(',', ':'))
assert sha3.sha3_256(payload.encode()).hexdigest() == signed_create_tx.id
示例14: test_create_tx_no_asset_data
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def test_create_tx_no_asset_data(b, create_tx, alice):
tx_body = create_tx.to_dict()
del tx_body['asset']['data']
tx_serialized = json.dumps(
tx_body, skipkeys=False, sort_keys=True, separators=(',', ':'))
tx_body['id'] = sha3.sha3_256(tx_serialized.encode()).hexdigest()
validate_raises(tx_body)
################################################################################
# Inputs
示例15: test_post_create_transaction_with_invalid_signature
# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import sha3_256 [as 别名]
def test_post_create_transaction_with_invalid_signature(mock_logger,
b,
client):
from bigchaindb.common.exceptions import InvalidSignature
from bigchaindb.models import Transaction
user_priv, user_pub = crypto.generate_key_pair()
tx = Transaction.create([user_pub], [([user_pub], 1)]).to_dict()
tx['inputs'][0]['fulfillment'] = 64 * '0'
tx['id'] = sha3_256(
json.dumps(
tx,
sort_keys=True,
separators=(',', ':'),
ensure_ascii=False,
).encode(),
).hexdigest()
res = client.post(TX_ENDPOINT, data=json.dumps(tx))
expected_status_code = 400
expected_error_message = (
'Invalid transaction ({}): Fulfillment URI '
'couldn\'t been parsed'
).format(InvalidSignature.__name__)
assert res.status_code == expected_status_code
assert res.json['message'] == expected_error_message
assert mock_logger.error.called
assert (
'HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s' in
mock_logger.error.call_args[0]
)
assert (
{
'message': expected_error_message, 'status': expected_status_code,
'method': 'POST', 'path': TX_ENDPOINT
} in mock_logger.error.call_args[0]
)
# TODO put back caplog based asserts once possible
# assert caplog.records[0].args['status'] == expected_status_code
# assert caplog.records[0].args['message'] == expected_error_message