@sphereon/ssi-sdk-qr-react
Version:
QR Code provider (react)
146 lines (111 loc) • 3.6 kB
Markdown
<!--suppress HtmlDeprecatedAttribute -->
<h1 align="center">
<br>
<a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a>
<br>waci-pex-qr-react (Typescript)
<br>
</h1>
---
**Warning: This package still is in very early development. Breaking changes without notice will happen at this point!**
---
A `Sphereon SSI-SDK` plugin to create an QR code and to verify using `SIOPv2` or `OIDC4`. This plugin component is only
supporting react and react-native frameworks.
It will be possible in future to request the issuer to issue credentials.
```shell
yarn add @sphereon/ssi-sdk-waci-pex-qr-react
```
```shell
yarn build
```
The usage scenario will include the plugin code to be integrated in the client code. A party will be requesting the
recipient to either:
1. authenticate itself to the requester
2. inviting the issuer to issue a credential
The object fields required to generate the QR code will depend on the type of request and the acceptable values. The
possible `accept` value may be:
1. `oidc4vp`
2. `siopv2+oidc4vp`
3. `siopv2`
4. `didcomm/v2`
```typescript
import { QrCodeProvider } from '@sphereon/ssi-sdk-waci-pex-qr-react'
// Include in the interface
// const agent = createAgent<... QrCodeProvider>
```
```typescript
plugins: [
...
new QrCodeProvider()
],
```
```typescript
export const createSsiQrCode = agent.ssiQrCode
```
The function declared in agent can be imported for usage like below:
```typescript
import { createSsiQrCode } from '../agent'
import { QRContent, QRType } from '@sphereon/ssi-sdk-waci-pex-qr-react'
```
```typescript
import { WaciOobProps } from '@sphereon/ssi-sdk-waci-pex-qr-react'
function getOobQrCodeProps(): QRRenderingProps {
return {
baseUrl: 'https://example.com/?oob=',
type: QRType.SIOPV2,
id: '599f3638-b563-4937-9487-dfe55099d900',
from: 'did:key:zrfdjkgfjgfdjk',
object: {
goalCode: GoalCode.STREAMLINED_VP,
accept: [AcceptMode.SIOPV2_WITH_OIDC4VP],
},
onGenerate: (oobQRProps: QRRenderingProps, payload: WaciOobProps) => {
console.log(payload)
},
bgColor: 'white',
fgColor: 'black',
level: 'L',
size: 128,
title: 'title2021120903',
}
}
delegateCreateOobQRCode = () => {
let qrCode = createQrCode(this.getOobQrCodeProps())
return qrCode.then((qrCodeResolved) => {
return qrCodeResolved
})
}
```
On generate gives the following (example) output
```json lines
{
"type": "openid",
"id": "599f3638-b563-4937-9487-dfe55099d900",
"from": "did:key:zrfdjkgfjgfdjk",
"object": {
"goal-code": "streamlined-vp",
"accept": ["siopv2+oidc4vp"]
}
}
```
If you want to create the payload manually and want to do serialization yourself you can use:
```typescript
const payload = DidCommOutOfBandMessage.createPayload(getOobQrCodeProps())
const encoded = DidCommOutOfBandMessage.urlEncode(payload)
const url = oobQRProps.baseUrl + encoded
console.log(url) // https://example.com/?oob=eyJ0eXBlIjoic2lvcHYyIiwiaWQiOiI1OTlmMzYzOC1iNTYzLTQ5MzctOTQ4Ny1kZmU1NTA5OWQ5MDAiLCJmcm9tIjoiZGlkOmtleTp6cmZkamtnZmpnZmRqayIsImJvZHkiOnsiZ29hbC1jb2RlIjoic3RyZWFtbGluZWQtdnAiLCJhY2NlcHQiOlsic2lvcHYyK29pZGM0dnAiXX19
```
```jsx
<View>
//...
{this.delegateCreateOobQRCode()}
</View>
```