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


Python bitcoin.ecdsa_raw_sign方法代碼示例

本文整理匯總了Python中bitcoin.ecdsa_raw_sign方法的典型用法代碼示例。如果您正苦於以下問題:Python bitcoin.ecdsa_raw_sign方法的具體用法?Python bitcoin.ecdsa_raw_sign怎麽用?Python bitcoin.ecdsa_raw_sign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bitcoin的用法示例。


在下文中一共展示了bitcoin.ecdsa_raw_sign方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Sign

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def Sign(message, private_key):
        """
        Sign the message with the given private key.

        Args:
            message (hexstr): message to be signed
            private_key (str): 32 byte key as a double digit hex string (e.g. having a length of 64)
        Returns:
            bytearray: the signature of the message.
        """
        Crypto.SetupSignatureCurve()

        hash = hashlib.sha256(binascii.unhexlify(message)).hexdigest()

        v, r, s = bitcoin.ecdsa_raw_sign(hash, private_key)

        rb = bytearray(r.to_bytes(32, 'big'))
        sb = bytearray(s.to_bytes(32, 'big'))

        sig = rb + sb

        return sig 
開發者ID:CityOfZion,項目名稱:neo-python,代碼行數:24,代碼來源:Crypto.py

示例2: Sign

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def Sign(message, private_key):
        """
        Sign the message with the given private key.

        Args:
            message (str): message to be signed
            private_key (str): 32 byte key as a double digit hex string (e.g. having a length of 64)
        Returns:
            bytearray: the signature of the message.
        """

        hash = hashlib.sha256(binascii.unhexlify(message)).hexdigest()

        v, r, s = bitcoin.ecdsa_raw_sign(hash, private_key)

        rb = bytearray(r.to_bytes(32, 'big'))
        sb = bytearray(s.to_bytes(32, 'big'))

        sig = rb + sb

        return sig 
開發者ID:CityOfZion,項目名稱:neo-python-core,代碼行數:23,代碼來源:Crypto.py

示例3: sign

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def sign(messageHash, seckey):
	return pack_signature(*b.ecdsa_raw_sign(messageHash, seckey)) 
開發者ID:HarryR,項目名稱:solcrypto,代碼行數:4,代碼來源:ecdsa.py

示例4: test_ecdsa

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def test_ecdsa(self):
        # Verifies that a random sample of freshly generated keys don't
        # end up setting the 'flag' bit which replaces 'v'
        # If this test ever fails, the entire premise of this thing is fucked!
        for _ in range(0, 100):
            messageHash = randb256()
            seckey = randb256()
            pubkey = pubkey_to_ethaddr(b.privtopub(seckey))

            sig_t = b.ecdsa_raw_sign(messageHash, seckey)
            sig = sign(messageHash, seckey)
            assert unpack_signature(*sig) == sig_t

            pubkey_v = recover(messageHash, *sig)
            assert pubkey == pubkey_v 
開發者ID:HarryR,項目名稱:solcrypto,代碼行數:17,代碼來源:test_ecdsa.py

示例5: ecdsa_sign

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def ecdsa_sign(msg: str, wif_priv_key: str, dash_network: str):
    """Signs a message with the Elliptic Curve algorithm.
    """

    v, r, s = bitcoin.ecdsa_raw_sign(electrum_sig_hash(msg), wif_priv_key)
    sig = bitcoin.encode_sig(v, r, s)
    pubkey = bitcoin.privkey_to_pubkey(wif_to_privkey(wif_priv_key, dash_network))

    ok = bitcoin.ecdsa_raw_verify(electrum_sig_hash(msg), bitcoin.decode_sig(sig), pubkey)
    if not ok:
        raise Exception('Bad signature!')
    return sig 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:14,代碼來源:dash_utils.py

示例6: ecdsa_sign_raw

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def ecdsa_sign_raw(msg_raw: bytes, wif_priv_key: str, dash_network: str):
    """Signs raw bytes (a message hash) with the Elliptic Curve algorithm.
    """

    v, r, s = bitcoin.ecdsa_raw_sign(msg_raw, wif_priv_key)
    sig = bitcoin.encode_sig(v, r, s)
    pubkey = bitcoin.privkey_to_pubkey(wif_to_privkey(wif_priv_key, dash_network))

    ok = bitcoin.ecdsa_raw_verify(msg_raw, bitcoin.decode_sig(sig), pubkey)
    if not ok:
        raise Exception('Bad signature!')
    return sig 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:14,代碼來源:dash_utils.py

示例7: ecdsa_sign

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def ecdsa_sign(message, privkey):
    s = _encode_sig(*bitcoin.ecdsa_raw_sign(message, privkey))
    return s 
開發者ID:heikoheiko,項目名稱:pydevp2p,代碼行數:5,代碼來源:crypto.py

示例8: make_tx_signatures

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import ecdsa_raw_sign [as 別名]
def make_tx_signatures(txs_to_sign, privkey_list, pubkey_list):
    """
    Loops through txs_to_sign and makes signatures using privkey_list and pubkey_list

    Not sure what privkeys and pubkeys to supply?
    Use get_input_addresses() to return a list of addresses.
    Matching those addresses to keys is up to you and how you store your private keys.
    A future version of this library may handle this for you, but it is not trivial.

    Note that if spending multisig funds the process is significantly more complicated.
    Each tx_to_sign must be signed by *each* private key.
    In a 2-of-3 transaction, two of [privkey1, privkey2, privkey3] must sign each tx_to_sign

    http://dev.blockcypher.com/#multisig-transactions
    """
    assert len(privkey_list) == len(pubkey_list) == len(txs_to_sign)
    # in the event of multiple inputs using the same pub/privkey,
    # that privkey should be included multiple times

    signatures = []
    for cnt, tx_to_sign in enumerate(txs_to_sign):
        sig = der_encode_sig(*ecdsa_raw_sign(tx_to_sign.rstrip(' \t\r\n\0'), privkey_list[cnt]))
        err_msg = 'Bad Signature: sig %s for tx %s with pubkey %s' % (
            sig,
            tx_to_sign,
            pubkey_list[cnt],
            )
        assert ecdsa_raw_verify(tx_to_sign, der_decode_sig(sig), pubkey_list[cnt]), err_msg
        signatures.append(sig)
    return signatures 
開發者ID:blockcypher,項目名稱:blockcypher-python,代碼行數:32,代碼來源:api.py


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