Skip to content

Commit

Permalink
feat(ios): proximity flow
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <berend@animo.id>
  • Loading branch information
berendsliedrecht committed Jan 22, 2025
1 parent caef0ce commit b1fcc65
Show file tree
Hide file tree
Showing 21 changed files with 4,138 additions and 4,307 deletions.
6 changes: 5 additions & 1 deletion apps/easypid/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const config = {
'@animo-id/expo-mdoc-data-transfer',
{
ios: {
buildStatic: [],
buildStatic: ['RNReanimated', 'RNScreens', 'aries-askar', 'anoncreds', 'indy_vdr', 'react-native-executorch'],
},
},
],
Expand All @@ -87,6 +87,10 @@ const config = {
useLegacyPackaging: true,
extraMavenRepos: ['https://s01.oss.sonatype.org/content/repositories/snapshots/'],
},
ios: {
deploymentTarget: '15.1',
useFrameworks: 'dynamic',
},
},
],
[
Expand Down
21 changes: 15 additions & 6 deletions apps/easypid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@expo-google-fonts/raleway": "^0.2.3",
"@hyperledger/anoncreds-react-native": "catalog:",
"@hyperledger/aries-askar-react-native": "catalog:",
"@hyperledger/indy-vdr-react-native": "catalog:",
"@package/agent": "workspace:*",
"@package/app": "workspace:*",
"@package/scanner": "workspace:*",
Expand Down Expand Up @@ -56,24 +55,34 @@
"react": "catalog:",
"react-native": "catalog:",
"react-native-argon2": "^2.0.1",
"react-native-executorch": "^0.1.2",
"react-native-executorch": "0.1.3",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "~2.16.2",
"react-native-gesture-handler": "~2.18.1",
"react-native-get-random-values": "~1.11.0",
"react-native-keychain": "^8.2.0",
"react-native-mmkv": "^2.12.2",
"react-native-qrcode-svg": "^6.3.12",
"react-native-reanimated": "~3.10.1",
"react-native-reanimated": "~3.15.5",
"react-native-reanimated-carousel": "^3.5.1",
"react-native-safe-area-context": "4.10.5",
"react-native-screens": "~3.31.1",
"react-native-screens": "~3.34.1",
"react-native-svg": "15.9.0"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@tamagui/babel-plugin": "1.109.5",
"@tamagui/babel-plugin": "1.122.6",
"babel-plugin-syntax-hermes-parser": "^0.25.1",
"expo-build-properties": "^0.12.5",
"typescript": "catalog:"
},
"expo": {
"install": {
"exclude": [
"react-native@~0.74.0",
"react-native-reanimated@~3.10.0",
"react-native-gesture-handler@~2.16.1",
"react-native-screens@~3.31.1"
]
}
}
}
21 changes: 11 additions & 10 deletions apps/easypid/src/features/proximity/mdocProximity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mdocDataTransfer } from '@animo-id/expo-mdoc-data-transfer'
import {
COSEKey,
DataItem,
Expand All @@ -15,9 +16,6 @@ import type { EasyPIDAppAgent, FormattedSubmission, MdocRecord } from '@package/
import { handleBatchCredential } from '@package/agent/src/batch'
import { type Permission, PermissionsAndroid, Platform } from 'react-native'

const requireMdocDataTransfer = () =>
require('@animo-id/expo-mdoc-data-transfer') as typeof import('@animo-id/expo-mdoc-data-transfer')

type ShareDeviceResponseOptions = {
sessionTranscript: Uint8Array
deviceRequest: Uint8Array
Expand Down Expand Up @@ -53,8 +51,7 @@ export const checkMdocPermissions = async () => {
}

export const getMdocQrCode = async () => {
const mdt = requireMdocDataTransfer().mdocDataTransfer.instance()
mdt.enableNfc()
const mdt = mdocDataTransfer.instance()
const qrData = await mdt.startQrEngagement()
return qrData
}
Expand All @@ -67,10 +64,12 @@ export const getMdocQrCode = async () => {
*
*/
export const waitForDeviceRequest = async () => {
const mdt = requireMdocDataTransfer().mdocDataTransfer.instance()
const mdt = mdocDataTransfer.instance()
const { deviceRequest, sessionTranscript } = await mdt.waitForDeviceRequest()

const encodedSessionTranscript = cborEncode(DataItem.fromData(cborDecode(sessionTranscript)))
// current bug on android required re-encapsulation
const encodedSessionTranscript =
Platform.OS === 'android' ? cborEncode(DataItem.fromData(cborDecode(sessionTranscript))) : sessionTranscript

return { deviceRequest, sessionTranscript: encodedSessionTranscript }
}
Expand Down Expand Up @@ -114,7 +113,7 @@ export const shareDeviceResponse = async (options: ShareDeviceResponseOptions) =
crypto: MdocContext['crypto']
}

const mdt = requireMdocDataTransfer().mdocDataTransfer.instance()
const mdt = mdocDataTransfer.instance()

if (mdoc.documents.length > 1) {
throw new Error('Only one mdoc supported at the moment due to only being able to sign with one device key')
Expand All @@ -134,10 +133,12 @@ export const shareDeviceResponse = async (options: ShareDeviceResponseOptions) =
.authenticateWithSignature(publicDeviceJwk, 'ES256')
.sign(mdocContext)

console.log(Platform.OS, ':', Buffer.from(deviceResponse.encode()).toString('hex'))

await mdt.sendDeviceResponse(deviceResponse.encode())
}

export const shutdownDataTransfer = () => {
const mdt = requireMdocDataTransfer().mdocDataTransfer.instance()
mdt.shutdown()
// const mdt = mdocDataTransfer.instance()
// mdt.shutdown()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
BiometricAuthenticationCancelledError,
type CredentialsForProofRequest,
type FormattedSubmissionEntrySatisfied,
getCredentialsForProofRequest,
getDisclosedAttributeNamesForDisplay,
shareProof,
} from '@package/agent'
import { useToastController } from '@package/ui'
Expand All @@ -12,7 +10,6 @@ import React, { useEffect, useState, useCallback } from 'react'

import { useAppAgent } from '@easypid/agent'
import { InvalidPinError } from '@easypid/crypto/error'
import { useOverAskingAi } from '@easypid/hooks'
import { useDevelopmentMode } from '@easypid/hooks'
import { usePushToWallet } from '@package/app/src/hooks/usePushToWallet'
import { setWalletServiceProviderPin } from '../../crypto/WalletServiceProviderClient'
Expand Down Expand Up @@ -61,38 +58,6 @@ export function FunkeOpenIdPresentationNotificationScreen() {
})
}, [credentialsForRequest, params.data, params.uri, toast.show, agent, pushToWallet, toast, isDevelopmentModeEnabled])

