-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uint8Array --> String --> Uint8Array Conversion from isoUint8Array helper doesn't work #509
Comments
I've noticed that it's working with the // Saving :
const hexCredentialID = isoUint8Array.toHex(verification.registrationInfo.credentialID);
const hexCredentialPublicKey = isoUint8Array.toHex(verification.registrationInfo.credentialPublicKey);
// Authentification Option :
const previousAuthenticator = await Authenticator.findOne({ userId: user._id });
const credentialIDbackFromHex = isoUint8Array.fromHex(previousAuthenticator.credentialID);
console.log('credentialIDbackFromHex = ', credentialIDbackFromHex ); // The "restored" uInt8Array is the same !
const options = await generateAuthenticationOptions({
rpID,
allowCredentials: [
{
id: credentialIDbackFromHex ,
type: 'public-key',
transports: previousAuthenticator.transports,
},
],
userVerification: 'preferred',
}); I can then trigger the windows hello prompt successfully but then on the verify part I get this error : Verify part code : const previousAuthenticator = await Authenticator.findOne({ userId: user?._id });
try {
const backFromHexCredentialID = isoUint8Array.fromHex(previousAuthenticator.credentialID);
const backFromHexPublicKey = isoUint8Array.fromHex(previousAuthenticator.credentialID);
verification = await verifyAuthenticationResponse({
response: challengeResponse,
expectedChallenge: user?.challenge,
expectedOrigin: origin,
expectedRPID: rpID,
authenticator: {
...previousAuthenticator,
credentialID: backFromHexCredentialID,
credentialPublicKey: backFromHexPublicKey,
},
requireUserVerification: true,
});
res.status(200).json({ ok: verification.verified });
} catch (error) {
console.error(error);
return res.status(400).send({ message: error.message });
} |
Credential ID bytes are effectively random so I'm not at all surprised they're not encoding to readable UTF-8. I recommend using the
Looking at your code sample I think I see the problem: const backFromHexPublicKey = isoUint8Array.fromHex(previousAuthenticator.credentialID);
|
O.M.GI can't believe this ! Too much copy / paste kills copy / paste 😢 Sorry to made you loose your time ! And a big thank you ! ♥ At least I've learned that I should probably use |
Describe the issue
I'm trying to convert the credentialID (Uint8Array) to an UTF-8 string in order to save it in my MongoDB Database.
I've tried multiple packages to do so ... Until I found out that there's some helpers into this library itself ...
But the flow : Uint8Array --> String --> Uint8Array seems ... broken ?
Am I missing something ?
Reproduction Steps
And here is the result :
Expected behavior
The converted back Uint8Array should be the same ? Right ? And the String must be UTF-8 no ?
Dependencies
The text was updated successfully, but these errors were encountered: