From 63f059b7a0dd13e5ea9d212ca85966e180299312 Mon Sep 17 00:00:00 2001 From: Fabrizio <26501317+fabriziofff@users.noreply.github.com> Date: Fri, 29 Nov 2024 20:14:41 +0100 Subject: [PATCH] update react-native-passkey --- apps/mobile-app/ios/Podfile.lock | 6 ++-- .../src/common/passkey/authenticate.ts | 33 +++++-------------- .../mobile-app/src/common/passkey/register.ts | 33 +++++-------------- libs/api-schema/src/lib/internalTypes.ts | 19 ++++++----- package.json | 2 +- yarn.lock | 8 ++--- 6 files changed, 34 insertions(+), 67 deletions(-) diff --git a/apps/mobile-app/ios/Podfile.lock b/apps/mobile-app/ios/Podfile.lock index a5e9187..c39976c 100644 --- a/apps/mobile-app/ios/Podfile.lock +++ b/apps/mobile-app/ios/Podfile.lock @@ -396,7 +396,7 @@ PODS: - React-jsinspector (0.72.6) - React-logger (0.72.6): - glog - - react-native-passkey (2.1.1): + - react-native-passkey (3.0.0): - React-Core - react-native-safe-area-context (4.6.3): - RCT-Folly @@ -748,7 +748,7 @@ SPEC CHECKSUMS: React-jsiexecutor: 3bf18ff7cb03cd8dfdce08fbbc0d15058c1d71ae React-jsinspector: 194e32c6aab382d88713ad3dd0025c5f5c4ee072 React-logger: cebf22b6cf43434e471dc561e5911b40ac01d289 - react-native-passkey: 29ff814a83dfd4311478498e71a801dce68043ac + react-native-passkey: 1f8d18b3d0202ae5f6171cd39e3193247ab6f1af react-native-safe-area-context: 36cc67648134e89465663b8172336a19eeda493d React-NativeModulesApple: 02e35e9a51e10c6422f04f5e4076a7c02243fff2 React-perflogger: e3596db7e753f51766bceadc061936ef1472edc3 @@ -774,4 +774,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 0af5f9eae31c4f74d02762d86b314e00e744da35 -COCOAPODS: 1.11.3 +COCOAPODS: 1.15.2 diff --git a/apps/mobile-app/src/common/passkey/authenticate.ts b/apps/mobile-app/src/common/passkey/authenticate.ts index 6f5760b..d7a3929 100644 --- a/apps/mobile-app/src/common/passkey/authenticate.ts +++ b/apps/mobile-app/src/common/passkey/authenticate.ts @@ -9,40 +9,24 @@ import { JwtTokenResponse, PublicKeyCredentialRequestOptions, } from '@passkey-example/api-schema'; + import { - PasskeyAuthenticationRequest, - PasskeyAuthenticationResult, -} from 'react-native-passkey/lib/typescript/Passkey'; -import base64url from 'base64url'; -import { Passkey } from 'react-native-passkey'; + Passkey, + PasskeyGetRequest, + PasskeyGetResult, +} from 'react-native-passkey'; import { parsePasskeyError } from './errors'; -const convertToReactNativePasskeyOptions = ( - options: PublicKeyCredentialRequestOptions -): PasskeyAuthenticationRequest => ({ - ...options, - challenge: base64url.toBase64(options.challenge), -}); - -const nativeAuthenticatePasskey = (request: PasskeyAuthenticationRequest) => +const nativeAuthenticatePasskey = (request: PasskeyGetRequest) => Effect.tryPromise({ - try: () => Passkey.authenticate(request), + try: () => Passkey.get(request), catch: parsePasskeyError, }); const convertToAuthenticationResponseJSON = ( - response: PasskeyAuthenticationResult + response: PasskeyGetResult ): AuthenticationResponseJSON => ({ ...response, - id: base64url.fromBase64(response.id), - rawId: base64url.fromBase64(response.rawId), - response: { - clientDataJSON: base64url.fromBase64(response.response.clientDataJSON), - authenticatorData: base64url.fromBase64( - response.response.authenticatorData - ), - signature: base64url.fromBase64(response.response.signature), - }, clientExtensionResults: {}, type: 'public-key', }); @@ -52,7 +36,6 @@ export const authenticatePasskey = () => axiosGenerateAuthenticationOptions(), Effect.map((response) => response.data), Effect.flatMap(S.parseEither(PublicKeyCredentialRequestOptions)), - Effect.map(convertToReactNativePasskeyOptions), Effect.flatMap(nativeAuthenticatePasskey), Effect.map(convertToAuthenticationResponseJSON), Effect.flatMap(axiosVerifyAuthenticationOptions), diff --git a/apps/mobile-app/src/common/passkey/register.ts b/apps/mobile-app/src/common/passkey/register.ts index cb33eb9..51f28a6 100644 --- a/apps/mobile-app/src/common/passkey/register.ts +++ b/apps/mobile-app/src/common/passkey/register.ts @@ -9,40 +9,24 @@ import { JwtTokenResponse, RegistrationResponseJSON, } from '@passkey-example/api-schema'; -import { - PasskeyRegistrationRequest, - PasskeyRegistrationResult, -} from 'react-native-passkey/lib/typescript/Passkey'; import base64url from 'base64url'; -import { Passkey } from 'react-native-passkey'; +import { + Passkey, + PasskeyCreateRequest, + PasskeyCreateResult, +} from 'react-native-passkey'; import { parsePasskeyError } from './errors'; -const convertCredentialCreationOptionsToReactNativePasskeyOptions = ( - options: CredentialCreationOptions -): PasskeyRegistrationRequest => ({ - ...options, - challenge: base64url.toBase64(options.challenge), -}); - -const nativeRegisterPasskey = (request: PasskeyRegistrationRequest) => +const nativeRegisterPasskey = (request: PasskeyCreateRequest) => Effect.tryPromise({ - try: () => Passkey.register(request), + try: () => Passkey.create(request), catch: parsePasskeyError, }); const convertToRegistrationResponse = (email: string) => - (result: PasskeyRegistrationResult): RegistrationResponseJSON => ({ + (result: PasskeyCreateResult): RegistrationResponseJSON => ({ ...result, - id: base64url.fromBase64(result.id), - rawId: base64url.fromBase64(result.rawId), - response: { - ...result.response, - attestationObject: base64url.fromBase64( - result.response.attestationObject - ), - clientDataJSON: base64url.fromBase64(result.response.clientDataJSON), - }, clientExtensionResults: {}, type: 'public-key', email, @@ -54,7 +38,6 @@ export const registerPasskey = (email: string) => { axiosGenerateRegistrationOptions, Effect.map((response) => response.data), Effect.flatMap(S.parseEither(CredentialCreationOptions)), - Effect.map(convertCredentialCreationOptionsToReactNativePasskeyOptions), Effect.flatMap(nativeRegisterPasskey), Effect.map(convertToRegistrationResponse(email)), Effect.flatMap(axiosVerifyRegistrationOptions), diff --git a/libs/api-schema/src/lib/internalTypes.ts b/libs/api-schema/src/lib/internalTypes.ts index 4e323a2..6ca0f0e 100644 --- a/libs/api-schema/src/lib/internalTypes.ts +++ b/libs/api-schema/src/lib/internalTypes.ts @@ -1,15 +1,16 @@ // https://w3c.github.io/webauthn/#enum-transport import * as S from '@effect/schema/Schema'; -export const AuthenticatorTransportFuture = S.literal( - 'ble', - 'internal', - 'nfc', - 'usb', - 'cable', - 'smart-card', - 'hybrid' -); +enum AuthenticatorTransport { + usb = 'usb', + nfc = 'nfc', + ble = 'ble', + smartCard = 'smart-card', + hybrid = 'hybrid', + internal = 'internal', +} + +export const AuthenticatorTransportFuture = S.enums(AuthenticatorTransport); // https://w3c.github.io/webauthn/#dom-authenticatorselectioncriteria-authenticatorattachment export const AuthenticatorAttachment = S.literal('cross-platform', 'platform'); diff --git a/package.json b/package.json index 670f010..89c56e2 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.72.6", - "react-native-passkey": "^2.1.1", + "react-native-passkey": "^3.0.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-svg": "13.9.0", diff --git a/yarn.lock b/yarn.lock index 853d527..b6fe837 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11826,10 +11826,10 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-native-passkey@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/react-native-passkey/-/react-native-passkey-2.1.1.tgz#30a1f4d99e22a209a4cc1e64b37a363c06eac8c3" - integrity sha512-/SBlL+8aJOiAAyO4jmRhJAxo1LklMpjQijLyl1jZlt9bKtRnh4Uz94z7AYouBR2anTB+DaEycLIhunG7h8Xbwg== +react-native-passkey@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/react-native-passkey/-/react-native-passkey-3.0.0.tgz#f81255bca91c0b64b4dc940df9b4f5b53d4131c2" + integrity sha512-U26Jaz8BeN+LxB9a5rwJiDHIYNBj7sobfnlQnkfyuqylKnSHxzThOnYcJq3WGCSzTYNI5DT0xUtArQkc482fkQ== react-native-safe-area-context@4.6.3: version "4.6.3"