forked from jelurida-dev/app-ledger-ardor-main
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.py
152 lines (137 loc) · 11.4 KB
/
test.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from ledgerblue.comm import getDongle
from ledgerblue.commException import CommException
# from secp256k1 import PublicKey
import binascii
import codecs
dongle = getDongle(True)
CLA = "80"
# Derivation path, header of 44'/30' used on the App
ACCOUNT = "00"
CHANGE = "00"
INDEX = "01"
P1 = "00"
P2 = "00"
# Instructions accepted by the Burst Ledger App
INS_GET_VERSION = "01"
INS_AUTH_SIGN_TXN = "03"
INS_ENCRYPT_DECRYPT_MSG = "04"
INS_SHOW_ADDRESS = "05"
INS_GET_PUBLIC_KEY = "06"
INS = INS_GET_VERSION
LEN = "00"
DATA = ""
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("version ", binascii.hexlify(ret))
INS = INS_GET_PUBLIC_KEY
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
print("publicKey ", binascii.hexlify(ret[1:1+32]))
# Show the address for the given index, blocks for user input (wait for an accept)
INS = INS_SHOW_ADDRESS
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
# An ordinary payment transaction
INS = INS_AUTH_SIGN_TXN
P1 = "11" # sign init and authorize
DATA = "0010b40ad80ae803c980cdc2fded5c1d402fc37eb46eee66706574f037469d47da14f9d7df53f834b6592e05e1c7d3a900e1f505000000008096980000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005191020085834c122c1c5665"
LEN = "b0" # 176
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
P1 = "03" # sign finish
P2 = "00"
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
print("sig ", binascii.hexlify(ret[1:1+64]))
# Token transfer transaction
INS = INS_AUTH_SIGN_TXN
P1 = "11" # sign init and authorize
DATA = "0211223fd80ae80334a7ca8bbded4e3f24c60ecb655f9235ac1b12d97aea698c554df8bf1d950f2db6592e05e1c7d3a900000000000000008096980000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008a9102008981c4210120df530151a4f5468b89f5faa00f000000000000"
LEN = "c1" # 193
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
P1 = "03" # sign finish
P2 = "00"
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
print("sig ", binascii.hexlify(ret[1:1+64]))
# Token transfer transaction (TRT)
INS = INS_AUTH_SIGN_TXN
P1 = "11" # sign init and authorize
DATA = "0211e405d90aa005416d25901e5b4f8e03d00c92fd508798d3794883e4a73630ab9e88454b7aed49d84228d09c9f7e2d0000000000000000b0dfc90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009a7b0b0025241b746d4b92e2018409fe8f2e3b1eace803000000000000"
LEN = "c1" # 193
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
P1 = "03" # sign finish
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
print("sig ", binascii.hexlify(ret[1:1+64]))
# Token buy offer (TRT)
INS = INS_AUTH_SIGN_TXN
P1 = "11" # sign init and authorize
DATA = "02130609d90aa005416d25901e5b4f8e03d00c92fd508798d3794883e4a73630ab9e88454b7aed4900000000000000000000000000000000209586000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a27b0b00add44456cab796a4018409fe8f2e3b1eac50c3000000000000c409000000000000"
LEN = "c9" # 201
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
P1 = "03" # sign finish
P2 = "00"
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
print("sig ", binascii.hexlify(ret[1:1+64]))
# Token cancel offer
INS = INS_AUTH_SIGN_TXN
P1 = "11" # sign init and authorize
DATA = "0215840cd90aa005416d25901e5b4f8e03d00c92fd508798d3794883e4a73630ab9e88454b7aed4900000000000000000000000000000000209586000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a47b0b0065491ec2c52052c7019567ff4148b62b98"
LEN = "b9" # 185
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
P1 = "03" # sign finish
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
print("sig ", binascii.hexlify(ret[1:1+64]))
# Register a contract total length is 2598 (a26 in hex), send the first 176 bytes and later the remaining length
DATA_CONTRACT = "1610537eda0aa0050f60494941ed795b7296174a58dd9946eda87c07fe29cd16a561ab72429a5d010000000000000000000000000000000030fab1050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e8930200aa466d324c0de0a101054254444558210042544445582073656c6c20636f6e74726163742031353839383133373436333933020000000a00010001000100002d3101000000001d0901170000001800000000000000320b0335040116000000303304030c0000003500010d0000001e0d00000007283507030c000000320a033504010f0000003506030e0000003209033504011300000001100000003587d5c34408df950710000000130000001e1000000010120f0100001a1800000001100000002b665d12e76b8b940710000000130000001e100000001e350501180000003506011a00000012fa0100001a18000000011000000031276f22f01aad700710000000130000001e100000001e350501180000003506011a000000127d0300001a180000000110000000b00e004992c79bd80710000000130000001e10000000173505011800000012b60700001a180000001a1800000002100000000600000007100000000f0000001b100000000b1af901000001110000002000000000000000101100000011110000000210000000030000000710000000110000001010000000111000000003110000002110000000110000000f1af90100000210000000050000000610000000040000001010000000101600000011100000001111000000331601100000003302041100000002100000000500000007100000000700000010100000001111000000331601060000003302041100000003110000001011000000110600000003110000001011000000110300000033160100000000320304130111000000010000000000000010110000001111000000021000000003000000071000000011000000101000000011100000001b100000000b1a4d0300000211000000170000000e100000001100000010100000001111000000021000000005000000071000000011000000101000000011100000001b100000000b1a4d030000021100000017000000041100000004110000000e100000001100000010100000001111000000021000000004000000071000000011000000101000000011100000001b100000000b1a4d030000021100000017000000041100000004110000000e100000001100000010100000000211000000170000000e10000000110000001010000000111100000011100000000610000000110000001010000000111100000002100000000e0000000710000000110000001010000000111000000003110000002010000000110000000f1a5c0300003316010f0000003302040e00000013011100000020000000000000001011000000110300000002060000000f0000001301110000002000000000000000101100000011110000000210000000030000000710000000110000001010000000111000000003110000002110000000110000000f1a570400001016000000111000000007100000000f0000001b100000000b1a570400000211000000170000000e100000001100000010100000001108000000021100000017000000041100000004110000000e10000000110000001010000000110900000001110000000002000000000000101100000011110000000210000000030000000a10000000110000001010000000110300000001110000002000000000000000101100000011110000000210000000030000000710000000110000001010000000111000000003110000002110000000110000000f1a3005000002100000000600000007100000000f0000001b100000000b1a300500000211000000170000000e10000000110000001010000000110a000000021100000017000000041100000004110000000e10000000110000001010000000110b00000001110000000004000000000000101100000011110000000210000000030000000a10000000110000001010000000110300000001110000000001000000000000101100000011110000000210000000030000000710000000110000001010000000111000000003110000002110000000110000000f1ab105000002100000000100000007100000000f0000001e100000000b1a6706000002100000000200000007100000000f0000001e100000000b1a6706000001110000000006000000000000101100000011110000000210000000030000000b1000000011000000101000000001110000000006000000000000101100000011110000001110000000071000000011000000101000000011100000001b100000000b1ab507000002100000000800000007100000000a000000101000000011100000001b100000000b1ab507000002100000000900000007100000000b000000101000000011100000001b100000000b1ab50700000211000000170000000e10000000110000001010000000021100000017000000041100000004110000000e1000000011000000101000000011110000001110000000061000000011000000101000000002100000000400000006100000000500000010100000001110000000061000000005000000101000000011100000000710000000070000001010000000111100000011100000000710000000110000001010000000111000000003110000002010000000110000000f1a8d0700000211000000170000000e100000001100000010100000001016000000111000000011110000003316011000000033020411000000021100000017000000041100000004110000000e100000001100000010100000001111000000331601060000003302041100000003110000001011000000110600000003110000001011000000110300000033160100000000320304131016000000111000000007100000000f0000001b100000000b1a1c09000001110000001000000000000000101100000011110000000210000000030000000710000000110000001010000000111000000003110000002010000000110000000f1a1c0900000211000000170000000e10000000110000001010000000110400000001110000000100000000000000101100000011030000000211000000170000000e100000001100000010100000000311000000101100000011110000001110000000071000000011000000101000000011100000001b100000000b1ac50800000311000000101100000011050000000311000000101100000011030000001016000000331601160000003203041335000410000000101000000011050000000211000000170000000e10000000110000001010000000011100000090010000000000001011000000111100000011100000000910000000110000001010000000110700000013180e640300000000002b308f6b8f15f951a23677e9ce2322cf"
print ((len(DATA_CONTRACT)))
INS = INS_AUTH_SIGN_TXN
P1 = "01" # sign init
LEN = "ff" # 255
DATA = DATA_CONTRACT[0:255*2]
DATA_CONTRACT = DATA_CONTRACT[255*2:]
print ('data len: ', len(DATA))
print ('remaining: ', len(DATA_CONTRACT))
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
while len(DATA_CONTRACT) > 255*2 :
P1 = "02" # sign continue
DATA = DATA_CONTRACT[0:255*2]
DATA_CONTRACT = DATA_CONTRACT[255*2:]
print ('data len: ', len(DATA))
print ('remaining: ', len(DATA_CONTRACT))
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
P1 = "12" # sign continue and authorize
DATA = DATA_CONTRACT
print ('data len: ', len(DATA))
LEN = format(len(DATA)>>1, 'x')
print (LEN)
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
P1 = "03" # sign finish
LEN = "03"
DATA = ACCOUNT + CHANGE + INDEX
ret = dongle.exchange(bytearray.fromhex(CLA + INS + P1 + P2 + LEN + DATA))
print("ret ", str(ret[0]))
print("sig ", binascii.hexlify(ret[1:1+64]))