-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathTransactions - python 3.5.py
107 lines (66 loc) · 2.97 KB
/
Transactions - python 3.5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#p2pkh
version = (1).to_bytes(4, byteorder="little", signed=False)
tx_in_count = (1).to_bytes(1, byteorder="little", signed=False)
tx_in = "soon!"
tx_out_count = (1).to_bytes(1, byteorder="little", signed=False)
tx_out = "soon!"
lock_time = (0).to_bytes(4, byteorder="little", signed=False)
tx_out_value = (299000000).to_bytes(8, byteorder="little", signed=True)
tx_out_pubScript = bytes.fromhex("76a91431726579c6ab17fe2f85e236309d4c0bcff2805588ac")
tx_out_pubScript_size = bytes.fromhex("19")
prv_tx_id = bytes.fromhex("192730e77f297a5b805fac2a833948c761e79c1d74929d170523d624d20aff193")
reversed_prv_tx_id = bytearray(prv_tx_id)
reversed_prv_tx_id.reverse()
index = (2).to_bytes(4, byteorder="little", signed=False)
sigScript_raw = bytes.fromhex("76a91486501b046d9c67aa1e361cbf49cfc6482fd16d1b88ac")
sigScript_raw_size = bytes.fromhex("19")
sequence = bytes.fromhex("ffffffff")
raw_tx = ( version
+ tx_in_count
+ reversed_prv_tx_id
+ index
+ sigScript_raw_size
+ sigScript_raw
+ sequence
+ tx_out_count
+ tx_out_value
+ tx_out_pubScript_size
+ tx_out_pubScript
+ lock_time
+ (1).to_bytes(4, byteorder="little", signed=False) #hash code
)
print(raw_tx.hex())
import hashlib
hash_1 = hashlib.sha256(raw_tx).digest()
hash_2 = hashlib.sha256(hash_1).digest()
print(hash_2.hex())
import ecdsa
privateKey = bytes.fromhex("")
sk = ecdsa.SigningKey.from_string(privateKey, curve=ecdsa.SECP256k1)
verifying_key = sk.get_verifying_key()
public_key = bytes.fromhex("04") + verifying_key.to_string()
signature = sk.sign_digest(hash_2, sigencode = ecdsa.util.sigencode_der_canonize)
sigScript = ((len(signature) + 1).to_bytes(1, byteorder="little", signed=False)
+ signature
+ bytes.fromhex("01")
+(len(public_key)).to_bytes(1, byteorder="little", signed=False)
+ public_key
)
sigScript_size = (int(len(sigScript))).to_bytes(1, byteorder="little", signed=False)
REAL_TX = ( version
+ tx_in_count
+ reversed_prv_tx_id
+ index
+ sigScript_size
+ sigScript
+ sequence
+ tx_out_count
+ tx_out_value
+ tx_out_pubScript_size
+ tx_out_pubScript
+ lock_time
)
print(REAL_TX.hex())
hash_1 = hashlib.sha256(bytes.fromhex("0100000001e18e68f7fc653a9f3e249c887f03963bf5c8d10f8afc01944a1126af36e98a19060000008a4730440220113f91f8d10725b3a279cf4bd4de3d43c21d94210d22acde8f9e58c7240e884c022061b05a6ccdf8dbad5b34eb57ff6832eb2a7cb584b828bdd8ada6ec843438348d01410448d297e22dbd448f2a00501a6336c15b809df00228c527e4221338d0ce9999439e80f93a6b4c1e8281724967a62bcf44142d46dfc72d31f58b8304556f5f70aaffffffff01c060d211000000001976a91486501b046d9c67aa1e361cbf49cfc6482fd16d1b88ac00000000")).digest()
hash_2 = hashlib.sha256(hash_1).digest()
print(hash_2.hex())