@@ -53,11 +53,19 @@ const NanospClickTable = new Map([
53
53
] )
54
54
55
55
const StaxClickTable = new Map ( [
56
- [ OutputType . Base , 2 ] ,
57
- [ OutputType . Multisig , 3 ] ,
58
- [ OutputType . Token , 3 ] ,
59
- [ OutputType . BaseAndToken , 3 ] ,
60
- [ OutputType . MultisigAndToken , 4 ] ,
56
+ [ OutputType . Base , 1 ] ,
57
+ [ OutputType . Multisig , 2 ] ,
58
+ [ OutputType . Token , 2 ] ,
59
+ [ OutputType . BaseAndToken , 2 ] ,
60
+ [ OutputType . MultisigAndToken , 2 ] ,
61
+ ] )
62
+
63
+ const FlexClickTable = new Map ( [
64
+ [ OutputType . Base , 1 ] ,
65
+ [ OutputType . Multisig , 2 ] ,
66
+ [ OutputType . Token , 2 ] ,
67
+ [ OutputType . BaseAndToken , 2 ] ,
68
+ [ OutputType . MultisigAndToken , 3 ] ,
61
69
] )
62
70
63
71
function getOutputClickSize ( outputType : OutputType ) {
@@ -66,8 +74,8 @@ function getOutputClickSize(outputType: OutputType) {
66
74
case 'nanos' : return NanosClickTable . get ( outputType ) !
67
75
case 'nanosp' :
68
76
case 'nanox' : return NanospClickTable . get ( outputType ) !
69
- case 'stax' :
70
- case 'flex' : return StaxClickTable . get ( outputType ) !
77
+ case 'stax' : return StaxClickTable . get ( outputType ) !
78
+ case 'flex' : return FlexClickTable . get ( outputType ) !
71
79
default : throw new Error ( `Unknown model ${ model } ` )
72
80
}
73
81
}
@@ -95,12 +103,16 @@ const STAX_APPROVE_POSITION = { x: 200, y: 515 }
95
103
const STAX_REJECT_POSITION = { x : 36 , y : 606 }
96
104
const STAX_SETTINGS_POSITION = { x : 342 , y : 55 }
97
105
const STAX_BLIND_SETTING_POSITION = { x : 342 , y : 90 }
106
+ const STAX_GO_TO_SETTINGS = { x : 36 , y : 606 }
107
+ const STAX_ACCEPT_RISK_POSITION = { x : 36 , y : 606 }
98
108
99
109
const FLEX_CONTINUE_POSITION = { x : 430 , y : 550 }
100
110
const FLEX_APPROVE_POSITION = { x : 240 , y : 435 }
101
111
const FLEX_REJECT_POSITION = { x : 55 , y : 530 }
102
112
const FLEX_SETTINGS_POSITION = { x : 405 , y : 75 }
103
113
const FLEX_BLIND_SETTING_POSITION = { x : 405 , y : 96 }
114
+ const FLEX_GO_TO_SETTINGS = { x : 55 , y : 530 }
115
+ const FLEX_ACCEPT_RISK_POSITION = { x : 55 , y : 530 }
104
116
105
117
async function touchPosition ( pos : Position ) {
106
118
await sleep ( 1000 )
@@ -110,14 +122,24 @@ async function touchPosition(pos: Position) {
110
122
} )
111
123
}
112
124
113
- async function _touch ( times : number ) {
125
+ async function longPress ( pos : Position ) {
126
+ await sleep ( 1000 )
127
+ return fetch ( `http://localhost:25000/finger` , {
128
+ method : 'POST' ,
129
+ body : JSON . stringify ( { action : 'press-and-release' , x : pos . x , y : pos . y , delay : 3 } )
130
+ } )
131
+ }
132
+
133
+ async function _touch ( times : number , approve : boolean = false ) {
114
134
const model = getModel ( )
115
135
const continuePos = model === 'stax' ? STAX_CONTINUE_POSITION : FLEX_CONTINUE_POSITION
116
136
for ( let i = 0 ; i < times ; i += 1 ) {
117
137
await touchPosition ( continuePos )
118
138
}
119
- const approvePos = model === 'stax' ? STAX_APPROVE_POSITION : FLEX_APPROVE_POSITION
120
- await touchPosition ( approvePos )
139
+ if ( approve ) {
140
+ const approvePos = model === 'stax' ? STAX_APPROVE_POSITION : FLEX_APPROVE_POSITION
141
+ await longPress ( approvePos )
142
+ }
121
143
}
122
144
123
145
export async function staxFlexApproveOnce ( ) {
@@ -129,16 +151,19 @@ export async function staxFlexApproveOnce() {
129
151
}
130
152
131
153
async function touch ( outputs : OutputType [ ] , hasExternalInputs : boolean ) {
132
- await sleep ( 1000 ) ;
154
+ await sleep ( 3000 ) ;
133
155
if ( hasExternalInputs ) {
134
156
await staxFlexApproveOnce ( )
135
157
}
136
158
159
+ _touch ( 1 ) // the first review page
160
+ await sleep ( 1000 )
161
+
137
162
for ( let index = 0 ; index < outputs . length ; index += 1 ) {
138
163
await _touch ( getOutputClickSize ( outputs [ index ] ) )
139
164
}
140
165
141
- await _touch ( 2 ) // fees
166
+ await _touch ( 1 , true ) // fees
142
167
}
143
168
144
169
export async function approveTx ( outputs : OutputType [ ] , hasExternalInputs : boolean = false ) {
@@ -147,7 +172,7 @@ export async function approveTx(outputs: OutputType[], hasExternalInputs: boolea
147
172
const isSelfTransfer = outputs . length === 0 && ! hasExternalInputs
148
173
if ( isSelfTransfer ) {
149
174
if ( isStaxOrFlex ( ) ) {
150
- await _touch ( 2 )
175
+ await _touch ( 2 , true )
151
176
} else {
152
177
await clickAndApprove ( 2 )
153
178
}
@@ -164,7 +189,7 @@ export async function approveTx(outputs: OutputType[], hasExternalInputs: boolea
164
189
export async function approveHash ( ) {
165
190
if ( ! needToAutoApprove ( ) ) return
166
191
if ( isStaxOrFlex ( ) ) {
167
- return await _touch ( 3 )
192
+ return await _touch ( 2 , true )
168
193
}
169
194
if ( getModel ( ) === 'nanos' ) {
170
195
await clickAndApprove ( 5 )
@@ -176,7 +201,9 @@ export async function approveHash() {
176
201
export async function approveAddress ( ) {
177
202
if ( ! needToAutoApprove ( ) ) return
178
203
if ( isStaxOrFlex ( ) ) {
179
- return await _touch ( 2 )
204
+ await _touch ( 1 )
205
+ await staxFlexApproveOnce ( )
206
+ return
180
207
}
181
208
if ( getModel ( ) === 'nanos' ) {
182
209
await clickAndApprove ( 4 )
@@ -185,21 +212,32 @@ export async function approveAddress() {
185
212
}
186
213
}
187
214
188
- function isStaxOrFlex ( ) : boolean {
215
+ export function isStaxOrFlex ( ) : boolean {
189
216
return ! getModel ( ) . startsWith ( 'nano' )
190
217
}
191
218
192
219
export function isNanos ( ) : boolean {
193
220
return getModel ( ) === 'nanos'
194
221
}
195
222
196
- export function skipBlindSigningWarning ( ) {
223
+ export async function skipBlindSigningWarning ( ) {
197
224
if ( ! needToAutoApprove ( ) ) return
198
225
if ( isStaxOrFlex ( ) ) {
199
- const rejectPos = getModel ( ) === 'stax' ? STAX_REJECT_POSITION : FLEX_REJECT_POSITION
200
- touchPosition ( rejectPos )
226
+ await sleep ( 3000 )
227
+ const goToSettings = getModel ( ) === 'stax' ? STAX_GO_TO_SETTINGS : FLEX_GO_TO_SETTINGS
228
+ await touchPosition ( goToSettings )
229
+ } else {
230
+ await clickAndApprove ( 3 )
231
+ }
232
+ }
233
+
234
+ export async function staxFlexAcceptRisk ( ) {
235
+ if ( ! needToAutoApprove ( ) ) return
236
+ await sleep ( 3000 )
237
+ if ( getModel ( ) === 'stax' ) {
238
+ await touchPosition ( STAX_ACCEPT_RISK_POSITION )
201
239
} else {
202
- clickAndApprove ( 3 )
240
+ await touchPosition ( FLEX_ACCEPT_RISK_POSITION )
203
241
}
204
242
}
205
243
0 commit comments