示例#1
0
 def sign_vote(self, sk, vk):
     add = Address()
     add.load(sk, vk)
     self.script_sig = add.sign_message(
         json.dumps({
             "ip_address": self.ip_address,
             "representative": self.representative
         }))
     self.vk = vk
示例#2
0
def create_tx(addr):
    add_data = {
        "address":
        "1d3f347aada53547142da8edea5e0019e6ef31bb15",
        "vk":
        "-----BEGIN PUBLIC KEY-----\nMEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEHxzkpgh/lqgd1/rb7d+D+srhlhzG\ncOAveBQafVnHkffNR2aCiFHVQZKzhyO7iC/p\n-----END PUBLIC KEY-----\n",
        "sk":
        "-----BEGIN EC PRIVATE KEY-----\nMF8CAQEEGKtkXJ8xlejSSOl4mzNTYiXmb70wRByW1aAKBggqhkjOPQMBAaE0AzIA\nBB8c5KYIf5aoHdf62+3fg/rK4ZYcxnDgL3gUGn1Zx5H3zUdmgohR1UGSs4cju4gv\n6Q==\n-----END EC PRIVATE KEY-----\n"
    }
    tx = Transaction()
    add = Address()
    add.load(add_data["sk"], add_data["vk"])
    # print(addr)
    tx.inputs = []
    tx.inputs.append(
        TransactionInput.from_json({
            'previous_tx':
            "16e8dab3a9185d5329fac9cfdc0a81c7817826f701e747cb3751878061e4dc8c",
            'index':
            0,
            'scriptSig': [
                add.sign_message(
                    json.dumps({
                        'previous_tx':
                        "16e8dab3a9185d5329fac9cfdc0a81c7817826f701e747cb3751878061e4dc8c",
                        'index': 0
                    }).encode("utf-8")).hex()
            ],
            'address':
            addr,
            'verifying_key': [add_data["vk"]]
        }))
    tx.outputs.append(
        TransactionOutput.from_json({
            'address': "yikgyyf67rr68t887tfc",
            'value': 25,
            'n': 0
        }))
    tx.generate_hash()
    txf = tx.to_json()
    # print(txf['inputs'][0]['address'])
    return txf
示例#3
0
def create_fake_transaction(address: Address):
    tmp_tx = Transaction()
    add = Address()
    add.load(add_data["sk"], add_data["vk"])

    tmp_tx.inputs.append(TransactionInput.from_json({
        'previous_tx': "16e8dab3a9185d5329fac9cfdc0a81c7817826f701e747cb3751878061e4dc8c",
        'index': 0,
        'scriptSig': [add.sign_message(json.dumps({
            'previous_tx': "16e8dab3a9185d5329fac9cfdc0a81c7817826f701e747cb3751878061e4dc8c",
            'index': 0
        }).encode("utf-8")).hex()],
        'address': add_data["address"],
        'verifying_key': [add_data["vk"]]
    }))
    tmp_tx.outputs.append(TransactionOutput.from_json({
        'address': "12345",
        'value': 25,
        'n': 0
    }))
    tmp_tx.generate_hash()

    return tmp_tx
示例#4
0
 def sign_verif(self):
     add = Address()
     sgn = add.sign_message("hello world")
     res = add.verify_signature("hello world", sgn)
     self.assertEqual(res, True)