Skip to content

Commit

Permalink
Attempt at resolving broken Android types
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Nov 19, 2024
1 parent 3d4b135 commit d4f10ca
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/react-native-passkey-stamper/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Passkey } from "react-native-passkey";
import {
Passkey,
PasskeyCreateResult,
PasskeyGetResult,
} from "react-native-passkey";
import type { TurnkeyApiTypes } from "@turnkey/http";
import { base64StringToBase64UrlEncodedString as base64Tobase64url } from "@turnkey/encoding";
import { getChallengeFromPayload, getRandomChallenge } from "./util";
Expand Down Expand Up @@ -120,6 +124,10 @@ export function isSupported(): boolean {
return Passkey.isSupported();
}

// Context: https://github.com/f-23/react-native-passkey/issues/54
type BrokenPasskeyCreateResult = PasskeyCreateResult | string;
type BrokenPasskeyGetResult = PasskeyGetResult | string;

/**
* Creates a passkey and returns authenticator params
*/
Expand All @@ -137,7 +145,8 @@ export async function createPasskey(
: options?.withSecurityKey
? Passkey.createSecurityKey
: Passkey.create;
const registrationResult = await createFn({

let registrationResult = await createFn({
challenge: challenge,
rp: config.rp,
user: config.user,
Expand All @@ -163,6 +172,15 @@ export async function createPasskey(
],
});

// See https://github.com/f-23/react-native-passkey/issues/54
// On Android the typedef lies. Registration result is actually a string!
// TODO: remove me once the above is resolved.
const brokenRegistrationResult =
registrationResult as BrokenPasskeyCreateResult;
if (typeof brokenRegistrationResult === "string") {
registrationResult = JSON.parse(brokenRegistrationResult);
}

return {
authenticatorName: config.authenticatorName,
challenge: challenge,
Expand Down Expand Up @@ -220,7 +238,16 @@ export class PasskeyStamper {
: this.forceSecurityKey
? Passkey.getSecurityKey
: Passkey.get;
const authenticationResult = await passkeyGetfn(signingOptions);
let authenticationResult = await passkeyGetfn(signingOptions);

// See https://github.com/f-23/react-native-passkey/issues/54
// On Android the typedef lies. Authentication result is actually a string!
// TODO: remove me once the above is resolved.
const brokenAuthenticationResult =
authenticationResult as BrokenPasskeyGetResult;
if (typeof brokenAuthenticationResult === "string") {
authenticationResult = JSON.parse(brokenAuthenticationResult);
}

const stamp = {
authenticatorData: base64Tobase64url(
Expand Down

0 comments on commit d4f10ca

Please sign in to comment.