-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: moved functionality into functions
Signed-off-by: Berend Sliedrecht <[email protected]>
- Loading branch information
1 parent
4d3901f
commit a50320e
Showing
21 changed files
with
1,077 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BleProverProps> = ({ 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 ( | ||
<View> | ||
<Text>Ble Prover</Text> | ||
<Spacer /> | ||
<Button title="Ready to share" onPress={shareProof} /> | ||
<Spacer /> | ||
<Text>Proof has{hasSharedProof ? ' ' : ' not '}been shared!</Text> | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { usePeripheral } 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 { bleRequestProof } from './bleRequestProof' | ||
import { closeBleTransports } from './utils/closeBleTransports' | ||
import type { ProofTemplate } from './utils/createBleProofMessage' | ||
|
||
type BleVerifierProps = { | ||
agent: AppAgent | ||
serviceUuid: string | ||
} | ||
|
||
const presentationTemplate: ProofTemplate = { | ||
id: 'test', | ||
name: 'my-proof-request', | ||
requestMessage: { | ||
anoncreds: { | ||
name: 'anon-request', | ||
version: '2.0', | ||
requested_attributes: { nameGroup: { name: 'name' } }, | ||
requested_predicates: { | ||
ageGroup: { name: 'age', p_value: 20, p_type: '>' }, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const BleVerifier: React.FC<BleVerifierProps> = ({ agent, serviceUuid }) => { | ||
const [hasReceivedProof, setHasReceivedProof] = useState(false) | ||
const { peripheral } = usePeripheral() | ||
|
||
const onFailure = () => console.error('[PERIPHEAL]: failure') | ||
const onConnected = () => console.log('[PERIPHERAL]: connected') | ||
const onDisconnected = () => console.log('[PERIPHERAL]: disconnected') | ||
|
||
useEffect(() => { | ||
return () => { | ||
console.log('[PERIPHERAL]: shutting down') | ||
closeBleTransports(agent) | ||
void peripheral.shutdown() | ||
} | ||
}, [peripheral.shutdown, agent]) | ||
|
||
const requestProof = () => | ||
bleRequestProof({ | ||
onConnected, | ||
onDisconnected, | ||
onFailure, | ||
peripheral, | ||
agent, | ||
serviceUuid, | ||
presentationTemplate, | ||
}).then(() => setHasReceivedProof(true)) | ||
|
||
return ( | ||
<View> | ||
<Text>Ble Verifier</Text> | ||
<Spacer /> | ||
<Button title="Request a proof" onPress={requestProof} /> | ||
<Spacer /> | ||
<Text>Proof has{hasReceivedProof ? ' ' : ' not '}been received!</Text> | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import type { FunctionComponent } from 'react' | ||
import { Text, View } from 'react-native' | ||
import { type FunctionComponent, type ReactElement, useState } from 'react' | ||
import { Button, Text } from 'react-native' | ||
import { BleVerifier } from './BleVerifier' | ||
import type { AppAgent } from './agent' | ||
|
||
type VerifierProps = { | ||
agent: AppAgent | ||
serviceUuid: string | ||
} | ||
|
||
export const Verifier: FunctionComponent<VerifierProps> = ({ agent }) => { | ||
return ( | ||
<View> | ||
<Text>Verifier</Text> | ||
</View> | ||
) | ||
export const Verifier: FunctionComponent<VerifierProps> = ({ agent, serviceUuid }) => { | ||
const [bleFlowInProgress, setBleFlowInProgress] = useState(false) | ||
|
||
let component: ReactElement | ||
|
||
if (bleFlowInProgress) { | ||
component = ( | ||
<> | ||
<Button title="quit ble flow" onPress={() => setBleFlowInProgress(false)} /> | ||
<BleVerifier agent={agent} serviceUuid={serviceUuid} /> | ||
</> | ||
) | ||
} | ||
|
||
if (!bleFlowInProgress) { | ||
component = ( | ||
<> | ||
<Text>Verifier</Text> | ||
<Button title="request proof" onPress={() => setBleFlowInProgress(true)} /> | ||
</> | ||
) | ||
} | ||
|
||
return component | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.