bob_addr = "1NWzVg38ggPoVGAG2VWt6ktdWMaV6S1pJk"#"1FMb8Jnn1jSh7yjDFfonC8xCCH3ittoEzB"
bob_hashed_pubkey = base58check.b58decode(bob_addr)[1:]
bob2_hashed_pubkey = b'\xec\x06\xb2\xbf\x18\xc8\x97\x06\x85_v\x1d!_!\xf31[9\x94'.hex()
bob3_hashed_pubkey =codecs.encode(bob_hashed_pubkey, 'hex')
print("bob_hashed_pubkey: ", bob2_hashed_pubkey )
bob_private_key = "CF933A6C602069F1CBC85990DF087714D7E86DF0D0E48398B7D8953E1F03534A"
prv_txid = "84d813beb51c3a12cb5d0bb18c6c15062453d476de24cb2f943ca6e20115d85c"
charlie_addr = "17X4s8JdSdLxFyraNUDBzgmnSNeZpjm42g"
charlie_hashed_pubkey = base58check.b58decode(charlie_addr)[1:]
charlie2_hashed_pubkey = b'G\x80u\x92*\xf4\x1f\xb4A\xaa\n\xb6~\x91\xae\xf2~\xf1\xe6\x86'.hex()
class raw_tx:
version = struct.pack("<L", 1)
tx_in_count = struct.pack("<B", 1)
tx_in = {}
tx_out_count = struct.pack("<B", 2)
tx_out1 = {}
tx_out2 = {}
lock_time = struct.pack("<L", 0)
hashcode = struct.pack("<L", 1)
nonce = struct.pack("Q", 0)
class raw_tx2:
version = struct.pack("<L", 1)
lock_time = struct.pack("<L", 0)
hashcode = struct.pack("<L", 1)
def flip_byte_order(string):
flipped = "".join(reversed([string[i:i+2] for i in range(0, len(string), 2)]))
return flipped
rtx = raw_tx()
rtx.tx_in["txouthash"] = codecs.decode(flip_byte_order(prv_txid), 'hex')
rtx.tx_in["tx_out_index"] = struct.pack("<L", 0)
rtx.tx_in["script"] = codecs.decode(("76a914%s88ac" % bob2_hashed_pubkey), 'hex')
rtx.tx_in["script_bytes"]= struct.pack("<B", len(rtx.tx_in["script"]))
rtx.tx_in["sequence"] = codecs.decode("ffffffff", 'hex')
rtx.tx_out1["value"] = struct.pack("<Q", 100000)
rtx.tx_out1["pk_script"] = codecs.decode(("76a914%s88ac" % charlie2_hashed_pubkey), 'hex')
rtx.tx_out1["pk_script_bytes"] = struct.pack("<B", len(rtx.tx_out1["pk_script"]))
rtx.tx_out2["value"] = struct.pack("<Q", 50000)
rtx.tx_out2["pk_script"] = codecs.decode(("76a914%s88ac" % bob2_hashed_pubkey), 'hex')
rtx.tx_out2["pk_script_bytes"] = struct.pack("<B", len(rtx.tx_out2["pk_script"]))
raw_tx_string = (
rtx.version +
rtx.tx_in_count +
rtx.tx_in["txouthash"] +
rtx.tx_in["tx_out_index"]+
rtx.tx_in["script_bytes"]+
rtx.tx_in["script"] +
rtx.tx_in["sequence"]+
rtx.tx_out_count +
rtx.tx_out1["value"]+
rtx.tx_out1["pk_script_bytes"]+
rtx.tx_out1["pk_script"]+
rtx.tx_out2["value"]+
rtx.tx_out2["pk_script_bytes"]+
rtx.tx_out2["pk_script"]+
rtx.lock_time +
struct.pack("<L", 1)
)
hashed_tx_to_sign = hashlib.sha256(hashlib.sha256(raw_tx_string).digest()).digest()
sk = ecdsa.SigningKey.from_string(codecs.decode(bob_private_key, 'hex'), curve = ecdsa.SECP256k1)
vk = sk.verifying_key
public_key = (b'\04'.hex() + vk.to_string().hex())
signature = sk.sign_digest(hashed_tx_to_sign, sigencode=ecdsa.util.sigencode_der)
sigscript = (
signature
+ b'\01'
+ struct.pack("<B", len(codecs.decode(public_key, 'hex')))
+ codecs.decode(public_key, 'hex')
)
print("public_key: ", public_key)
ha = rtx.version.hex()
ha1 = rtx.tx_in_count.hex()
ha2 = flip_byte_order(prv_txid)
ha3 = struct.pack("<L", 0).hex()
ha4 = struct.pack("<B", len(sigscript) + 1).hex()
ha40 = struct.pack("<B", len(signature) + 1).hex()
ha5 = sigscript.hex()
ha6 = 'ffffffff'
ha7 = rtx.tx_out_count.hex()
ha8 = struct.pack("<Q", 100000).hex()
ha9 = struct.pack("<B", len(rtx.tx_out1["pk_script"])).hex()
ha10 = ('76a914%s88ac' % charlie2_hashed_pubkey)
ha11 = struct.pack("<Q", 50000).hex()
ha12 = struct.pack("<B", len(rtx.tx_out2["pk_script"])).hex()
ha13 = ('76a914%s88ac' % bob2_hashed_pubkey)
ha14 = rtx.lock_time.hex()
my output is :
01000000
01
5cd81501e2a63c942fcb24de76d4532406156c8cb10b5dcb123a1cb5be13d884
00000000
8b
48
304502207088158730ae6a7f0d6bc51e3e6ea30fb36599a5017760f222f20dee8a4d6701022100ff1636de2d06332e78532bcb8cfcb15db4bd956bd53bbe98ace82d1c2f6b9c2b014
10437078f8c4a54b67cd1724a3535cb1918bca186c7a143459c9aac35113d4a958b0d4eea6b320fa82c17147b72e0fe11c08b0054897ffb7bdb194f259b0db9e129
ffffffff
02
a086010000000000
1976a914478075922af41fb441aa0ab67e91aef27ef1e68688ac
50c3000000000000
1976a914ec06b2bf18c89706855f761d215f21f3315b399488ac
00000000
her output is:
01000000
01
5cd81501e2a63c942fcb24de76d4532406156c8cb10b5dcb123a1cb5be13d884
00000000
8b
48
304502205139475c3a1b5d6c009d1856fcc906a50e594eac92e317e989fec0fd2a1f73b8022100d36ba3cc952ef0e71df0b6f0215cdc7136e90ce6134cd21245645bbc7b63bc6a01410437078f8c4a54b67cd1724a3535cb1918bca186c7a143459c9aac35113d4a958b0d4eea6b320fa82c17147b72e0fe11c08b0054897ffb7bdb194f259b0db9e129
ffffffff
02
a086010000000000
19
76a914478075922af41fb441aa0ab67e91aef27ef1e68688ac
50c3000000000000
19
76a914ec06b2bf18c89706855f761d215f21f3315b399488ac
00000000
Can one let me know why my signature script is a not identical?