Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ruijialin-avalabs committed Jan 21, 2025
1 parent ee3d3d8 commit 7ae06e8
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const FidoNameInput = ({
theme: { colors }
} = useTheme()

const handleClear = (): void => setName('')

return (
<BlurredBarsContentLayout>
<View
Expand Down Expand Up @@ -65,7 +67,7 @@ const FidoNameInput = ({
onChangeText={setName}
placeholder={textInputPlaceholder}
/>
<TouchableOpacity onPress={() => setName('')}>
<TouchableOpacity onPress={handleClear}>
<Icons.Action.Clear
width={16}
height={16}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useRegisterAndAuthenticateFido = (): {
const withSecurityKey = fidoType === FidoType.YUBI_KEY

fidoRegisterInit(passkeyName, async challenge => {
const credential = await PasskeyService.create(
const credential = await PasskeyService.createCredential(
challenge.options,
withSecurityKey
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import Logger from 'utils/Logger'

function useSeedlessManageMFA(): {
totpResetInit: (
onInitialzied: (challenge: TotpChallenge) => void
onInitialized: (challenge: TotpChallenge) => void
) => Promise<void>
fidoRegisterInit: (
name: string,
onInitialzied: (challenge: AddFidoChallenge) => Promise<void>
onInitialized: (challenge: AddFidoChallenge) => Promise<void>
) => Promise<void>
} {
const { verifyMFA } = useVerifyMFA(SeedlessService.sessionManager)

async function totpResetInit(
onInitialzied: (challenge: TotpChallenge) => void
onInitialized: (challenge: TotpChallenge) => void
): Promise<void> {
try {
const totpResetInitResponse =
Expand All @@ -26,7 +26,7 @@ function useSeedlessManageMFA(): {
const handleVerifySuccess: HandleVerifyMfaSuccess<
TotpChallenge
> = async totpChallenge => {
onInitialzied(totpChallenge)
onInitialized(totpChallenge)
}

verifyMFA({
Expand All @@ -36,7 +36,7 @@ function useSeedlessManageMFA(): {
} else {
const totpChallenge = totpResetInitResponse.data()

onInitialzied(totpChallenge)
onInitialized(totpChallenge)
}
} catch (e) {
Logger.error('totpResetInit error', e)
Expand All @@ -46,7 +46,7 @@ function useSeedlessManageMFA(): {

async function fidoRegisterInit(
name: string,
onInitialzied: (challenge: AddFidoChallenge) => Promise<void>
onInitialized: (challenge: AddFidoChallenge) => Promise<void>
): Promise<void> {
try {
const fidoRegisterInitResponse =
Expand All @@ -56,7 +56,7 @@ function useSeedlessManageMFA(): {
const handleVerifySuccess: HandleVerifyMfaSuccess<
AddFidoChallenge
> = async addFidoChallenge => {
onInitialzied(addFidoChallenge)
onInitialized(addFidoChallenge)
}

verifyMFA({
Expand All @@ -66,7 +66,7 @@ function useSeedlessManageMFA(): {
} else {
const addFidoChallenge = fidoRegisterInitResponse.data()

onInitialzied(addFidoChallenge)
onInitialized(addFidoChallenge)
}
} catch (e) {
Logger.error('fidoRegisterInit error', e)
Expand Down
16 changes: 8 additions & 8 deletions packages/core-mobile/app/seedless/hooks/useSeedlessManageMFA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import useVerifyMFA from './useVerifyMFA'

function useSeedlessManageMFA(): {
totpResetInit: (
onInitialzied: (challenge: TotpChallenge) => void
onInitialized: (challenge: TotpChallenge) => void
) => Promise<void>
fidoRegisterInit: (
name: string,
onInitialzied: (challenge: AddFidoChallenge) => Promise<void>
onInitialized: (challenge: AddFidoChallenge) => Promise<void>
) => Promise<void>
fidoDelete: (fidoId: string, onDelete: () => void) => Promise<void>
} {
const { verifyMFA } = useVerifyMFA(SeedlessService.sessionManager)

async function totpResetInit(
onInitialzied: (challenge: TotpChallenge) => void
onInitialized: (challenge: TotpChallenge) => void
): Promise<void> {
try {
const totpResetInitResponse =
Expand All @@ -31,7 +31,7 @@ function useSeedlessManageMFA(): {
const handleVerifySuccess: HandleVerifyMfaSuccess<
TotpChallenge
> = async totpChallenge => {
onInitialzied(totpChallenge)
onInitialized(totpChallenge)
}

verifyMFA({
Expand All @@ -41,7 +41,7 @@ function useSeedlessManageMFA(): {
} else {
const totpChallenge = totpResetInitResponse.data()

onInitialzied(totpChallenge)
onInitialized(totpChallenge)
}
} catch (e) {
Logger.error('totpResetInit error', e)
Expand All @@ -51,7 +51,7 @@ function useSeedlessManageMFA(): {

async function fidoRegisterInit(
name: string,
onInitialzied: (challenge: AddFidoChallenge) => Promise<void>
onInitialized: (challenge: AddFidoChallenge) => Promise<void>
): Promise<void> {
try {
const fidoRegisterInitResponse =
Expand All @@ -61,7 +61,7 @@ function useSeedlessManageMFA(): {
const handleVerifySuccess: HandleVerifyMfaSuccess<
AddFidoChallenge
> = async addFidoChallenge => {
onInitialzied(addFidoChallenge)
onInitialized(addFidoChallenge)
}

verifyMFA({
Expand All @@ -71,7 +71,7 @@ function useSeedlessManageMFA(): {
} else {
const addFidoChallenge = fidoRegisterInitResponse.data()

onInitialzied(addFidoChallenge)
onInitialized(addFidoChallenge)
}
} catch (e) {
Logger.error('fidoRegisterInit error', e)
Expand Down
2 changes: 1 addition & 1 deletion packages/core-mobile/app/seedless/hooks/useVerifyMFA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function useVerifyMFA(sessionManager: SeedlessSessionManager): {
onVerifySuccess: (response: T) => void
}) => {
const challenge = await sessionManager.fidoApproveStart(response.mfaId())
const credential = await PasskeyService.get(challenge.options, true)
const credential = await PasskeyService.getCredential(challenge.options, true)
const mfaRequestInfo = await challenge.answer(credential)
if (!mfaRequestInfo.receipt?.confirmation) {
throw new Error('FIDO authentication failed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const AddRecoveryMethods = (): JSX.Element => {
const withSecurityKey = fidoType === FidoType.YUBI_KEY

fidoRegisterInit(passkeyName, async challenge => {
const credential = await PasskeyService.create(
const credential = await PasskeyService.createCredential(
challenge.options,
withSecurityKey
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class SeedlessSessionManager {
withSecurityKey: boolean
): Promise<void> {
const challenge = await this.fidoApproveStart(mfaId)
const credential = await PasskeyService.get(
const credential = await PasskeyService.getCredential(
challenge.options,
withSecurityKey
)
Expand Down
25 changes: 12 additions & 13 deletions packages/core-mobile/app/services/passkey/PasskeyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
FIDOAuthenticationResult,
FIDOAuthenticationRequest,
FIDORegistrationResult,
FIDORegistrationRequest,
PasskeyServiceInterface
FIDORegistrationRequest
} from 'services/passkey/types'
import {
base64ToBase64Url,
Expand All @@ -20,12 +19,12 @@ import {
} from 'utils/data/base64'
import { FIDO_TIMEOUT, RP_ID, RP_NAME } from './consts'

class PasskeyService implements PasskeyServiceInterface {
class PasskeyService {
get isSupported(): boolean {
return Passkey.isSupported()
}

async create(
async createCredential(
challengeOptions: FIDORegistrationRequest,
withSecurityKey: boolean
): Promise<FIDORegistrationResult> {
Expand All @@ -40,7 +39,7 @@ class PasskeyService implements PasskeyServiceInterface {
return this.convertRegistrationResult(result)
}

async get(
async getCredential(
challengeOptions: FIDOAuthenticationRequest,
withSecurityKey: boolean
): Promise<FIDOAuthenticationResult> {
Expand Down Expand Up @@ -114,18 +113,18 @@ class PasskeyService implements PasskeyServiceInterface {
return {
type: result.type,
id: base64ToBase64Url(result.id),
rawId: base64UrlToBuffer(result.rawId) as Buffer,
rawId: base64UrlToBuffer(result.rawId),
response: {
clientDataJSON: base64UrlToBuffer(
'clientDataJSON' in result.response
? result.response.clientDataJSON
: ''
) as Buffer,
),
attestationObject: base64UrlToBuffer(
'attestationObject' in result.response
? result.response.attestationObject
: ''
) as Buffer
)
}
}
}
Expand All @@ -136,24 +135,24 @@ class PasskeyService implements PasskeyServiceInterface {
return {
id: base64ToBase64Url(result.id),
type: result.type,
rawId: base64UrlToBuffer(result.rawId) as Buffer,
rawId: base64UrlToBuffer(result.rawId),
response: {
clientDataJSON: base64UrlToBuffer(
'clientDataJSON' in result.response
? result.response.clientDataJSON
: ''
) as Buffer,
),
authenticatorData: base64UrlToBuffer(
'authenticatorData' in result.response
? result.response.authenticatorData
: ''
) as Buffer,
),
signature: base64UrlToBuffer(
'signature' in result.response ? result.response.signature : ''
) as Buffer,
),
userHandle: base64UrlToBuffer(
'userHandle' in result.response ? result.response.userHandle : ''
) as Buffer
)
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions packages/core-mobile/app/services/passkey/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,3 @@ export enum FidoType {
PASS_KEY = 'Passkey',
YUBI_KEY = 'Yubikey'
}

export interface PasskeyServiceInterface {
readonly isSupported: boolean
create(
challengeOptions: FIDORegistrationRequest,
withSecurityKey: boolean
): Promise<FIDORegistrationResult>
get(
challengeOptions: FIDOAuthenticationRequest,
withSecurityKey: boolean
): Promise<FIDOAuthenticationResult>
}
2 changes: 1 addition & 1 deletion packages/core-mobile/app/utils/data/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const base64ToBase64Url = (b64: string): string => {
return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/[=]*$/g, '')
}

export const base64UrlToBuffer = (b64url: string): Uint8Array => {
export const base64UrlToBuffer = (b64url: string): Buffer => {
const b64 = b64url.replace(/-/g, '+').replace(/_/g, '/').replace(/[=]*$/g, '')
return Buffer.from(b64, 'base64')
}
Expand Down

0 comments on commit 7ae06e8

Please sign in to comment.