openwallet-foundation / bifold-wallet

Aries Mobile Agent React Native - Part of the Aries Bifold effort to provide SSI capabilities in a production ready app.
Apache License 2.0
151 stars 148 forks source link

A way to detect Biometry type for Android/iOS devices #1159

Open FarjadGov14 opened 5 months ago

FarjadGov14 commented 5 months ago

Description of feature / user story

A great feature to add would be to detect biometry type for Android/iOS devices, by using this below library react-native-biometrics

If we can create a service or a utility in bifold to detect Biometry type we can guide the users accordingly, a utility function that can be used in a context provider and used by wallets to enhance User experience.

A Sample code that we could use below:

import Biometry, { BiometryType } from 'react-native-biometrics'

export interface IsSensorAvailableResult {
  available: boolean
  biometryType?: BiometryType
  error?: string
}

export interface SimplePromptResult {
  success: boolean
  error?: string
}

export function serviceGetBiometryDescription(biometryType: BiometryType | undefined): string {
  switch (biometryType) {
    case Biometry.TouchID:
      return Biometry.TouchID
    case Biometry.FaceID:
      return Biometry.FaceID
    case 'Biometrics':
      return 'Biometrics'
    default:
      throw new Error('We do not support this type of biometry')
  }
}

export function serviceAuthenticateWithBiometrics(promptMessage: string): Promise<SimplePromptResult> {
  return Biometry.simplePrompt({
    promptMessage: promptMessage,
  })
}

export function serviceGetEnrolledBiometry(): Promise<IsSensorAvailableResult> {
  return Biometry.isSensorAvailable()
}

export async function biometryType(): Promise<BiometryType | undefined> {
  let biometryType: BiometryType | undefined
  await Biometry.isSensorAvailable().then((resultObject) => {
    biometryType = resultObject.biometryType
  })
  return biometryType
}

This can be used across different wallets as a utility service.

Acceptance Criteria

A Hook for biometryType that can detect the device type and it can be used by other wallets as a custom hook.

Wireframes or relevant image assets / links

timbl-ont commented 1 day ago

@jleach This can be closed. In a previous discussion it was pointed out that react-native-keychain which is already in the wallet can be used to get the Biometry type.

A utility function could be useful, but currently there no longer any plans to submit a PR for this issue.