From 39b0f85d383cd96aa82010d8d89f761b332a9db0 Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht Date: Thu, 26 Sep 2024 16:32:29 +0200 Subject: [PATCH 1/6] feat: added setup for credo agent Signed-off-by: Berend Sliedrecht --- example/index.js | 3 + example/metro.config.js | 2 + example/package.json | 10 +- example/src/App.tsx | 14 +- example/src/RequestPermissions.ts | 11 + example/src/RequestPermissions.tsx | 11 - example/src/credo/CredoScreen.tsx | 42 + example/src/credo/Issuer.tsx | 15 + example/src/credo/Screen.tsx | 42 + example/src/credo/Verifier.tsx | 15 + example/src/credo/agent.ts | 23 + example/src/regular/Screen.tsx | 40 +- pnpm-lock.yaml | 1697 +++++++++++++++++++++++++++- 13 files changed, 1859 insertions(+), 66 deletions(-) create mode 100644 example/src/RequestPermissions.ts delete mode 100644 example/src/RequestPermissions.tsx create mode 100644 example/src/credo/CredoScreen.tsx create mode 100644 example/src/credo/Issuer.tsx create mode 100644 example/src/credo/Screen.tsx create mode 100644 example/src/credo/Verifier.tsx create mode 100644 example/src/credo/agent.ts diff --git a/example/index.js b/example/index.js index 90813e8..68d3fc7 100644 --- a/example/index.js +++ b/example/index.js @@ -1,3 +1,6 @@ +import 'react-native-get-random-values' +import 'fast-text-encoding' + import { registerRootComponent } from 'expo' import { App } from './src/App' diff --git a/example/metro.config.js b/example/metro.config.js index 354f43a..19acfd9 100644 --- a/example/metro.config.js +++ b/example/metro.config.js @@ -12,4 +12,6 @@ config.resolver.nodeModulesPaths = [ path.resolve(monorepoRoot, 'node_modules'), ] +config.resolver.sourceExts = ['js', 'json', 'ts', 'tsx', 'cjs'] + module.exports = config diff --git a/example/package.json b/example/package.json index ecd0ce0..1281831 100644 --- a/example/package.json +++ b/example/package.json @@ -10,13 +10,21 @@ }, "dependencies": { "@animo-id/react-native-ble-didcomm": "workspace:*", + "@credo-ts/askar": "^0.5.11", + "@credo-ts/core": "^0.5.11", + "@credo-ts/react-native": "^0.5.11", + "@hyperledger/aries-askar-react-native": "^0.2.3", "expo": "*", "expo-status-bar": "~1.12.1", + "fast-text-encoding": "^1.0.6", "react": "*", - "react-native": "*" + "react-native": "*", + "react-native-fs": "^2.20.0", + "react-native-get-random-values": "^1.11.0" }, "devDependencies": { "@babel/core": "^7.20.0", + "@types/fast-text-encoding": "^1.0.3", "babel-plugin-module-resolver": "^5.0.2", "typescript": "*" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index b7e5e9b..4f6137d 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,7 +1,9 @@ -import React, { type ReactElement, useState } from 'react' -import { Button, StyleSheet, View } from 'react-native' +import React, { type ReactElement, useState, useEffect } from 'react' +import { Button, Platform, StyleSheet, View } from 'react-native' +import { requestPermissions } from './RequestPermissions' import { Spacer } from './Spacer' +import { CredoScreen } from './credo/CredoScreen' import { RegularScreen } from './regular/Screen' export const App = () => { @@ -9,6 +11,12 @@ export const App = () => { let component: ReactElement + useEffect(() => { + if (Platform.OS === 'android') { + void requestPermissions() + } + }, []) + if (!flow) { component = ( <> @@ -24,7 +32,7 @@ export const App = () => { } if (flow === 'credo') { - component = + component = } return ( diff --git a/example/src/RequestPermissions.ts b/example/src/RequestPermissions.ts new file mode 100644 index 0000000..e474390 --- /dev/null +++ b/example/src/RequestPermissions.ts @@ -0,0 +1,11 @@ +import { type Permission, PermissionsAndroid } from 'react-native' + +const PERMISSIONS = [ + 'android.permission.ACCESS_FINE_LOCATION', + 'android.permission.BLUETOOTH_CONNECT', + 'android.permission.BLUETOOTH_SCAN', + 'android.permission.BLUETOOTH_ADVERTISE', + 'android.permission.ACCESS_COARSE_LOCATION', +] as const as Permission[] + +export const requestPermissions = async () => PermissionsAndroid.requestMultiple(PERMISSIONS) diff --git a/example/src/RequestPermissions.tsx b/example/src/RequestPermissions.tsx deleted file mode 100644 index 50852c6..0000000 --- a/example/src/RequestPermissions.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { PermissionsAndroid } from 'react-native' - -export const requestPermissions = async () => { - await PermissionsAndroid.requestMultiple([ - 'android.permission.ACCESS_FINE_LOCATION', - 'android.permission.BLUETOOTH_CONNECT', - 'android.permission.BLUETOOTH_SCAN', - 'android.permission.BLUETOOTH_ADVERTISE', - 'android.permission.ACCESS_COARSE_LOCATION', - ]) -} diff --git a/example/src/credo/CredoScreen.tsx b/example/src/credo/CredoScreen.tsx new file mode 100644 index 0000000..07222ae --- /dev/null +++ b/example/src/credo/CredoScreen.tsx @@ -0,0 +1,42 @@ +import * as React from 'react' +import { type ReactElement, useEffect, useState } from 'react' +import { Button, Text } from 'react-native' +import { Spacer } from '../Spacer' +import { Issuer } from './Issuer' +import { Verifier } from './Verifier' +import { type AppAgent, setupAgent } from './agent' + +export const CredoScreen = () => { + const [role, setRole] = useState<'issuer' | 'verifier'>() + const [agent, setAgent] = useState() + + useEffect(() => { + setupAgent().then(setAgent) + }, []) + + let component: ReactElement + + if (!role) { + component = ( + <> +