const { checkForOverAsking, isProcessingOverAsking, overAskingResponse, stopOverAsking } = useOverAskingAi()

useEffect(() => {
if (!credentialsForRequest?.formattedSubmission || !credentialsForRequest?.formattedSubmission.areAllSatisfied) {
return
}

if (isProcessingOverAsking || overAskingResponse) {
// Already generating or already has result
return
}

const submission = credentialsForRequest.formattedSubmission
const requestedCards = submission.entries
.filter((entry): entry is FormattedSubmissionEntrySatisfied => entry.isSatisfied)
.flatMap((entry) => entry.credentials)

void checkForOverAsking({
verifier: {
name: credentialsForRequest.verifier.name ?? 'No name provided',
domain: credentialsForRequest.verifier.hostName ?? 'No domain provided',
},
name: submission.name ?? 'No name provided',
purpose: submission.purpose ?? 'No purpose provided',
cards: requestedCards.map((credential) => ({
name: credential.credential.display.name ?? 'Card name',
subtitle: credential.credential.display.description ?? 'Card description',
requestedAttributes: getDisclosedAttributeNamesForDisplay(credential),
})),
})
}, [credentialsForRequest, checkForOverAsking, isProcessingOverAsking, overAskingResponse])

const onProofAccept = useCallback(
async (pin?: string): Promise<PresentationRequestResult> => {
if (!credentialsForRequest)
Expand All @@ -103,7 +68,6 @@ export function FunkeOpenIdPresentationNotificationScreen() {
},
}

stopOverAsking()
setIsSharing(true)

if (shouldUsePin) {
Expand Down Expand Up @@ -188,11 +152,10 @@ export function FunkeOpenIdPresentationNotificationScreen() {
}
}
},
[credentialsForRequest, agent, shouldUsePin, stopOverAsking, isDevelopmentModeEnabled]
[credentialsForRequest, agent, shouldUsePin, isDevelopmentModeEnabled]
)

