コード例 #1
0
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
ファイル: nodetalk.py プロジェクト: jarret/nodetalk
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
ファイル: ewcore.py プロジェクト: RCasatta/ew-core
    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)
コード例 #5
0
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
コード例 #6
0
    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))
コード例 #7
0
    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
コード例 #9
0
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
ファイル: bk2.py プロジェクト: GabrielleDuarte/blockchain
 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
ファイル: sign-message.py プロジェクト: RCasatta/ew-core
#
# 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))
コード例 #15
0
# 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
ファイル: bitcoinecdsa.py プロジェクト: kingcoocha/causeway
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')