Exemplo n.º 1
0
def VerifyMessage(address, message, sig):
    sig = base64.b64decode(sig)
    hash = message.GetHash()

    pubkey = CPubKey.recover_compact(hash, sig)

    return str(P2PKHBitcoinAddress.from_pubkey(pubkey)) == str(address)
Exemplo n.º 2
0
 def parse_secret(self, txid):
     raw = self.zcashd.gettransaction(txid, True)['hex']
     decoded = self.zcashd.decoderawtransaction(raw)
     scriptSig = decoded['vin'][0]['scriptSig']
     asm = scriptSig['asm'].split(" ")
     pubkey = asm[1]
     secret = x2s(asm[2])
     redeemPubkey = P2PKHBitcoinAddress.from_pubkey(x(pubkey))
     return secret
Exemplo n.º 3
0
def parse_secret(txid):
    raw = zcashd.gettransaction(txid)['hex']
    # print("Raw", raw)
    decoded = zcashd.decoderawtransaction(raw)
    scriptSig = decoded['vin'][0]['scriptSig']
    print("Decoded", scriptSig)
    asm = scriptSig['asm'].split(" ")
    pubkey = asm[1]
    secret = hex2str(asm[2])
    redeemPubkey = P2PKHBitcoinAddress.from_pubkey(x(pubkey))
    print('redeemPubkey', redeemPubkey)
    print(secret)
    return secret
Exemplo n.º 4
0
 def find_recipient(self, contract):
     # make this dependent on actual fund tx to p2sh, not contract
     txid = contract.fund_tx
     raw = self.zcashd.gettransaction(lx(txid), True)['hex']
     decoded = self.zcashd.decoderawtransaction(raw)
     scriptSig = decoded['vin'][0]['scriptSig']
     print("Decoded", scriptSig)
     asm = scriptSig['asm'].split(" ")
     pubkey = asm[1]
     initiator = CBitcoinAddress(contract.initiator)
     fulfiller = CBitcoinAddress(contract.fulfiller)
     print("Initiator", b2x(initiator))
     print("Fulfiller", b2x(fulfiller))
     print('pubkey', pubkey)
     redeemPubkey = P2PKHBitcoinAddress.from_pubkey(x(pubkey))
     print('redeemPubkey', redeemPubkey)
Exemplo n.º 5
0
def find_refundAddr(contract):
    scriptarray = parse_script(contract.redeemScript)
    funder = scriptarray[13]
    refundAddr = P2PKHBitcoinAddress.from_bytes(x(funder))
    return refundAddr
Exemplo n.º 6
0
def find_redeemAddr(contract):
    scriptarray = parse_script(contract['redeemScript'])
    redeemer = scriptarray[6]
    redeemAddr = P2PKHBitcoinAddress.from_bytes(x(redeemer))
    return redeemAddr
Exemplo n.º 7
0
 def find_redeemAddr(self, contract):
     scriptarray = self.parse_script(contract.redeemScript)
     redeemer = scriptarray[6]
     redeemAddr = P2PKHBitcoinAddress.from_bytes(x(redeemer))
     return redeemAddr
Exemplo n.º 8
0
# This file is part of python-bitcoinlib.
#
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
#
# No part of python-bitcoinlib, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in the
# LICENSE file.

from __future__ import absolute_import, division, print_function, unicode_literals

from zcash.wallet import CBitcoinSecret, P2PKHBitcoinAddress
from zcash.signmessage import BitcoinMessage, VerifyMessage, SignMessage

key = CBitcoinSecret("L4vB5fomsK8L95wQ7GFzvErYGht49JsCPJyJMHpB4xGM6xgi2jvG")
address = P2PKHBitcoinAddress.from_pubkey(
    key.pub)  # "1F26pNMrywyZJdr22jErtKcjF8R3Ttt55G"
message = "Hey I just met you, and this is crazy, but I'll verify my address, maybe ..."

message = BitcoinMessage(message)

signature = SignMessage(key, message)

print(key, address)
print("Address: %s" % address)
print("Message: %s" % message)
print("\nSignature: %s" % signature)
print("\nVerified: %s" % VerifyMessage(address, message, signature))

print("\nTo verify using zcash core;")
print("`bitcoin-cli verifymessage %s \"%s\" \"%s\"`" %
      (address, signature.decode('ascii'), message))