Skip to content

Commit

Permalink
feat: shutdown and enable NFC
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
Berend Sliedrecht committed Nov 26, 2024
1 parent 267d71e commit 3938607
Show file tree
Hide file tree
Showing 16 changed files with 21,583 additions and 31,574 deletions.
96 changes: 52 additions & 44 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,65 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

- uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies
run: npm install
run: pnpm install

- name: Style
run: npm run style:check
run: pnpm style:check

- name: Build
run: npm run build
run: pnpm build

- name: Check types
run: npm run types:check
run: pnpm types:check

continuous-deployment:
if: github.event_name == 'workflow_dispatch'

name: 'Continuous Deployment'
runs-on: ubuntu-latest
needs: ['continuous-integration']

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
run: npm install

- name: Build
run: npm run build

- name: Set git configuration
run: |
git config user.name "Animo Solutions"
git config user.email "[email protected]"
- name: Publish
id: publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
if [ ${{ inputs.release-type }} == 'alpha' ]; then
npm run release -- --preRelease=alpha
else
npm run release -- -i=${{ inputs.release-type }}
fi
if: github.event_name == 'workflow_dispatch'

name: 'Continuous Deployment'
runs-on: ubuntu-latest
needs: ['continuous-integration']

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: '20'

- uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Set git configuration
run: |
git config user.name "Animo Solutions"
git config user.email "[email protected]"
- name: Publish
id: publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
if [ ${{ inputs.release-type }} == 'alpha' ]; then
pnpm release -- --preRelease=alpha
else
pnpm release -- -i=${{ inputs.release-type }}
fi
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class MdocDataTransfer(
sendEvent(
MdocDataTransferEvent.ON_REQUEST_RECEIVED,
mapOf(
("deviceRequest" to request.deviceRequestBytes.asList()),
("sessionTranscript" to request.sessionTranscriptBytes.asList())
("deviceRequest" to request.deviceRequestBytes.asList()),
("sessionTranscript" to request.sessionTranscriptBytes.asList())
)
)
}
Expand Down Expand Up @@ -85,7 +85,16 @@ class MdocDataTransfer(
MdocDataTransferManager.transferManager.value.sendResponse(deviceResponse)
}

fun shutdown() {
fun enableNfc() {
NfcEngagementService.enable(currentActivity as ComponentActivity)
}

fun disableNfc() {
NfcEngagementService.disable(currentActivity as ComponentActivity)
}

fun shutdown() {
disableNfc()
MdocDataTransferManager.transferManager.value.stopPresentation(true, true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package id.animo.mdocdatatransfer

import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import eu.europa.ec.eudi.iso18013.transfer.DocumentsResolver
import eu.europa.ec.eudi.iso18013.transfer.TransferManager
import eu.europa.ec.eudi.iso18013.transfer.response.ResponseGenerator
Expand Down Expand Up @@ -30,6 +29,7 @@ object MdocDataTransferManager {
.apply {
documentsResolver = DocumentsResolver { listOf() }
}.build()

}.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package id.animo.mdocdatatransfer

import android.util.Log
import expo.modules.kotlin.Promise
import expo.modules.kotlin.exception.Exceptions
import expo.modules.kotlin.modules.Module
Expand Down Expand Up @@ -39,7 +38,6 @@ class MdocDataTransferModule : Module() {


AsyncFunction("startQrEngagement") { promise: Promise ->
Log.d("ABBA", "cheese")
mDocDataTransfer?.apply {
onQrEngagementReady = { qrCode ->
promise.resolve(qrCode)
Expand All @@ -58,5 +56,9 @@ class MdocDataTransferModule : Module() {
Function("shutdown") {
(mDocDataTransfer ?: throw MdocDataTransferException.NotInitialized()).shutdown()
}

Function("enableNfc") {
(mDocDataTransfer ?: throw MdocDataTransferException.NotInitialized()).enableNfc()
}
}
}
47 changes: 40 additions & 7 deletions example/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { mdocDataTransfer } from '@animo-id/expo-mdoc-data-transfer'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { Button, Platform, View } from 'react-native'
import { type Permission, PermissionsAndroid } from 'react-native'

import QrCode from 'react-native-qrcode-svg'
import { SafeAreaView } from 'react-native-safe-area-context'

const Pad = () => <View style={{ marginBottom: 10 }} />

Expand All @@ -20,15 +21,26 @@ const requestPermissions = async () => PermissionsAndroid.requestMultiple(PERMIS
export const App = () => {
const [qrCode, setQrCode] = useState<string>()

useEffect(() => {
return () => {
mdocDataTransfer.instance().shutdown()
}
}, [])

const startEngagement = async () => {
const mdt = mdocDataTransfer.instance()
//const qr = await mdt.startQrEngagement()
const qr = await mdt.startQrEngagement()
mdt.enableNfc()
await mdt.sendDeviceResponse(new Uint8Array([1, 2, 3]))
//setQrCode(qr)
//await mdt.waitForDeviceRequest()
//console.log('--- convert device request into a device response ---')
//await mdt.sendDeviceResponse(new Uint8Array())
//await mdt.shutdown()
setQrCode(qr)
await mdt.waitForDeviceRequest()
console.log('--- convert device request into a device response ---')
await mdt.sendDeviceResponse(new Uint8Array())
mdt.shutdown()
}

const shutdown = () => {
mdocDataTransfer.instance().shutdown()
}

return (
Expand All @@ -37,7 +49,28 @@ export const App = () => {
<Pad />
<Button title="start engagement" onPress={startEngagement} />
<Pad />
<Button title="shutdown" onPress={shutdown} />
<Pad />
{qrCode && <QrCode value={qrCode} size={300} />}
</View>
)
}

export const PApp = () => {
const [renderApp, setRenderApp] = useState(false)

if (renderApp) {
return (
<SafeAreaView style={{ flex: 1 }}>
<Button title="remove app" onPress={() => setRenderApp(false)} />
<App />
</SafeAreaView>
)
}

return (
<SafeAreaView>
<Button title="render app" onPress={() => setRenderApp(true)} />
</SafeAreaView>
)
}
4 changes: 2 additions & 2 deletions example/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerRootComponent } from 'expo'
import { App } from './App'
import { PApp } from './App'

// Register the app as the main component
registerRootComponent(App)
registerRootComponent(PApp)
Loading

0 comments on commit 3938607

Please sign in to comment.