Example #1
0
def pubkeys_to_basic_stealth_address(scan_pubkey, spend_pubkey, magic_byte=42):
    # magic_byte = 42 for mainnet, 43 for testnet.
    hex_scankey = main.encode_pubkey(scan_pubkey, 'hex_compressed')
    hex_spendkey = main.encode_pubkey(spend_pubkey, 'hex_compressed')
    hex_data = '00{0:066x}01{1:066x}0100'.format(int(hex_scankey, 16), int(hex_spendkey, 16))
    addr = main.hex_to_b58check(hex_data, magic_byte)
    return addr
Example #2
0
def pubkeys_to_basic_stealth_address(scan_pubkey, spend_pubkey, magic_byte=42):
    # magic_byte = 42 for mainnet, 43 for testnet.
    hex_scankey = main.encode_pubkey(scan_pubkey, 'hex_compressed')
    hex_spendkey = main.encode_pubkey(spend_pubkey, 'hex_compressed')
    hex_data = '00{0:066x}01{1:066x}0100'.format(int(hex_scankey, 16), int(hex_spendkey, 16))
    addr = main.hex_to_b58check(hex_data, magic_byte)
    return addr
Example #3
0
def mk_stealth_metadata_script(ephem_pubkey, nonce):
    op_return = '6a'
    msg_size = '26'
    version = '06'
    return op_return + msg_size + version + '{0:08x}'.format(
        nonce) + main.encode_pubkey(ephem_pubkey, 'hex_compressed')
Example #4
0
def shared_secret_sender(scan_pubkey, ephem_privkey):
    shared_point = main.multiply(scan_pubkey, ephem_privkey)
    shared_secret = main.sha256(
        main.encode_pubkey(shared_point, 'bin_compressed'))
    return shared_secret
Example #5
0
def mk_stealth_metadata_script(ephem_pubkey, nonce):
    op_return = '6a'
    msg_size = '26'
    version = '06'
    return op_return + msg_size + version + '{0:08x}'.format(
        nonce) + main.encode_pubkey(ephem_pubkey, 'hex_compressed')
Example #6
0
def shared_secret_sender(scan_pubkey, ephem_privkey):
    shared_point = main.multiply(scan_pubkey, ephem_privkey)
    shared_secret = main.sha256(main.encode_pubkey(shared_point,
                                                   'bin_compressed'))
    return shared_secret
# 개인키를 생성한다
while (1):
    privKey = btc.random_key()  # 256 bit Random number를 생성한다
    dPrivKey = btc.decode_privkey(privKey, 'hex')  # 16진수 문자열을 10진수 숫자로 변환한다
    if dPrivKey < btc.N:  # secp256k1 의 N 보다 작으면 OK
        break

# 개인키로 공개키를 생성한다.
pubKey = btc.privkey_to_pubkey(privKey)

# 공개키로 지갑 주소를 생성한다. (mainnet 용)
address1 = btc.pubkey_to_address(pubKey, 0)

# 공개키로 160-bit public key hash를 생성한다
pubHash160 = btc.hash160(btc.encode_pubkey(pubKey, 'bin'))

# 160-bit public key hash로 지갑 주소를 생성한다. (위의 address와 동일하다)
address2 = btc.hex_to_b58check(pubHash160, 0)

# 지갑 주소를 160-bit public key hash로 변환한다. (위의 pubHash160과 동일하다)
pubHash1601 = btc.b58check_to_hex(address2)

# 공개키로 testnet용 지갑 주소를 생성한다
address3 = btc.pubkey_to_address(pubKey, 0x6f)

# 결과 확인
print("\n\n개인키 : ", privKey)
print("개인키 --> 공개키 : ", pubKey)
print("\n공개키 --> 지갑주소 (1. mainet 용) : ", address1)
print("공개키 --> 공개키 해시 : ", pubHash160)
Example #8
0
print("v1 = " + int_to_hex_str(v1))
print("v2 = " + int_to_hex_str(v2))
print("m1 = " + m1)
print("m2 = " + m2)
print("solution hash = " + solution_hash)

print("Eth input = ")

eth_input = """ "0x%s", %d, "0x%s", "0x%s", "0x%s", "0x%s", "%s", "%s", 0 <--- replace the zero with the index returned from CommitSolutionHsh""" % (
    int_to_hex_str(hm1), v1, int_to_hex_str(r1), int_to_hex_str(s1),
    int_to_hex_str(hm2), int_to_hex_str(s2), destination, destination)
print(eth_input)

rec_pub_key = ecdsa_raw_recover(unhexlify(int_to_hex_str(hm1)), (v1, r1, s1))
if v1 >= 31:
    rec_pub_key = encode_pubkey(rec_pub_key, 'hex_compressed')
else:
    rec_pub_key = encode_pubkey(rec_pub_key, 'hex')

print("Recovery 1 = " + rec_pub_key)

print("Ver sig hm1 from rec = " +
      str(ecdsa_raw_verify(int_to_hex_str(hm1), (v1, r1, s1), rec_pub_key)))
print("Ver sig hm1 from attack = " +
      str(ecdsa_raw_verify(int_to_hex_str(hm1), (v1, r1, s1), pub_key)))

rec_pub_key = ecdsa_raw_recover(unhexlify(int_to_hex_str(hm2)), (v2, r2, s2))
if v1 >= 31:
    rec_pub_key = encode_pubkey(rec_pub_key, 'hex_compressed')
else:
    rec_pub_key = encode_pubkey(rec_pub_key, 'hex')