-
Notifications
You must be signed in to change notification settings - Fork 8
/
demo.py
53 lines (42 loc) · 2.26 KB
/
demo.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
from ledgerblue.comm import getDongle
from ledgerblue.commException import CommException
import argparse
import struct
def parse_bip32_path(path):
if len(path) == 0:
return ""
result = ""
elements = path.split('/')
for pathElement in elements:
element = pathElement.split('\'')
if len(element) == 1:
result = result + struct.pack(">I", int(element[0]))
else:
result = result + struct.pack(">I", 0x80000000 | int(element[0]))
return result
parser = argparse.ArgumentParser()
parser.add_argument('--path', help="BIP 32 path to sign with")
parser.add_argument('--tx', help="TX to sign, hex encoded")
args = parser.parse_args()
if args.path == None:
args.path="44'/3030'/0'/0'/0'"
#if args.tx == None:
# raise Exception("Missing TX")
#args.tx = args.tx.decode('hex')
donglePath = parse_bip32_path(args.path)
pathLength = len(donglePath) + 1
p1 = "80"
p2 = "80"
#data1 = ("0a130a0c08e9b2ace60510e088a88103120318ce101202180318a08d062202081e320d54657374205472616e7366657272140a120a070a0318cc1010010a070a0318cd101002").decode('hex')
data1 = ("0a120a0b0899cf80e80510b88be609120318e9071202180318a08d062202081e320f48617264776172653157616c6c657472180a160a090a0318e90710a79a010a090a0318f20710a89a01").decode('hex')
apdu = ("e002" + p1 + p2).decode('hex') + chr(pathLength) + chr(len(donglePath) / 4) + donglePath
#apdu = ("e004" + p1 + p2).decode('hex') + chr(pathLength + len(data1)) + chr(len(donglePath) / 4) + donglePath + data1
dongle = getDongle(True)
result = dongle.exchange(bytes(apdu))
#0a130a0c08e9b2ace60510e088a88103120318ce101202180318a08d062202081e320d54657374205472616e7366657272140a120a070a0318cc1010010a070a0318cd101002
#if data2 != None:
# apdu = "e0048140".decode('hex') + chr(len(data2)) + data2
# result = dongle.exchange(bytes(apdu))
#result = dongle.exchange(bytes("e0040040a0058000002c80000090800000008000000000000000000b207900039f97d5a32fa1a1a0e12920f5ed21fde918a11ebf14cd42b70b4cc3633b027fcf175fa2a273f5a34d65710e67fc2b4bfe50d0d8140a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e9a435000000008096980000000000".decode('hex')))
# result = dongle.exchange(bytes("e002004096058000002c80000090800000008000000000000000".decode('hex')))
#print "publicKey " + str(result).encode('hex')