コード例 #1
0
    def test_verify(self):
        announce = MasternodeAnnounce.deserialize(raw_announce)
        message = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_bc_address(
            announce.collateral_key.decode('hex'), 139)
        self.assertTrue(announce.verify())

        raw = '7ca6564432d0e0920b811887e1f9077a92924c83564e6ea8ea874fc8843ccd2b0000000000ffffffff00000000000000000000ffffc0a801014e1f410411e2638aeb4584ff2e027b6ee20e05655ff05583185b1d87188185d6955534fe02ad35caabb5e6e9ce8747ba73fdccccd2369feb9a6f2b0bdee93378e7c8f1c0410411e2638aeb4584ff2e027b6ee20e05655ff05583185b1d87188185d6955534fe02ad35caabb5e6e9ce8747ba73fdccccd2369feb9a6f2b0bdee93378e7c8f1c0411bab132617d8e6a0e3b5434c91a5a64ff13a9cfadc6c178a47b87691f13a26e7440c08660e488ddf927bba1bf04c1ec196370452a30fd3381ea8ba27d627f9d4468be80e5700000000d71101007ca6564432d0e0920b811887e1f9077a92924c83564e6ea8ea874fc8843ccd2b0000000000ffffffffd75eb4fa0cb71dd2e99d7b242784a5601c5c86d7c1cf0362a3391575070000008be80e5700000000411b6d5985008e0821c936fafc192f31963141ae2fab837e84bb9f12422711c1952d5750f9a781c89117a6f4576edc1149a1bf211e7151c5c88cf3252e2d83cb154a0000000000000000'
        announce = MasternodeAnnounce.deserialize(raw)
        msg = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_bc_address(
            announce.collateral_key.decode('hex'), 139)
        self.assertTrue(announce.verify(pk))
コード例 #2
0
    def _do_test_crypto(self, message):
        G = generator_secp256k1
        _r  = G.order()
        pvk = ecdsa.util.randrange( pow(2,256) ) %_r

        Pub = pvk*G
        pubkey_c = point_to_ser(Pub,True)
        #pubkey_u = point_to_ser(Pub,False)
        addr_c = public_key_to_bc_address(pubkey_c)
        #addr_u = public_key_to_bc_address(pubkey_u)

        #print "Private key            ", '%064x'%pvk
        eck = EC_KEY(number_to_string(pvk,_r))

        #print "Compressed public key  ", pubkey_c.encode('hex')
        enc = EC_KEY.encrypt_message(message, pubkey_c)
        dec = eck.decrypt_message(enc)
        assert dec == message

        #print "Uncompressed public key", pubkey_u.encode('hex')
        #enc2 = EC_KEY.encrypt_message(message, pubkey_u)
        dec2 = eck.decrypt_message(enc)
        assert dec2 == message

        signature = eck.sign_message(message, True, addr_c)
        #print signature
        EC_KEY.verify_message(addr_c, signature, message)
コード例 #3
0
    def _do_test_crypto(self, message):
        G = generator_secp256k1
        _r = G.order()
        pvk = ecdsa.util.randrange(pow(2, 256)) % _r

        Pub = pvk * G
        pubkey_c = point_to_ser(Pub, True)
        #pubkey_u = point_to_ser(Pub,False)
        addr_c = public_key_to_bc_address(pubkey_c)
        #addr_u = public_key_to_bc_address(pubkey_u)

        #print "Private key            ", '%064x'%pvk
        eck = EC_KEY(number_to_string(pvk, _r))

        #print "Compressed public key  ", pubkey_c.encode('hex')
        enc = EC_KEY.encrypt_message(message, pubkey_c)
        dec = eck.decrypt_message(enc)
        assert dec == message

        #print "Uncompressed public key", pubkey_u.encode('hex')
        #enc2 = EC_KEY.encrypt_message(message, pubkey_u)
        dec2 = eck.decrypt_message(enc)
        assert dec2 == message

        signature = eck.sign_message(message, True, addr_c)
        #print signature
        EC_KEY.verify_message(addr_c, signature, message)
コード例 #4
0
ファイル: pubkey.py プロジェクト: genjix/unsystematic-borg
def generate_address(n):
    # get_new_address
    for_change = False
    z = get_sequence(n, for_change)
    dec_mpk = master_public_key.decode("hex")
    # verifykey from_string
    order = SECP256k1.order
    assert len(dec_mpk) == SECP256k1.verifying_key_length
    xs = dec_mpk[:SECP256k1.baselen]
    ys = dec_mpk[SECP256k1.baselen:]
    assert len(xs) == SECP256k1.baselen
    assert len(ys) == SECP256k1.baselen
    def string_to_number(string):
        import binascii
        return int(binascii.hexlify(string), 16)
    x = string_to_number(xs)
    y = string_to_number(ys)
    mpk = ecdsa.VerifyingKey.from_string( master_public_key.decode('hex'), curve = SECP256k1 )
    mpk_pubkey_point = Point(SECP256k1.curve, x, y, order)
    pubkey_point = mpk_pubkey_point + z*SECP256k1.generator
    public_key2 = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 )
    address = bitcoin.public_key_to_bc_address( '04'.decode('hex') + public_key2.to_string() )
    return address