Skip to content
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

chore: Update react-native-passkey to 3.0.0 #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/mobile-app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -774,4 +774,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 0af5f9eae31c4f74d02762d86b314e00e744da35

COCOAPODS: 1.11.3
COCOAPODS: 1.15.2
33 changes: 8 additions & 25 deletions apps/mobile-app/src/common/passkey/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand All @@ -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),
Expand Down
33 changes: 8 additions & 25 deletions apps/mobile-app/src/common/passkey/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
19 changes: 10 additions & 9 deletions libs/api-schema/src/lib/internalTypes.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

[email protected]:
version "4.6.3"
Expand Down