signToPasskeySignature method
override
Signs the intended request and returns the signedMessage.
hash
: The hash of the intended request.credentialId
: The credential id.
Returns a PassKeySignature
.
Implementation
@override
Future<PassKeySignature> signToPasskeySignature(
Uint8List hash, String credentialId) async {
final webAuthnOptions = _opts;
webAuthnOptions.type = "webauthn.get";
// Prepare hash
final hashBase64 = base64Url
.encode(hash)
.replaceAll(RegExp(r'=', multiLine: true, caseSensitive: false), '');
// Prepare challenge
final challenge32 =
clientDataHash32(webAuthnOptions, challenge: hashBase64);
// Authenticate
final assertion = await _authenticate([credentialId], challenge32, true);
final sig = await getMessagingSignature(assertion.signature);
// Prepare challenge for response
final challenge = clientDataHash(webAuthnOptions, challenge: hashBase64);
final clientDataJSON = utf8.decode(challenge);
int challengePos = clientDataJSON.indexOf(hashBase64);
String challengePrefix = clientDataJSON.substring(0, challengePos);
String challengeSuffix =
clientDataJSON.substring(challengePos + hashBase64.length);
return PassKeySignature(
base64Url.encode(assertion.selectedCredentialId),
[
Uint256.fromHex(sig[0]),
Uint256.fromHex(sig[1]),
],
assertion.authenticatorData,
challengePrefix,
challengeSuffix,
);
}