当前位置: 首页>>代码示例>>Python>>正文


Python BtcTxStore.verify_signature方法代码示例

本文整理汇总了Python中btctxstore.BtcTxStore.verify_signature方法的典型用法代码示例。如果您正苦于以下问题:Python BtcTxStore.verify_signature方法的具体用法?Python BtcTxStore.verify_signature怎么用?Python BtcTxStore.verify_signature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在btctxstore.BtcTxStore的用法示例。


在下文中一共展示了BtcTxStore.verify_signature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestIO

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import verify_signature [as 别名]
class TestIO(unittest.TestCase):

    def setUp(self):
        self.api = BtcTxStore(dryrun=True, testnet=True)

    def test_readwrite_nulldata(self):
        rawtx = self.api.create_tx()
        rawtx = self.api.add_nulldata(rawtx, "f483")
        data = self.api.get_nulldata(rawtx)
        self.assertEqual(data, "f483")

    def test_readwrite_hash160data(self):
        rawtx = self.api.create_tx()
        rawtx = self.api.add_hash160data(rawtx, 10 * "f483")
        data = self.api.get_hash160data(rawtx, 0)
        self.assertEqual(data, 10 * "f483")

    def test_readwrite_data_blob(self):
        rawtx = self.api.create_tx()
        data_in = "f483" * 30 + "beef" * 30
        rawtx = self.api.add_data_blob(rawtx, data_in)
        data_out = self.api.get_data_blob(rawtx)
        self.assertEqual(data_in, data_out)

    def test_readwrite_broadcast_message(self):
        message = u"Ünicode test massage"
        sender_wif = fixtures["wallet"]["wif"]
        sender_address = fixtures["wallet"]["address"]
        sender_hash160hex = fixtures["wallet"]["hash160hex"]

        # create broadcast message tx
        rawtx = self.api.create_tx()
        rawtx = self.api.add_broadcast_message(rawtx, message, sender_wif)

        # check that sender address is aligned so its visible in history
        hash160hex = self.api.get_hash160data(rawtx, 3)
        self.assertEqual(hash160hex, sender_hash160hex)

        # get broadcast message from tx
        result = self.api.get_broadcast_message(rawtx)
        self.assertEqual(result["address"], sender_address)
        self.assertEqual(result["message"], message)

        # check signature is valid
        hex_message = binascii.hexlify(result["message"].encode('utf-8'))
        valid_signature = self.api.verify_signature(result["address"],
                                                    result["signature"],
                                                    hex_message)
        self.assertTrue(valid_signature)

    def test_only_one_nulldata_output(self):
        def callback():
            rawtx = self.api.create_tx()
            rawtx = self.api.add_nulldata(rawtx, "f483")
            self.api.add_nulldata(rawtx, "f483")  # writing second fails
        self.assertRaises(exceptions.ExistingNulldataOutput, callback)
开发者ID:F483,项目名称:btctxstore,代码行数:58,代码来源:other.py

示例2: TestVerifySignature

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import verify_signature [as 别名]
class TestVerifySignature(unittest.TestCase):

    def setUp(self):
        self.api = BtcTxStore(dryrun=True, testnet=True)

    def test_verify_positive(self):
        _fixtures = fixtures["verify_signature"]["positive"]
        address = _fixtures["address"]
        signature = _fixtures["signature"]
        data = binascii.hexlify(b"testmessage")
        result = self.api.verify_signature(address, signature, data)
        self.assertEqual(result, True)

    def test_verify_incorrect_address(self):
        _fixtures = fixtures["verify_signature"]["incorrect_address"]
        address = _fixtures["address"]
        signature = _fixtures["signature"]
        data = binascii.hexlify(b"testmessage")
        result = self.api.verify_signature(address, signature, data)
        self.assertEqual(result, False)

    def test_verify_incorrect_signature(self):
        _fixtures = fixtures["verify_signature"]["incorrect_signature"]
        address = _fixtures["address"]
        signature = _fixtures["signature"]
        data = binascii.hexlify(b"testmessage")
        result = self.api.verify_signature(address, signature, data)
        self.assertEqual(result, False)

    def test_verify_incorrect_data(self):
        _fixtures = fixtures["verify_signature"]["incorrect_data"]
        address = _fixtures["address"]
        signature = _fixtures["signature"]
        data = binascii.hexlify(b"testmessagee")
        result = self.api.verify_signature(address, signature, data)
        self.assertEqual(result, False)

    def test_verify_signature_params(self):
        wif = "cSuT2J14dYbe1zvB5z5WTXeRcMbj4tnoKssAK1ZQbnX5HtHfW3bi"
        data = binascii.hexlify(b"testmessage")
        address = self.api.get_address(wif)
        sig = "///////////////////////////////////////////////////////////////////////////////////////="
        self.assertFalse(self.api.verify_signature(address, sig, data))
开发者ID:robertsdotpm,项目名称:btctxstore,代码行数:45,代码来源:other.py

示例3: TestSignData

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import verify_signature [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)
开发者ID:F483,项目名称:btctxstore,代码行数:22,代码来源:other.py

示例4: __init__

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import verify_signature [as 别名]

#.........这里部分代码省略.........
        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"

        return self.data_request(action, data_id, file_size, node_unl)

    def data_request(self, action, data_id, file_size, node_unl):
        """
        Action = put (upload), get (download.)
        """
        _log.debug("In data request function")

        # Who is hosting this data?
        if action == "upload":
            # We store this data.
            direction = u"send"
            host_unl = self.net.unl.value
            assert(storage.manager.find(self.store_config, data_id) is not None)
        else:
            # They store the data.
            direction = u"receive"
            host_unl = node_unl
            if data_id in self.downloading:
                raise Exception("Already trying to download this.")
开发者ID:F483,项目名称:storjnode,代码行数:69,代码来源:file_transfer.py

示例5: output

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import verify_signature [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")
开发者ID:richvincent,项目名称:bitcoin-research,代码行数:32,代码来源:write_to_blockchain.py


注:本文中的btctxstore.BtcTxStore.verify_signature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。