registerBegin method
Creates options with a 1-64 byte user ID and non-null user names.
Implementation
RegistrationRequest registerBegin(
PublicKeyCredentialUserEntity user, {
List<int>? challenge,
}) {
if (user.id.isEmpty ||
user.id.length > 64 ||
user.id.any((byte) => byte < 0 || byte > 255)) {
throw ArgumentError.value(user.id, 'user.id', 'Expected 1 to 64 bytes');
}
if (user.name == null || user.displayName == null) {
throw ArgumentError('Registration requires name and displayName');
}
final nonce = List<int>.unmodifiable(
challenge ?? RustCrypto.randomBytes(32),
);
if (nonce.length < 16) {
throw ArgumentError('Challenge must be at least 16 bytes');
}
final offered = List<int>.unmodifiable(config.signatureAlgorithms);
return RegistrationRequest(
{
'rp': {'id': config.rpId, 'name': config.rpName},
'user': {
'id': _b64(user.id),
'name': user.name,
'displayName': user.displayName,
},
'challenge': _b64(nonce),
'pubKeyCredParams': [
for (final alg in offered) {'type': 'public-key', 'alg': alg},
],
'attestation': config.attestation.name,
'authenticatorSelection': {
'userVerification': config.requireUserVerification
? 'required'
: 'preferred',
},
},
nonce,
offered,
);
}