本文整理汇总了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
示例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
示例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))
示例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
示例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
示例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
示例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
示例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