-
Notifications
You must be signed in to change notification settings - Fork 5
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
CP-9607: update android passkey implementation #2192
Open
ruijialin-avalabs
wants to merge
5
commits into
main
Choose a base branch
from
cp-9607
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6204f58
update android passkey implementation
ruijialin-avalabs 775454b
remove passkey patch
ruijialin-avalabs 56e6916
revert .xcode.env
ruijialin-avalabs 9bc298b
Merge branch 'main' into cp-9607
ruijialin-avalabs 625c331
remove console
ruijialin-avalabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
packages/core-mobile/app/new/features/onboarding/components/FidoNameInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from 'react' | ||
import { | ||
Text, | ||
TextInput, | ||
useTheme, | ||
View, | ||
Icons, | ||
Button, | ||
TouchableOpacity | ||
} from '@avalabs/k2-alpine' | ||
import BlurredBarsContentLayout from 'common/components/BlurredBarsContentLayout' | ||
import { FIDONameInputProps } from 'new/routes/onboarding/seedless/fidoNameInput' | ||
|
||
const FidoNameInput = ({ | ||
title, | ||
description, | ||
textInputPlaceholder, | ||
name, | ||
setName, | ||
handleSave | ||
}: Omit<FIDONameInputProps, 'fidoType'> & { | ||
name: string | ||
setName: (value: string) => void | ||
handleSave: () => void | ||
}): JSX.Element => { | ||
const { | ||
theme: { colors } | ||
} = useTheme() | ||
|
||
return ( | ||
<BlurredBarsContentLayout> | ||
<View | ||
style={{ | ||
flex: 1, | ||
marginHorizontal: 16, | ||
marginTop: 25, | ||
justifyContent: 'space-between' | ||
}}> | ||
<View> | ||
<Text variant="heading2">{title}</Text> | ||
<Text variant="body1" sx={{ marginTop: 14 }}> | ||
{description} | ||
</Text> | ||
<View | ||
sx={{ | ||
marginTop: 27, | ||
paddingHorizontal: 13, | ||
backgroundColor: colors.$surfaceSecondary, | ||
borderRadius: 12, | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
height: 44 | ||
}}> | ||
<TextInput | ||
sx={{ | ||
flex: 1, | ||
fontFamily: 'Inter-Regular', | ||
marginRight: 13, | ||
height: 44, | ||
fontSize: 16, | ||
color: colors.$textPrimary | ||
}} | ||
value={name} | ||
onChangeText={setName} | ||
placeholder={textInputPlaceholder} | ||
/> | ||
<TouchableOpacity onPress={() => setName('')}> | ||
<Icons.Action.Clear | ||
width={16} | ||
height={16} | ||
color={colors.$textSecondary} | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
<View sx={{ marginVertical: 36 }}> | ||
<Button | ||
type="primary" | ||
size="large" | ||
disabled={name === ''} | ||
onPress={handleSave}> | ||
Next | ||
</Button> | ||
</View> | ||
</View> | ||
</BlurredBarsContentLayout> | ||
) | ||
} | ||
|
||
export default FidoNameInput |
71 changes: 71 additions & 0 deletions
71
packages/core-mobile/app/new/features/onboarding/hooks/useRegisterAndAuthenticateFido.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { FidoType } from 'services/passkey/types' | ||
import PasskeyService from 'services/passkey/PasskeyService' | ||
import AnalyticsService from 'services/analytics/AnalyticsService' | ||
import SeedlessService from 'seedless/services/SeedlessService' | ||
import Logger from 'utils/Logger' | ||
import { showSnackbar } from 'common/utils/toast' | ||
import { showLogoModal, hideLogoModal } from 'common/components/LogoModal' | ||
import { useRecoveryMethodContext } from '../contexts/RecoveryMethodProvider' | ||
import useSeedlessManageMFA from './useSeedlessManageMFA' | ||
|
||
export const useRegisterAndAuthenticateFido = (): { | ||
registerAndAuthenticateFido: ({ | ||
name, | ||
fidoType, | ||
onAccountVerified | ||
}: { | ||
name?: string | ||
fidoType: FidoType | ||
onAccountVerified: () => void | ||
}) => Promise<void> | ||
} => { | ||
const { oidcAuth } = useRecoveryMethodContext() | ||
const { fidoRegisterInit } = useSeedlessManageMFA() | ||
|
||
const registerAndAuthenticateFido = async ({ | ||
name, | ||
fidoType, | ||
onAccountVerified | ||
}: { | ||
name?: string | ||
fidoType: FidoType | ||
onAccountVerified: () => void | ||
}): Promise<void> => { | ||
const passkeyName = name && name.length > 0 ? name : fidoType.toString() | ||
|
||
showLogoModal() | ||
|
||
try { | ||
const withSecurityKey = fidoType === FidoType.YUBI_KEY | ||
|
||
fidoRegisterInit(passkeyName, async challenge => { | ||
const credential = await PasskeyService.create( | ||
challenge.options, | ||
withSecurityKey | ||
) | ||
|
||
await challenge.answer(credential) | ||
|
||
AnalyticsService.capture('SeedlessMfaAdded') | ||
|
||
if (oidcAuth) { | ||
await SeedlessService.sessionManager.approveFido( | ||
oidcAuth.oidcToken, | ||
oidcAuth.mfaId, | ||
withSecurityKey | ||
) | ||
|
||
AnalyticsService.capture('SeedlessMfaVerified', { type: fidoType }) | ||
} | ||
onAccountVerified() | ||
}) | ||
} catch (e) { | ||
console.log('registerAndAuthenticateFido', e) | ||
Logger.error(`${fidoType} registration failed`, e) | ||
showSnackbar(`Unable to register ${fidoType}`) | ||
} finally { | ||
hideLogoModal() | ||
} | ||
} | ||
return { registerAndAuthenticateFido } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/core-mobile/app/new/routes/onboarding/seedless/fidoNameInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { useCallback, useState } from 'react' | ||
import { useLocalSearchParams, useRouter } from 'expo-router' | ||
import { FidoType } from 'services/passkey/types' | ||
import { useRegisterAndAuthenticateFido } from 'features/onboarding/hooks/useRegisterAndAuthenticateFido' | ||
import { hideLogoModal, showLogoModal } from 'common/components/LogoModal' | ||
import SeedlessService from 'seedless/services/SeedlessService' | ||
import Component from 'features/onboarding/components/FidoNameInput' | ||
|
||
export type FIDONameInputProps = { | ||
fidoType: FidoType | ||
title: string | ||
description: string | ||
textInputPlaceholder: string | ||
} | ||
|
||
const FidoNameInput = (): JSX.Element => { | ||
const router = useRouter() | ||
const { registerAndAuthenticateFido } = useRegisterAndAuthenticateFido() | ||
const { title, description, textInputPlaceholder, fidoType } = | ||
useLocalSearchParams<FIDONameInputProps>() | ||
|
||
const [name, setName] = useState<string>('') | ||
|
||
const onAccountVerified = useCallback(async (): Promise<void> => { | ||
showLogoModal() | ||
const walletName = await SeedlessService.getAccountName() | ||
hideLogoModal() | ||
|
||
if (walletName) { | ||
router.navigate('./createPin') | ||
return | ||
} | ||
router.navigate('./nameYourWallet') | ||
}, [router]) | ||
|
||
const handleSave = (): void => { | ||
if (router.canGoBack()) { | ||
router.back() | ||
} | ||
fidoType && | ||
registerAndAuthenticateFido({ | ||
name, | ||
fidoType, | ||
onAccountVerified | ||
}) | ||
} | ||
|
||
return ( | ||
<Component | ||
title={title ?? ''} | ||
description={description ?? ''} | ||
textInputPlaceholder={textInputPlaceholder ?? ''} | ||
name={name} | ||
setName={setName} | ||
handleSave={handleSave} | ||
/> | ||
) | ||
} | ||
|
||
export default FidoNameInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,11 +145,7 @@ async function fidoRefreshFlow( | |
sessionManager: SeedlessSessionManager | ||
): Promise<Result<void, RefreshSeedlessTokenFlowErrors>> { | ||
try { | ||
await sessionManager.approveFido( | ||
oidcToken, | ||
mfaId, | ||
false //FIXME: this parameter is not needed, should refactor approveFido to remove it, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
) | ||
await sessionManager.approveFido(oidcToken, mfaId, true) | ||
return { | ||
success: true, | ||
value: undefined | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
true
instead, if we don't know it is yubikey/passkey, we want to prompt both options to them.