def sign_and_verify(private_key, message, address):
    key = CBitcoinSecret(private_key)
    signature = SignMessage(key=key, message=BitcoinMessage(message))
    assert VerifyMessage(address=address,
                         message=BitcoinMessage(message),
                         sig=signature)
    return signature
示例#2
0
def signed_msg(msg_txt, addr, privkey):
    sig = SignMessage(privkey, BitcoinMessage(msg_txt)).decode('utf-8')
    s = MSG_START + "\n"
    s += msg_txt + "\n"
    s += SIG_START + "\n"
    s += addr + "\n"
    s += sig + "\n"
    s += MSG_END + "\n"
    return s
示例#3
0
    def sign(self, message):
        message = BitcoinMessage(message)
        signature = SignMessage(self.key, message).decode('ascii')
        print("Address: %s" % self.key)
        print("Message: %s" % message)
        print("Signature: %s" % signature)
        assert VerifyMessage(self.address, message, signature)

        return signature
示例#4
0
def retrieve_wallettoken(bit_key):
    bitcoinlib_key = CBitcoinSecret.from_secret_bytes(x(bit_key.to_hex()))
    pub_key_hex = str(bitcoinlib_key.pub.hex())

    message = "bitpost" + str(round(
        time.time() /
        1000))  # we add a timestamp to make the proof valid for only ~ 1h
    sig = SignMessage(bitcoinlib_key, BitcoinMessage(message))
    return bitpost_interface.get_wallettoken(pub_key_hex, sig)
def do_sign(certificate, secret_key):
    """Signs the certificate.
    """
    cert = json.loads(certificate)
    to_sign = cert['assertion']['uid']
    message = BitcoinMessage(to_sign)
    signature = SignMessage(secret_key, message)
    cert['signature'] = str(signature, 'utf-8')
    sorted_cert = json.dumps(cert, sort_keys=True)
    return sorted_cert
    def test_sign_message_simple(self):
        key = CBitcoinSecret(
            "L4vB5fomsK8L95wQ7GFzvErYGht49JsCPJyJMHpB4xGM6xgi2jvG")
        address = "1F26pNMrywyZJdr22jErtKcjF8R3Ttt55G"
        message = address

        message = BitcoinMessage(message)
        signature = SignMessage(key, message)

        self.assertTrue(signature)
        self.assertTrue(VerifyMessage(address, message, signature))
    def test_sign_message_vectors(self):
        for vector in load_test_vectors('signmessage.json'):
            key = CBitcoinSecret(vector['wif'])
            message = BitcoinMessage(vector['address'])

            signature = SignMessage(key, message)

            self.assertTrue(signature,
                            "Failed to sign for [%s]" % vector['address'])
            self.assertTrue(
                VerifyMessage(vector['address'], message, vector['signature']),
                "Failed to verify signature for [%s]" % vector['address'])
示例#8
0
def sign(to_sign, private_key, options, chain_name='mainnet'):
    import copy
    copy = copy.deepcopy(to_sign)
    if 'signature' in copy:
        del copy['signature']

    # normalize and get data to hash
    normalized = normalize_jsonld(to_sign)
    to_hash = _getDataToHash(normalized, options=options)

    # TODO: obtain lock while modifying global state
    bitcoin.SelectParams(chain_name)
    message = BitcoinMessage(to_hash)
    secret_key = CBitcoinSecret(private_key)
    signature = SignMessage(secret_key, message)

    # compact just signature part against all contexts
    signature_payload = {
        '@context': SECURITY_CONTEXT_URL,
        'type': algorithm,
        'creator': options.creator,
        'created': options.created,
        'signatureValue': signature.decode('utf-8')
    }

    tmp = {'https://w3id.org/security#signature': signature_payload}

    prev_contexts = JsonLdProcessor.get_values(to_sign, '@context')
    if not SECURITY_CONTEXT_URL in prev_contexts:
        prev_contexts.append(SECURITY_CONTEXT_URL)
    c = {'@context': prev_contexts}
    res = jsonld.compact(tmp,
                         c,
                         options={'documentLoader': cached_document_loader})
    copy['@context'] = prev_contexts
    copy['signature'] = res['signature']
    return copy