const onProofDecline = async () => {
stopOverAsking()
if (credentialsForRequest) {
await addSharedActivityForCredentialsForRequest(
agent,
Expand All @@ -218,7 +181,6 @@ export function FunkeOpenIdPresentationNotificationScreen() {
trustedEntities={credentialsForRequest?.verifier.trustedEntities}
lastInteractionDate={lastInteractionDate}
onComplete={() => pushToWallet('replace')}
overAskingResponse={overAskingResponse}
/>
)
}
15 changes: 8 additions & 7 deletions apps/easypid/src/features/wallet/FunkeOfflineQrScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useToastController,
} from '@package/ui'
import { useRouter } from 'expo-router'
import { useHaptics } from 'packages/app/src'
import { isIos, useHaptics } from 'packages/app/src'
import { useEffect, useState } from 'react'
import { Alert, Linking, useWindowDimensions } from 'react-native'
import { useMMKVBoolean } from 'react-native-mmkv'
Expand Down Expand Up @@ -56,6 +56,7 @@ export function FunkeOfflineQrScreen() {
}, [arePermissionsGranted])

const handlePermissions = async () => {
if (isIos()) return { granted: true, shouldShowSettings: false }
const permissions = await requestMdocPermissions()

if (!permissions) {
Expand Down Expand Up @@ -126,12 +127,12 @@ export function FunkeOfflineQrScreen() {
})
)

useEffect(() => {
// Cleanup function that runs when component unmounts
return () => {
shutdownDataTransfer()
}
}, [])
// useEffect(() => {
// // Cleanup function that runs when component unmounts
// return () => {
// shutdownDataTransfer()
// }
// }, [])

