redactForLog static method
A copy of an inbound frame safe for the (debug-only) wire log: the
value of every set_text / type step (params.text) is replaced by
<redacted len=N>. Whether the target is a PIN / password field is
only known later, on the device, so every typed value is redacted.
Implementation
@visibleForTesting
static Map<String, dynamic> redactForLog(Map<String, dynamic> json) {
final steps = json['steps'];
if (steps is! List) return json;
var touched = false;
final out = <dynamic>[];
for (final st in steps) {
if (st is Map &&
(st['action'] == 'set_text' || st['action'] == 'type') &&
st['params'] is Map &&
(st['params'] as Map).containsKey('text')) {
final params = Map<String, dynamic>.from(st['params'] as Map);
final v = params['text'];
params['text'] = '<redacted len=${v is String ? v.length : 0}>';
out.add({...Map<String, dynamic>.from(st), 'params': params});
touched = true;
} else {
out.add(st);
}
}
return touched ? {...json, 'steps': out} : json;
}