Skip to content

Commit

Permalink
feat(mdoc): proximity flow
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 6, 2024
1 parent 3e3c834 commit d676c72
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/easypid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@package/secure-store": "workspace:*",
"@package/ui": "workspace:*",
"@package/utils": "workspace:*",
"@protokoll/mdoc-client": "0.2.36",
"@react-native-community/blur": "^4.3.2",
"@react-native-community/netinfo": "11.4.1",
"@react-native-masked-view/masked-view": "0.3.1",
Expand Down Expand Up @@ -55,6 +56,7 @@
"react-native-get-random-values": "~1.11.0",
"react-native-keychain": "^8.2.0",
"react-native-mmkv": "^2.12.2",
"react-native-qrcode-svg": "^6.3.12",
"react-native-reanimated": "~3.16.1",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "4.0.0-beta.16",
Expand Down
19 changes: 19 additions & 0 deletions apps/easypid/src/features/proximity/MdocQrCode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { mdocDataTransfer } from '@animo-id/expo-mdoc-data-transfer'
import { Loader } from '@package/ui'
import { useEffect, useState } from 'react'
import QrCode from 'react-native-qrcode-svg'

export const MdocQrCode = () => {
const [qrCodeData, setQrCodeData] = useState<string>()

useEffect(() => {
const mdt = mdocDataTransfer.instance()
mdt.startQrEngagement().then(setQrCodeData)
}, [])

if (!qrCodeData) {
return <Loader size="large" />
}

return <QrCode value={qrCodeData} />
}
3 changes: 3 additions & 0 deletions apps/easypid/src/features/proximity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { MdocQrCode } from './MdocQrCode'
export { waitForDeviceRequestAndSessionTranscript } from './waitForDeviceRequestAndSessionTranscript'
export { shareDeviceResponse } from './shareDeviceResponse'
42 changes: 42 additions & 0 deletions apps/easypid/src/features/proximity/shareDeviceResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { mdocDataTransfer } from '@animo-id/expo-mdoc-data-transfer'
import { Key, KeyType, TypedArrayEncoder, getJwkFromKey } from '@credo-ts/core'
import { getMdocContext } from '@credo-ts/core/build/modules/mdoc/MdocContext'
import { deviceKeyPair } from '@easypid/storage/pidPin'
import type { EasyPIDAppAgent } from '@package/agent'
import { DeviceRequest, DeviceResponse, MDoc, type MdocContext, parseIssuerSigned } from '@protokoll/mdoc-client'

type ShareDeviceResponseOptions = {
sessionTranscript: Uint8Array
deviceRequest: Uint8Array
agent: EasyPIDAppAgent
}

export const shareDeviceResponse = async (options: ShareDeviceResponseOptions) => {
const mdocs = await options.agent.mdoc.getAll()
const issuerSignedDocuments = mdocs.map((mdoc) => {
const docType = mdoc.getTag('DocType') as string
return parseIssuerSigned(TypedArrayEncoder.fromBase64(mdoc.base64Url), docType)
})

const mdoc = new MDoc(issuerSignedDocuments)

const mdocContext = getMdocContext(options.agent.context) as unknown as {
cose: MdocContext['cose']
crypto: MdocContext['crypto']
}

const mdt = mdocDataTransfer.instance()

const key = Key.fromPublicKey(deviceKeyPair.publicKey(), KeyType.P256)
const devicePublicKey = getJwkFromKey(key)

const deviceRequest = DeviceRequest.parse(options.deviceRequest)

const deviceResponse = await DeviceResponse.from(mdoc)
.usingSessionTranscriptBytes(options.sessionTranscript)
.usingDeviceRequest(deviceRequest)
.authenticateWithSignature(devicePublicKey, 'ES256')
.sign(mdocContext)

await mdt.sendDeviceResponse(deviceResponse.encode())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { mdocDataTransfer } from '@animo-id/expo-mdoc-data-transfer'

export const waitForDeviceRequestAndSessionTranscript = mdocDataTransfer.instance().waitForDeviceRequest
69 changes: 69 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d676c72

Please sign in to comment.