const onCancel = () => {
back()
Expand Down
5 changes: 0 additions & 5 deletions apps/easypid/src/features/wallet/FunkeWalletScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export function FunkeWalletScreen() {
const pushToPidSetup = withHaptics(() => push('/pidSetup'))
const pushToAbout = withHaptics(() => push('/menu/about'))
const pushToOffline = () => {
if (Platform.OS === 'ios') {
toast.show('This feature is not supported on your OS yet.', { customData: { preset: 'warning' } })
return
}

withHaptics(() => push('/offline'))()
}

Expand Down
1 change: 0 additions & 1 deletion apps/easypid/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './usePidCredential'
export * from './useWalletReset'
export * from './useOverAskingAi'
export * from './useDevelopmentMode'
21 changes: 15 additions & 6 deletions apps/paradym/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@animo-id/expo-secure-environment": "catalog:",
"@hyperledger/anoncreds-react-native": "catalog:",
"@hyperledger/aries-askar-react-native": "catalog:",
"@hyperledger/indy-vdr-react-native": "catalog:",
"@package/agent": "workspace:*",
"@package/app": "workspace:*",
"@package/ui": "workspace:*",
Expand All @@ -40,18 +39,28 @@
"expo-system-ui": "~3.0.6",
"expo-updates": "~0.25.16",
"react": "catalog:",
"react-native": "catalog:",
"react-native": "^0.75.4",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "~2.16.2",
"react-native-gesture-handler": "~2.18.1",
"react-native-get-random-values": "~1.11.0",
"react-native-reanimated": "~3.10.1",
"react-native-reanimated": "~3.15.5",
"react-native-safe-area-context": "4.10.5",
"react-native-screens": "~3.31.1",
"react-native-screens": "~3.34.1",
"react-native-svg": "15.9.0"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@tamagui/babel-plugin": "1.109.5",
"@tamagui/babel-plugin": "1.122.6",
"typescript": "catalog:"
},
"expo": {
"install": {
"exclude": [
"react-native@~0.74.0",
"react-native-reanimated@~3.10.0",
"react-native-gesture-handler@~2.16.1",
"react-native-screens@~3.31.1"
]
}
}
}
22 changes: 16 additions & 6 deletions apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"expo-system-ui": "~3.0.6",
"react": "catalog:",
"react-device-frameset": "^1.3.4",
"react-native": "catalog:",
"react-native-gesture-handler": "~2.16.2",
"react-native": "^0.75.4",
"react-native-gesture-handler": "~2.18.1",
"react-native-get-random-values": "~1.11.0",
"react-native-reanimated": "~3.10.1",
"react-native-reanimated": "~3.15.5",
"react-native-safe-area-context": "4.10.5",
"react-native-screens": "~3.31.1",
"react-native-screens": "~3.34.1",
"react-native-svg": "15.9.0"
},
"devDependencies": {
Expand All @@ -60,14 +60,24 @@
"@storybook/react": "^7.6.18",
"@storybook/react-native": "^7.6.18",
"@storybook/react-webpack5": "^7.6.18",
"@tamagui/babel-plugin": "1.109.5",
"@tamagui/babel-plugin": "1.122.6",
"@types/react": "~18.2.79",
"babel-loader": "^8.2.3",
"babel-plugin-react-docgen-typescript": "^1.5.1",
"babel-plugin-react-native-web": "^0.19.10",
"cross-env": "^7.0.3",
"storybook": "^7.6.18",
"tamagui-loader": "1.109.5",
"tamagui-loader": "1.122.6",
"typescript": "catalog:"
},
"expo": {
"install": {
"exclude": [
"react-native@~0.74.0",
"react-native-reanimated@~3.10.0",
"react-native-gesture-handler@~2.16.1",
"react-native-screens@~3.31.1"
]
}
}
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "wallets",
"private": true,
"scripts": {
"postinstall": "pnpm deps:check",
"build": "pnpm -r build",
"upgrade:tamagui": "pnpm up '*tamagui*'@latest '@tamagui/*'@latest",
"upgrade:tamagui:canary": "pnpm up '*tamagui*'@canary '@tamagui/*'@canary",
Expand All @@ -17,7 +16,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.8.1",
"check-dependency-version-consistency": "^3.0.3",
"check-dependency-version-consistency": "^3.3.0",
"typescript": "catalog:"
},
"pnpm": {
Expand All @@ -37,17 +36,17 @@
"@credo-ts/node": "catalog:",
"@credo-ts/cheqd": "catalog:",
"@credo-ts/core": "catalog:",
"@credo-ts/indy-vdr": "catalog:",
"@credo-ts/openid4vc": "catalog:",
"@credo-ts/question-answer": "catalog:",
"@credo-ts/react-native": "catalog:",
"@sphereon/pex-models": "catalog:",
"@openid-federation/core": "catalog:"
},
"patchedDependencies": {
"@hyperledger/indy-vdr-react-native@0.2.2": "patches/@hyperledger__indy-vdr-react-native@0.2.2.patch",
"@credo-ts/askar@0.5.13": "patches/@credo-ts__askar@0.5.13.patch",
"@sphereon/kmp-mdl-mdoc": "patches/@sphereon__kmp-mdl-mdoc.patch"
"@sphereon/kmp-mdl-mdoc": "patches/@sphereon__kmp-mdl-mdoc.patch",
"@hyperledger/aries-askar-react-native@0.2.3": "patches/@hyperledger__aries-askar-react-native@0.2.3.patch",
"@hyperledger/anoncreds-react-native@0.2.4": "patches/@hyperledger__anoncreds-react-native@0.2.4.patch"
}
},
"packageManager": "pnpm@9.14.2+sha256.06e65a4965baff6d6097f9c8f75c35f6d420974dbc03d775009056a69edfd271"
Expand Down
Loading

0 comments on commit b1fcc65

Please sign in to comment.