Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/easypid/.env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
EXPO_PUBLIC_WALLET_SERVICE_PROVIDER_URL=
EXPO_PUBLIC_APP_TYPE=FUNKE_WALLET
EXPO_PUBLIC_APP_TYPE=PARADYM_WALLET
9 changes: 5 additions & 4 deletions apps/easypid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@expo-google-fonts/raleway": "catalog:",
"@gorhom/bottom-sheet": "catalog:",
"@hyperledger/anoncreds-react-native": "catalog:",
"@lingui/babel-plugin-lingui-macro": "^5.3.3",
"@lingui/babel-plugin-lingui-macro": "^5.5.0",
"@openwallet-foundation/askar-react-native": "catalog:",
"@package/agent": "workspace:*",
"@package/app": "workspace:*",
Expand All @@ -36,12 +36,13 @@
"@react-native-community/blur": "catalog:",
"@react-native-community/netinfo": "catalog:",
"@react-native-masked-view/masked-view": "catalog:",
"@react-native-picker/picker": "^2.11.1",
"@react-native-picker/picker": "^2.11.2",
"@react-navigation/native": "catalog:",
"babel-plugin-module-resolver": "catalog:",
"buffer": "catalog:",
"burnt": "catalog:",
"expo": "catalog:",
"expo-crypto": "catalog:",
"expo-application": "catalog:",
"expo-asset": "catalog:",
"expo-blur": "catalog:",
Expand Down Expand Up @@ -82,8 +83,8 @@
},
"devDependencies": {
"@babel/core": "catalog:",
"@lingui/cli": "^5.3.3",
"@lingui/format-json": "^5.3.3",
"@lingui/cli": "^5.5.0",
"@lingui/format-json": "^5.5.0",
"@tamagui/babel-plugin": "catalog:",
"babel-plugin-syntax-hermes-parser": "catalog:",
"expo-build-properties": "catalog:",
Expand Down
10 changes: 8 additions & 2 deletions apps/easypid/src/agent/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { setFallbackSecureEnvironment, shouldUseFallbackSecureEnvironment } from '@animo-id/expo-secure-environment'
import { AskarStoreInvalidKeyError } from '@credo-ts/askar'
import { trustedX509Certificates } from '@easypid/constants'
import { WalletServiceProviderClient } from '@easypid/crypto/WalletServiceProviderClient'
import { isFunkeWallet } from '@easypid/hooks/useFeatureFlag'
import { initializeEasyPIDAgent, initializeParadymAgent, isEasyPIDAgent } from '@package/agent'
import { InvalidPinError } from '../crypto/error'
import { getShouldUseCloudHsm } from '../features/onboarding/useShouldUseCloudHsm'

export function getWalletId(walletKeyVersion: number) {
Expand All @@ -19,15 +21,19 @@ export async function initializeAppAgent({
keyDerivation: 'raw',
walletId: getWalletId(walletKeyVersion),
walletKey,
walletLabel: 'EasyPID Wallet',
trustedX509Certificates,
}).catch((error) => {
if (error instanceof AskarStoreInvalidKeyError) throw new InvalidPinError()
throw error
})
: await initializeParadymAgent({
keyDerivation: 'raw',
walletId: getWalletId(walletKeyVersion),
walletKey,
walletLabel: 'Paradym Wallet',
trustedX509Certificates,
}).catch((error) => {
if (error instanceof AskarStoreInvalidKeyError) throw new InvalidPinError()
throw error
})

/**
Expand Down
6 changes: 4 additions & 2 deletions apps/easypid/src/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { Redirect, Stack, useGlobalSearchParams, usePathname, useRouter } from '
import { TypedArrayEncoder } from '@credo-ts/core'
import { useSecureUnlock } from '@easypid/agent'
import { mediatorDid } from '@easypid/constants'
import { activityStorage } from '@easypid/features/activity/activityRecord'
import { useHasFinishedOnboarding } from '@easypid/features/onboarding'
import { useFeatureFlag } from '@easypid/hooks/useFeatureFlag'
import { useResetWalletDevMenu } from '@easypid/utils/resetWallet'
import {
AgentProvider,
type InvitationType,
WalletJsonStoreProvider,
activityStorage,
deferredCredentialStorage,
registerCredentialsForDcApi,
useMediatorSetup,
} from '@package/agent'
Expand All @@ -21,7 +22,7 @@ import { useEffect, useState } from 'react'
import { Pressable } from 'react-native-gesture-handler'
import { useTheme } from 'tamagui'

const jsonRecordIds = [activityStorage.recordId]
const jsonRecordIds = [activityStorage.recordId, deferredCredentialStorage.recordId]

const isDIDCommEnabled = useFeatureFlag('DIDCOMM')

Expand Down Expand Up @@ -169,6 +170,7 @@ export default function AppLayout() {
}}
/>

<Stack.Screen name="notifications/deferredCredential" options={headerNormalOptions} />
<Stack.Screen name="credentials/index" options={headerNormalOptions} />
<Stack.Screen name="credentials/[id]/index" options={headerNormalOptions} />
<Stack.Screen name="credentials/[id]/attributes" options={headerNormalOptions} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DeferredCredentialNotificationScreen } from '@easypid/features/receive/DeferredCredentialNotificationScreen'

export default function Screen() {
return <DeferredCredentialNotificationScreen />
}
5 changes: 3 additions & 2 deletions apps/easypid/src/app/authenticate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Redirect, useLocalSearchParams } from 'expo-router'

import { TypedArrayEncoder, WalletInvalidKeyError } from '@credo-ts/core'
import { TypedArrayEncoder } from '@credo-ts/core'
import { initializeAppAgent, useSecureUnlock } from '@easypid/agent'
import { useBiometricsType } from '@easypid/hooks/useBiometricsType'
import { useLingui } from '@lingui/react/macro'
Expand All @@ -10,6 +10,7 @@ import { commonMessages } from '@package/translations'
import { FlexPage, Heading, HeroIcons, IconContainer, YStack, useDeviceMedia, useToastController } from '@package/ui'
import * as SplashScreen from 'expo-splash-screen'
import { useEffect, useRef, useState } from 'react'
import { InvalidPinError } from '../crypto/error'
import { useResetWalletDevMenu } from '../utils/resetWallet'

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ export default function Authenticate() {
})
.then((agent) => secureUnlock.setWalletKeyValid({ agent }, { enableBiometrics: true }))
.catch((error) => {
if (error instanceof WalletInvalidKeyError) {
if (error instanceof InvalidPinError) {
secureUnlock.setWalletKeyInvalid()
pinInputRef.current?.clear()
pinInputRef.current?.shake()
Expand Down
3 changes: 0 additions & 3 deletions apps/easypid/src/config/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ export const APP_CONFIGS = {
AI_ANALYSIS: true,
DIDCOMM: false,
CLOUD_HSM: true,
INBOX: false,
},
PARADYM_WALLET: {
EID_CARD: false,
AI_ANALYSIS: false,
DIDCOMM: true,
CLOUD_HSM: false,
INBOX: true,
},
} satisfies Record<string, Features>

Expand All @@ -20,7 +18,6 @@ export interface Features {
AI_ANALYSIS: boolean
DIDCOMM: boolean
CLOUD_HSM: boolean
INBOX: boolean
}

export type FeatureKey = keyof Features
34 changes: 21 additions & 13 deletions apps/easypid/src/crypto/WalletServiceProviderClient.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type { SecureEnvironment } from '@animo-id/expo-secure-environment'
import { AskarModule } from '@credo-ts/askar'
import { AskarStoreInvalidKeyError } from '@credo-ts/askar'
import {
Agent,
CredoWebCrypto,
type JwsProtectedHeaderOptions,
JwsService,
JwtPayload,
KeyDerivationMethod,
TypedArrayEncoder,
WalletInvalidKeyError,
getJwkFromKey,
} from '@credo-ts/core'
import { agentDependencies } from '@credo-ts/react-native'
import { askar } from '@openwallet-foundation/askar-react-native'
Expand All @@ -27,20 +25,24 @@ export const setWalletServiceProviderPin = async (pin: Array<number>, validatePi
const walletKey = await secureWalletKey.getWalletKeyUsingPin(pinString, walletKeyVersion)
const walletId = `easypid-wallet-${walletKeyVersion}`
const agent = new Agent({
config: {
label: 'pin_test_agent',
walletConfig: { id: walletId, key: walletKey, keyDerivationMethod: KeyDerivationMethod.Raw },
},
config: {},
modules: {
askar: new AskarModule({ askar }),
askar: new AskarModule({
askar,
store: {
id: walletId,
key: walletKey,
keyDerivationMethod: 'raw',
},
}),
},
dependencies: agentDependencies,
})

try {
await agent.initialize()
} catch (e) {
if (e instanceof WalletInvalidKeyError) {
if (e instanceof AskarStoreInvalidKeyError) {
throw new InvalidPinError()
}
throw e
Expand Down Expand Up @@ -73,19 +75,19 @@ export class WalletServiceProviderClient implements SecureEnvironment {
)
const jwsService = this.agent.context.dependencyManager.resolve(JwsService)
const salt = await this.getOrCreateSalt()
const key = await deriveKeypairFromPin(this.agent.context, pin, salt)
const jwk = await deriveKeypairFromPin(this.agent.context, pin, salt)

const payload = new JwtPayload({
additionalClaims: claims,
})

const protectedHeaderOptions: JwsProtectedHeaderOptions = {
alg: 'ES256',
jwk: getJwkFromKey(key),
jwk: jwk.toJson({ includeKid: false }),
}

const compactJws = await jwsService.createJwsCompact(this.agent.context, {
key,
keyId: jwk.keyId,
payload,
protectedHeaderOptions,
})
Expand All @@ -101,7 +103,7 @@ export class WalletServiceProviderClient implements SecureEnvironment {
})

const parsedData = await response.json()
return parsedData
return parsedData as T
}

public async register() {
Expand Down Expand Up @@ -147,6 +149,12 @@ export class WalletServiceProviderClient implements SecureEnvironment {
return new Uint8Array(publicKey)
}

public async deleteKey(keyId: string): Promise<void> {
this.agent.config.logger.warn('Deleting key from wallet service provider is not supported yet.', {
keyId,
})
}

public async createSalt() {
const maybeSalt = await this.getSalt()
if (maybeSalt) return maybeSalt
Expand Down
Loading