From a50320e287513cca8d32fdfe900b85d96db2bd95 Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht Date: Mon, 30 Sep 2024 15:42:42 +0200 Subject: [PATCH] chore: moved functionality into functions Signed-off-by: Berend Sliedrecht --- example/package.json | 2 + example/scripts/issueCredential.ts | 2 +- example/src/credo/BleProver.tsx | 50 +++++ example/src/credo/BleVerifier.tsx | 67 ++++++ example/src/credo/CredoScreen.tsx | 28 ++- example/src/credo/Prover.tsx | 42 ++-- example/src/credo/Verifier.tsx | 36 +++- example/src/credo/agent.ts | 19 +- example/src/credo/bleRequestProof.ts | 159 ++++++++++++++ example/src/credo/bleShareProof.ts | 197 ++++++++++++++++++ .../src/credo/hooks/useBleRequestProof.tsx | 109 ++++++++++ example/src/credo/hooks/useBleShareProof.tsx | 105 ++++++++++ .../utils/autoRespondToBleProofRequest.ts | 37 ++++ example/src/credo/utils/closeBleTransports.ts | 16 ++ .../src/credo/utils/createBleProofMessage.ts | 53 +++++ example/src/credo/utils/date.ts | 6 + example/src/credo/utils/extractRequested.ts | 53 +++++ .../credo/utils/returnWhenProofIsShared.tsx | 20 ++ library/src/plugin.ts | 54 +++++ library/src/withAndroidPermissions.ts | 31 --- pnpm-lock.yaml | 54 +++++ 21 files changed, 1077 insertions(+), 63 deletions(-) create mode 100644 example/src/credo/BleProver.tsx create mode 100644 example/src/credo/BleVerifier.tsx create mode 100644 example/src/credo/bleRequestProof.ts create mode 100644 example/src/credo/bleShareProof.ts create mode 100644 example/src/credo/hooks/useBleRequestProof.tsx create mode 100644 example/src/credo/hooks/useBleShareProof.tsx create mode 100644 example/src/credo/utils/autoRespondToBleProofRequest.ts create mode 100644 example/src/credo/utils/closeBleTransports.ts create mode 100644 example/src/credo/utils/createBleProofMessage.ts create mode 100644 example/src/credo/utils/date.ts create mode 100644 example/src/credo/utils/extractRequested.ts create mode 100644 example/src/credo/utils/returnWhenProofIsShared.tsx create mode 100644 library/src/plugin.ts delete mode 100644 library/src/withAndroidPermissions.ts diff --git a/example/package.json b/example/package.json index 00d703c..77a7fec 100644 --- a/example/package.json +++ b/example/package.json @@ -16,7 +16,9 @@ "@credo-ts/core": "^0.5.11", "@credo-ts/indy-vdr": "^0.5.11", "@credo-ts/node": "^0.5.11", + "@credo-ts/react-hooks": "^0.6.1", "@credo-ts/react-native": "^0.5.11", + "@credo-ts/transport-ble": "^0.3.0", "@hyperledger/anoncreds-nodejs": "^0.2.4", "@hyperledger/anoncreds-react-native": "^0.2.4", "@hyperledger/aries-askar-nodejs": "^0.2.3", diff --git a/example/scripts/issueCredential.ts b/example/scripts/issueCredential.ts index e496e14..493a4c8 100644 --- a/example/scripts/issueCredential.ts +++ b/example/scripts/issueCredential.ts @@ -70,7 +70,7 @@ void (async () => { label: 'nodejs-register-agent', walletConfig: { id: 'nodejs-register-agent', key: 'nodejs-register-key' }, logger: new ConsoleLogger(LogLevel.off), - endpoints: ['https://36ba-161-51-75-238.ngrok-free.app'], + endpoints: ['https://65a0-84-241-194-48.ngrok-free.app'], }, modules, dependencies: agentDependencies, diff --git a/example/src/credo/BleProver.tsx b/example/src/credo/BleProver.tsx new file mode 100644 index 0000000..9aa625e --- /dev/null +++ b/example/src/credo/BleProver.tsx @@ -0,0 +1,50 @@ +import { useCentral } from '@animo-id/react-native-ble-didcomm' +import type React from 'react' +import { useEffect, useState } from 'react' +import { Button, Text, View } from 'react-native' +import { Spacer } from '../Spacer' +import type { AppAgent } from './agent' +import { bleShareProof } from './bleShareProof' +import { closeBleTransports } from './utils/closeBleTransports' + +type BleProverProps = { + agent: AppAgent + serviceUuid: string +} + +export const BleProver: React.FC = ({ agent, serviceUuid }) => { + const [hasSharedProof, setHasSharedProof] = useState(false) + const { central } = useCentral() + + const onFailure = () => console.error('[CENTRAL]: failure') + const onConnected = () => console.log('[CENTRAL]: connected') + const onDisconnected = () => console.log('[CENTRAL]: disconnected') + + useEffect(() => { + return () => { + console.log('[CENTRAL]: shutting down') + closeBleTransports(agent) + void central.shutdown() + } + }, [central.shutdown, agent]) + + const shareProof = () => + bleShareProof({ + onFailure, + serviceUuid, + central, + agent, + onConnected, + onDisconnected, + }).then(() => setHasSharedProof(true)) + + return ( + + Ble Prover + +