當前位置: 首頁>>代碼示例>>Python>>正文


Python sha3.sha3_256方法代碼示例

本文整理匯總了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 
開發者ID:hyperledger,項目名稱:indy-plenum,代碼行數:24,代碼來源:utils.py

示例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) 
開發者ID:bigchaindb,項目名稱:bigchaindb,代碼行數:22,代碼來源:test_transaction.py

示例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()) 
開發者ID:bigchaindb,項目名稱:bigchaindb-driver,代碼行數:19,代碼來源:test_offchain.py

示例4: has_sha3

# 需要導入模塊: import sha3 [as 別名]
# 或者: from sha3 import sha3_256 [as 別名]
def has_sha3():
    return 'sha3_256' in hashlib.algorithms_available 
開發者ID:yuan-xy,項目名稱:libra-client,代碼行數:4,代碼來源:key_factory.py

示例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 
開發者ID:yuan-xy,項目名稱:libra-client,代碼行數:15,代碼來源:key_factory.py

示例6: _sha3_256

# 需要導入模塊: import sha3 [as 別名]
# 或者: from sha3 import sha3_256 [as 別名]
def _sha3_256(x):
        return _sha3.sha3_256(x).digest() 
開發者ID:QuarkChain,項目名稱:pyquarkchain,代碼行數:4,代碼來源:ethash_utils.py

示例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) 
開發者ID:QuarkChain,項目名稱:pyquarkchain,代碼行數:4,代碼來源:ethash.py

示例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 
開發者ID:QuarkChain,項目名稱:pyquarkchain,代碼行數:31,代碼來源:ethash.py

示例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 
開發者ID:QuarkChain,項目名稱:pyquarkchain,代碼行數:7,代碼來源:ethash.py

示例10: sha3_256

# 需要導入模塊: import sha3 [as 別名]
# 或者: from sha3 import sha3_256 [as 別名]
def sha3_256(x):
        return hashlib.sha3_256(x).digest() 
開發者ID:hyperledger,項目名稱:indy-plenum,代碼行數:4,代碼來源:utils.py

示例11: sha3

# 需要導入模塊: import sha3 [as 別名]
# 或者: from sha3 import sha3_256 [as 別名]
def sha3(seed):
    return sha3_256(seed).digest() 
開發者ID:heikoheiko,項目名稱:pydevp2p,代碼行數:4,代碼來源:crypto.py

示例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()) 
開發者ID:pipermerriam,項目名稱:eth-testrpc,代碼行數:9,代碼來源:rpc.py

示例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 
開發者ID:bigchaindb,項目名稱:bigchaindb,代碼行數:8,代碼來源:test_transaction_structure.py

示例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 
開發者ID:bigchaindb,項目名稱:bigchaindb,代碼行數:13,代碼來源:test_transaction_structure.py

示例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 
開發者ID:bigchaindb,項目名稱:bigchaindb,代碼行數:42,代碼來源:test_transactions.py


注:本文中的sha3.sha3_256方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。