-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Berend Sliedrecht <[email protected]>
- Loading branch information
Berend Sliedrecht
committed
Nov 6, 2024
1 parent
3e3c834
commit d676c72
Showing
6 changed files
with
138 additions
and
0 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
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} /> | ||
} |
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,3 @@ | ||
export { MdocQrCode } from './MdocQrCode' | ||
export { waitForDeviceRequestAndSessionTranscript } from './waitForDeviceRequestAndSessionTranscript' | ||
export { shareDeviceResponse } from './shareDeviceResponse' |
42 changes: 42 additions & 0 deletions
42
apps/easypid/src/features/proximity/shareDeviceResponse.ts
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,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()) | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/easypid/src/features/proximity/waitForDeviceRequestAndSessionTranscript.ts
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,3 @@ | ||
import { mdocDataTransfer } from '@animo-id/expo-mdoc-data-transfer' | ||
|
||
export const waitForDeviceRequestAndSessionTranscript = mdocDataTransfer.instance().waitForDeviceRequest |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.