PasskeyBinding.fromJson constructor
Implementation
factory PasskeyBinding.fromJson(
Map<String, Object?> json, {
bool allowLocalhost = false,
}) {
final keys = {
'version',
if (json['version'] == 3) ...['route', 'verification', 'transports'],
'prf',
'domain',
'credentialId',
'userId',
'publicKeyCose',
'input',
'backupEligible',
'backupState',
'signCount',
};
if (json.length != keys.length ||
!keys.every(json.containsKey) ||
json['version'] is! int ||
![2, 3].contains(json['version']) ||
(json['version'] == 3 &&
(json['route'] != 'hardware' ||
json['verification'] != 'required' ||
json['transports'] is! List ||
(json['transports'] as List).any((v) => v is! String))) ||
json['backupEligible'] is! bool ||
json['backupState'] is! bool ||
json['signCount'] is! int ||
json['prf'] != 'webauthn-prf-v1' ||
json['domain'] is! String) {
throw const PasskeyException(PasskeyErrorCode.invalidBinding);
}
return PasskeyBinding(
allowLocalhost: allowLocalhost,
route: json['version'] == 3 ? PasskeyRoute.hardware : PasskeyRoute.system,
transports: json['version'] == 3
? (json['transports'] as List).cast<String>()
: const [],
domain: json['domain']! as String,
credentialId: _decode(json['credentialId'], 1024),
userId: _decode(json['userId'], 64),
publicKeyCose: _decode(json['publicKeyCose'], 4096),
input: _decode(json['input'], 1024),
authenticatorState: AuthenticatorState(
backupEligible: json['backupEligible']! as bool,
backupState: json['backupState']! as bool,
signCount: json['signCount']! as int,
),
);
}