本文整理汇总了Python中btctxstore.BtcTxStore.sign_data方法的典型用法代码示例。如果您正苦于以下问题:Python BtcTxStore.sign_data方法的具体用法?Python BtcTxStore.sign_data怎么用?Python BtcTxStore.sign_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类btctxstore.BtcTxStore
的用法示例。
在下文中一共展示了BtcTxStore.sign_data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSignData
# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import sign_data [as 别名]
class TestSignData(unittest.TestCase):
def setUp(self):
self.api = BtcTxStore(dryrun=True, testnet=True)
def test_sign_a(self):
wif = fixtures["wallet"]["wif"]
data = binascii.hexlify(b"testmessage")
address = self.api.get_address(wif)
sig = self.api.sign_data(wif, data)
valid = self.api.verify_signature(address, sig, data)
self.assertEqual(valid, True)
def test_sign_b(self):
wif = "cSuT2J14dYbe1zvB5z5WTXeRcMbj4tnoKssAK1ZQbnX5HtHfW3bi"
data = binascii.hexlify(b"testmessage")
address = self.api.get_address(wif)
sig = self.api.sign_data(wif, data)
valid = self.api.verify_signature(address, sig, data)
self.assertEqual(valid, True)
示例2: sign
# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import sign_data [as 别名]
def sign(dict_obj, wif): # FIXME use create instead
assert(isinstance(dict_obj, OrderedDict))
if "signature" in dict_obj:
del dict_obj["signature"]
if sys.version_info >= (3, 0, 0):
msg = str(dict_obj).encode("ascii")
else:
msg = str(dict_obj)
# assert("signature" not in msg) # must be unsigned
# todo: fix this
api = BtcTxStore(testnet=False, dryrun=True)
msg = binascii.hexlify(msg).decode("utf-8")
sig = api.sign_data(wif, msg)
if sys.version_info >= (3, 0, 0):
dict_obj[u"signature"] = sig.decode("utf-8")
else:
dict_obj[u"signature"] = unicode(sig)
return dict_obj
示例3: __init__
# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import sign_data [as 别名]
#.........这里部分代码省略.........
_log.debug("ACK")
def save_contract(self, contract):
# Record contract details.
contract_id = self.contract_id(contract)
self.contracts[contract_id] = contract
return contract_id
def send_msg(self, dict_obj, unl):
node_id = self.net.unl.deconstruct(unl)["node_id"]
msg = json.dumps(dict_obj, ensure_ascii=True)
self.net.dht_node.direct_message(
node_id,
msg
)
def contract_id(self, contract):
if sys.version_info >= (3, 0, 0):
contract = str(contract).encode("ascii")
else:
contract = str(contract)
return hashlib.sha256(contract).hexdigest()
def sign_contract(self, contract):
if sys.version_info >= (3, 0, 0):
msg = str(contract).encode("ascii")
else:
msg = str(contract)
msg = binascii.hexlify(msg).decode("utf-8")
sig = self.wallet.sign_data(self.wif, msg)
if sys.version_info >= (3, 0, 0):
contract[u"signature"] = sig.decode("utf-8")
else:
contract[u"signature"] = unicode(sig)
return contract
def is_valid_contract_sig(self, contract):
sig = contract[u"signature"][:]
del contract[u"signature"]
if sys.version_info >= (3, 0, 0):
msg = str(contract).encode("ascii")
else:
msg = str(contract)
msg = binascii.hexlify(msg).decode("utf-8")
address = self.wallet.get_address(self.wif)
ret = self.wallet.verify_signature(address, sig, msg)
contract[u"signature"] = sig[:]
return ret
def simple_data_request(self, data_id, node_unl, direction):
file_size = 0
if direction == u"send":
action = u"upload"
else:
action = u"download"
示例4: output
# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import sign_data [as 别名]
# store data in blockchain as nulldata output (max 40bytes)
data = binascii.hexlify(b"example_data")
txid = api.store_nulldata(data, wifs)
# Show current transaction id
print("Current Transaction ID: {}".format(txid))
# Now, retrieve data based on transaction id
hexnulldata = api.retrieve_nulldata(txid)
print("Retrieved Data: {}".format(hexnulldata))
# create new private key
wif = api.create_key()
# get private key address
address = api.get_address(wif)
# hexlify messagetext
data = binascii.hexlify(b"messagetext")
# sign data with private key
signature = api.sign_data(wif, data)
print("signature:", signature)
# verify signature (no public or private key needed)
isvalid = api.verify_signature(address, signature, data)
print("valid signature" if isvalid else "invalid signature")