def sign_message(message, private_key):
    key = CBitcoinSecret(private_key)
    return SignMessage(key=key, message=BitcoinMessage(message)).decode()
示例#10
0
def signMessage():
    data = request.get_json()
    key = CBitcoinSecret(data["key"])
    msg = BitcoinMessage(data["msg"])
    return SignMessage(key, msg)
示例#11
0
 def sign(privKey, m):
     secret = CBitcoinSecret(privKey)
     message = BitcoinMessage(m)
     return SignMessage(secret, message)
示例#12
0
 def sign(privKey, message):
     secret = CBitcoinSecret(privKey)
     msg = BitcoinMessage(message)
     return SignMessage(secret, msg)
示例#13
0
def sign_message(key, msg):
    secret = CBitcoinSecret(key)
    message = BitcoinMessage(msg)
    return SignMessage(secret, message)
示例#14
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 bitcoin.wallet import CBitcoinSecret, P2PKHBitcoinAddress
from bitcoin.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 bitcoin core;")
print("`bitcoin-cli verifymessage %s \"%s\" \"%s\"`" % (address, signature.decode('ascii'), message))
# 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 bitcoin.wallet import CBitcoinSecret, P2PKHBitcoinAddress
from bitcoin.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 bitcoin core;")
print("`bitcoin-cli verifymessage %s \"%s\" \"%s\"`" %
      (address, signature.decode('ascii'), message))
示例#16
0
            'address': '17sxtd9FBmLcoRQATFwKz3uwuch8M5hHWy',
            'pubkey': '03ffd318e367ae0a8ea1eff6f6b9e324414fb51794c578f8c8ab1e217d4d6b0a0e',
            'privkey': 'L2TBvNdZ2q79qW4knjveCtSk2ZLsooR5pFc712hvXwrT4Ffm6E2N'
        }
    },
    'mediator': {
        'status': False,
        'fee': 0.0,
        'key': None
    },
    'validity': {
        'sin': generate_sin('18mSWcpYB9X9nobaxc4kCHZXPNZaVVLYbR')
    }
}
test_user_1['validity']['id'] = hashlib.sha256(json.dumps(test_user_1).encode('utf-8')).hexdigest()
test_user_1['validity']['signature'] = SignMessage(test_user_1['bitcoin']['delegate']['privkey'], test_user_1).decode('ascii')
test_user_1['validity']['signature_address'] = test_user_1['bitcoin']['delegate']['address']

test_user_2_mnemonic = 'hen skate guitar tube kick clutch decline silent way length stereo neglect'
test_user_2 = {
    'contact': {
        'login': '******',
        'email': '*****@*****.**'
    },
    'bitcoin': {
        'master_address': '1MGbFjsPAJTZAhf136shUrXinHJZJo1DKT',
        'delegate': {
            'address': '1HTWQLfE9mYPy1Knf7wgbWZLEJ9SDoNMX1',
            'pubkey': '027761c803512c83941f2c3ea43319b1d3806ad2f64156afd2fc3c63322d298396',
            'privkey': 'L3cckpG5S4fk54UMUBNW2SG3LynjFHBRdRj66AyCdFdupTTkDhTb'
        }
示例#17
0
def sign(key, message):
    key = CBitcoinSecret(key)
    message = BitcoinMessage(message)
    return SignMessage(key, message).decode('ascii')
示例#18
0
 def sign_message(self, wif, message_to_sign):
     secret_key = CBitcoinSecret(wif)
     message = BitcoinMessage(message_to_sign)
     signature = SignMessage(secret_key, message)
     return str(signature, 'utf-8')