0.23.4 • Published 18 hours ago

@sphereon/ssi-sdk.qr-code-generator v0.23.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
18 hours ago

qr-code-generator

A Sphereon SSI-SDK plugin to create an QR codes for SIOPv2/OpenID4VP, DIDCommv2 and OpenID4VCI. Next to the above specific QR types, of course you can also generate generic QR codes with this package.

It is tailored towards React and React-Native but also provides textual representations.

Installation

yarn add @sphereon/ssi-sdk.qr-code-generator

Build

yarn build

Usage

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

Importing the plugin

import { QrCodeProvider } from '@sphereon/ssi-sdk.qr-code-generator'

// Include in the interface
// const agent = createAgent<...  QrCodeProvider>

Adding plugin to the agent

plugins: [...new QrCodeProvider()]

Inside the component we can declare or get the values to pass to QR Code plugin

import { WaciOobProps } from '@sphereon/ssi-sdk.qr-code-generator'

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

{
  "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:

const payload = DidCommOutOfBandMessage.createPayload(getOobQrCodeProps())
const encoded = DidCommOutOfBandMessage.urlEncode(payload)
const url = oobQRProps.baseUrl + encoded
console.log(url) // https://example.com/?oob=eyJ0eXBlIjoic2lvcHYyIiwiaWQiOiI1OTlmMzYzOC1iNTYzLTQ5MzctOTQ4Ny1kZmU1NTA5OWQ5MDAiLCJmcm9tIjoiZGlkOmtleTp6cmZkamtnZmpnZmRqayIsImJvZHkiOnsiZ29hbC1jb2RlIjoic3RyZWFtbGluZWQtdnAiLCJhY2NlcHQiOlsic2lvcHYyK29pZGM0dnAiXX19

For rendering add to the view

<View>
  //...
  {this.delegateCreateOobQRCode()}
</View>

OpenID4VCI example:

This is the credential offer

export const credentialOffer = JSON.stringify({
  credential_issuer: 'https://credential-issuer.example.com',
  credentials: [
    'UniversityDegree_JWT',
    {
      format: 'mso_mdoc',
      doctype: 'org.iso.18013.5.1.mDL',
    },
  ],
  grants: {
    authorization_code: {
      issuer_state: 'eyJhbGciOiJSU0Et...FYUaBy',
    },
    'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
      'pre-authorized_code': 'adhjhdjajkdkhjhdj',
      user_pin_required: true,
    },
  },
})

It needs to be assigned to the credentialOffer field in the data scheme. The same can be done using a reference, this will require to use the credentialOfferUri property and assign the uri of the credential offer to it. Notice that the scheme defaults to openid-credential-offer and baseUri is optional.

const openid4vcObjectValue: OpenID4VCIDataWithScheme = {
  scheme: 'https',
  baseUri: 'test.com/credential-offer',
  credentialOffer,
}

Now the data scheme needs to be added to the QR code data

const openid4vciDataValue: QRData<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
  object: openid4vcObjectValue,
  type: QRType.OpenID4VCI,
  id: '568',
}

So the QR code can be generated

export const openid4vciCreateValue: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
  data: openid4vciDataValue,
  onGenerate: (result: ValueResult<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>) => {
    console.log(result, null, 2)
  },
}

And eventually added to an app

export const openid4vciCreateElement: CreateElementArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
  data: openid4vciDataValue,
  renderingProps,
  onGenerate: (result: ValueResult<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>) => {
    render(<div data-testid="test-div-openid4vci">{result.data.object.credentialOffer}</div>)
    console.log(result.value)
  },
}
0.23.5-unstable.17

18 hours ago

0.23.5-next.12

6 days ago

0.23.5-next.11

6 days ago

0.23.5-next.10

8 days ago

0.23.1-next.7

14 days ago

0.23.3-next.3

13 days ago

0.23.4

13 days ago

0.23.2-next.4

13 days ago

0.23.1-next.2

14 days ago

0.23.0

14 days ago

0.21.2-next.25

14 days ago

0.21.2-next.23

27 days ago

0.21.2-next.8

28 days ago

0.21.2-next.7

29 days ago

0.21.2-next.6

29 days ago

0.21.2-next.17

28 days ago

0.22.0

1 month ago

0.21.1-next.8

1 month ago

0.21.1-next.4

1 month ago

0.21.1-unstable.5

2 months ago

0.19.1-next.125

2 months ago

0.19.1-next.126

2 months ago

0.21.0

2 months ago

0.19.1-next.119

2 months ago

0.19.1-next.135

2 months ago

0.21.1-next.2

2 months ago

0.19.1-next.117

2 months ago

0.19.1-next.113

2 months ago

0.19.1-next.114

2 months ago

0.19.1-next.115

2 months ago

0.19.1-next.116

2 months ago

0.19.1-next.111

2 months ago

0.19.1-next.112

2 months ago

0.19.1-next.105

2 months ago

0.19.1-next.110

2 months ago

0.19.1-next.106

2 months ago

0.19.1-next.108

2 months ago

0.19.1-next.109

2 months ago

0.19.1-next.98

2 months ago

0.19.1-next.99

2 months ago

0.19.1-next.102

2 months ago

0.19.1-next.100

2 months ago

0.19.1-next.101

2 months ago

0.19.1-next.96

2 months ago

0.19.1-unstable.88

2 months ago

0.19.1-unstable.89

2 months ago

0.19.1-unstable.86

2 months ago

0.19.1-unstable.87

2 months ago

0.19.1-unstable.93

2 months ago

0.19.1-unstable.94

2 months ago

0.19.1-unstable.91

2 months ago

0.19.1-unstable.92

2 months ago

0.19.1-unstable.90

2 months ago

0.19.1-unstable.84

2 months ago

0.19.1-unstable.85

2 months ago

0.19.1-unstable.82

2 months ago

0.19.1-unstable.80

2 months ago

0.19.1-unstable.81

2 months ago

0.19.1-unstable.78

2 months ago

0.19.1-unstable.77

2 months ago

0.19.1-unstable.75

2 months ago

0.19.1-next.75

2 months ago

0.19.1-unstable.73

2 months ago

0.19.1-unstable.74

2 months ago

0.19.1-unstable.69

2 months ago

0.19.1-unstable.67

2 months ago

0.19.1-unstable.65

2 months ago

0.19.1-unstable.63

2 months ago

0.19.1-next.2

2 months ago

0.18.2-unstable.98

2 months ago

0.19.1-next.24

2 months ago

0.19.0

2 months ago

0.18.2-next.96

2 months ago

0.18.2-unstable.57

2 months ago

0.18.2-unstable.97

2 months ago

0.18.2-next.95

2 months ago

0.18.2-next.94

2 months ago

0.18.2-next.92

2 months ago

0.18.2-unstable.96

2 months ago

0.18.2-unstable.95

2 months ago

0.18.2-unstable.55

2 months ago

0.18.2-unstable.89

2 months ago

0.18.2-unstable.88

2 months ago

0.18.2-unstable.90

2 months ago

0.18.2-unstable.87

2 months ago

0.18.2-unstable.85

2 months ago

0.18.2-next.58

3 months ago

0.18.2-next.62

3 months ago

0.18.2-unstable.12

3 months ago

0.18.2-unstable.61

3 months ago

0.18.2-next.77

3 months ago

0.18.2-unstable.56

3 months ago

0.18.2-unstable.53

3 months ago

0.18.2-unstable.67

3 months ago

0.18.2-unstable.64

3 months ago

0.18.2-next.57

3 months ago

0.18.2-unstable.59

3 months ago

0.18.2-unstable.60

3 months ago

0.18.2-next.47

3 months ago

0.18.2-next.15

3 months ago

0.18.2-next.17

3 months ago

0.18.2-unstable.54

3 months ago

0.18.2-unstable.51

3 months ago

0.18.2-unstable.50

3 months ago

0.18.2-next.14

3 months ago

0.18.2-unstable.22

3 months ago

0.18.2-next.12

3 months ago

0.18.2-unstable.46

3 months ago

0.18.2-next.9

3 months ago

0.18.2-unstable.14

3 months ago

0.18.2-unstable.13

3 months ago

0.18.2-unstable.44

3 months ago

0.18.2-unstable.34

3 months ago

0.18.2-unstable.36

3 months ago

0.18.2-unstable.35

3 months ago

0.18.2-unstable.33

3 months ago

0.18.2-unstable.32

3 months ago

0.18.2-unstable.30

3 months ago

0.18.2-unstable.5

3 months ago

0.18.2-unstable.6

3 months ago

0.18.2-unstable.7

3 months ago

0.18.2-unstable.8

3 months ago

0.18.2-unstable.10

3 months ago

0.17.6-unstable.80

3 months ago

0.17.6-unstable.79

3 months ago

0.18.2-next.3

4 months ago

0.18.2-unstable.25

4 months ago

0.18.2-unstable.24

4 months ago

0.18.1

4 months ago

0.18.1-next.8

4 months ago

0.18.1-next.3

4 months ago

0.18.1-next.2

4 months ago

0.18.1-next.4

4 months ago

0.17.6-next.61

4 months ago

0.18.0

4 months ago

0.17.6-next.58

4 months ago

0.17.6-unstable.74

4 months ago

0.17.6-unstable.72

4 months ago

0.17.6-unstable.73

4 months ago

0.17.6-unstable.71

4 months ago

0.17.6-next.57

4 months ago

0.17.6-next.56

5 months ago

0.17.6-next.52

5 months ago

0.17.6-unstable.69

5 months ago

0.17.6-unstable.54

5 months ago

0.17.6-unstable.55

5 months ago

0.17.6-unstable.23

5 months ago

0.17.2

7 months ago

0.14.2-unstable.13

9 months ago

0.17.3

7 months ago

0.17.4

7 months ago

0.17.5

7 months ago

0.16.1-next.3

7 months ago

0.17.0

7 months ago

0.17.1

7 months ago

0.17.2-next.2

7 months ago

0.17.2-next.4

7 months ago

0.14.2-unstable.31

9 months ago

0.14.2-unstable.32

9 months ago

0.17.6-unstable.4

7 months ago

0.15.2-next.96

8 months ago

0.17.6-unstable.3

7 months ago

0.15.2-next.95

8 months ago

0.15.2-next.97

8 months ago

0.17.6-unstable.8

6 months ago

0.15.2-unstable.24

9 months ago

0.17.6-unstable.6

7 months ago

0.15.2-unstable.26

9 months ago

0.17.6-unstable.5

7 months ago

0.15.2-unstable.25

9 months ago

0.13.1-next.3

10 months ago

0.13.1-next.4

10 months ago

0.13.1-next.5

10 months ago

0.13.1-next.6

10 months ago

0.13.1-next.7

10 months ago

0.13.1-next.8

10 months ago

0.15.2-unstable.17

9 months ago

0.15.2-unstable.16

9 months ago

0.15.2-unstable.11

9 months ago

0.15.2-unstable.10

9 months ago

0.15.2-unstable.13

9 months ago

0.15.2-unstable.15

9 months ago

0.13.1-next.32

9 months ago

0.17.1-next.2

7 months ago

0.13.1-next.33

9 months ago

0.15.0

9 months ago

0.15.1

9 months ago

0.13.1-next.17

10 months ago

0.13.1-next.14

10 months ago

0.13.1-next.15

10 months ago

0.13.1-next.10

10 months ago

0.13.1-next.18

10 months ago

0.16.0

7 months ago

0.13.1-next.27

10 months ago

0.13.1-next.28

9 months ago

0.13.1-next.25

10 months ago

0.13.1-next.26

10 months ago

0.13.1-next.23

10 months ago

0.13.1-next.24

10 months ago

0.15.1-next.2

9 months ago

0.17.3-next.2

7 months ago

0.15.2-next.39

8 months ago

0.15.2-next.32

8 months ago

0.15.2-next.33

8 months ago

0.15.2-unstable.8

9 months ago

0.15.2-unstable.7

9 months ago

0.15.2-unstable.9

9 months ago

0.13.1-unstable.10

10 months ago

0.13.1-unstable.13

10 months ago

0.13.1-unstable.12

10 months ago

0.13.1-unstable.11

10 months ago

0.13.1-unstable.18

9 months ago

0.13.1-unstable.15

10 months ago

0.15.2-unstable.76

8 months ago

0.15.2-next.113

8 months ago

0.15.2-next.110

8 months ago

0.15.2-next.111

8 months ago

0.17.6-next.7

7 months ago

0.17.6-next.6

7 months ago

0.17.6-next.9

6 months ago

0.17.6-next.3

7 months ago

0.17.6-next.2

7 months ago

0.17.6-next.5

7 months ago

0.17.6-next.4

7 months ago

0.14.2-next.28

9 months ago

0.14.2-next.27

9 months ago

0.14.2-next.29

9 months ago

0.14.2-next.23

9 months ago

0.15.2-next.103

8 months ago

0.14.2-next.26

9 months ago

0.15.2-next.104

8 months ago

0.14.2-next.25

9 months ago

0.14.0

9 months ago

0.15.2-next.109

8 months ago

0.14.1

9 months ago

0.15.2-unstable.91

8 months ago

0.15.2-unstable.93

8 months ago

0.15.2-next.124

7 months ago

0.15.2-unstable.92

8 months ago

0.15.2-next.121

7 months ago

0.15.2-next.29

8 months ago

0.14.2-next.18

9 months ago

0.15.2-next.116

8 months ago

0.15.2-unstable.97

8 months ago

0.15.2-next.117

8 months ago

0.15.2-next.114

8 months ago

0.15.2-unstable.99

8 months ago

0.15.2-unstable.98

8 months ago

0.14.2-next.14

9 months ago

0.15.2-next.118

8 months ago

0.14.2-next.40

9 months ago

0.17.6-unstable.18

6 months ago

0.15.2-next.4

9 months ago

0.15.2-next.5

9 months ago

0.15.2-next.6

9 months ago

0.14.2-unstable.57

9 months ago

0.14.2-next.49

9 months ago

0.14.2-unstable.56

9 months ago

0.14.2-next.45

9 months ago

0.14.2-next.48

9 months ago

0.14.2-next.47

9 months ago

0.14.2-next.42

9 months ago

0.15.2-next.77

8 months ago

0.14.2-next.41

9 months ago

0.14.2-next.43

9 months ago

0.15.2-next.101

8 months ago

0.15.2-unstable.38

8 months ago

0.14.2-next.39

9 months ago

0.14.2-next.38

9 months ago

0.14.1-next.2

9 months ago

0.17.6-unstable.16

7 months ago

0.14.2-next.35

9 months ago

0.14.2-next.34

9 months ago

0.17.6-unstable.14

5 months ago

0.14.2-next.37

9 months ago

0.17.6-unstable.15

7 months ago

0.14.2-next.36

9 months ago

0.17.6-unstable.12

7 months ago

0.14.2-next.31

9 months ago

0.17.6-unstable.13

5 months ago

0.14.2-next.30

9 months ago

0.17.6-unstable.10

6 months ago

0.15.2-unstable.37

8 months ago

0.14.2-next.33

9 months ago

0.17.6-unstable.11

7 months ago

0.15.2-unstable.36

8 months ago

0.14.2-next.32

9 months ago

0.14.2-next.51

9 months ago

0.14.2-next.50

9 months ago

0.17.6-next.16

5 months ago

0.15.2-next.3

9 months ago

0.13.1-unstable.6

10 months ago

0.13.1-unstable.7

10 months ago

0.13.1-unstable.8

10 months ago

0.14.2-next.58

9 months ago

0.13.1-unstable.9

10 months ago

0.13.0

11 months ago

0.12.1-unstable.18

11 months ago

0.12.1-unstable.19

11 months ago

0.12.1-unstable.17

11 months ago

0.12.1-next.21

11 months ago

0.12.1-next.20

11 months ago

0.12.1-next.19

11 months ago

0.12.1-unstable.16

11 months ago

0.12.1-unstable.15

11 months ago

0.12.1-unstable.14

11 months ago

0.12.0

11 months ago

0.11.1-next.154

11 months ago

0.11.1-next.153

11 months ago

0.11.1-unstable.163

11 months ago

0.11.1-next.152

11 months ago

0.11.1-next.162

11 months ago

0.11.1-unstable.161

11 months ago

0.11.1-unstable.160

11 months ago

0.11.1-next.151

11 months ago

0.11.1-unstable.153

11 months ago

0.11.1-unstable.152

11 months ago

0.11.1-unstable.151

11 months ago

0.11.1-unstable.150

11 months ago

0.11.1-next.150

11 months ago

0.11.1-next.149

11 months ago

0.11.1-next.148

11 months ago

0.11.1-next.147

11 months ago

0.11.1-next.146

11 months ago

0.11.1-unstable.149

11 months ago

0.11.1-next.145

11 months ago

0.11.1-next.144

11 months ago

0.11.1-next.142

11 months ago

0.11.1-next.141

11 months ago

0.11.1-next.140

11 months ago

0.11.1-next.131

11 months ago

0.11.1-unstable.130

11 months ago

0.11.1-unstable.121

11 months ago

0.11.1-unstable.117

11 months ago

0.11.1-next.112

11 months ago

0.11.1-unstable.111

11 months ago

0.11.1-unstable.110

11 months ago

0.11.1-unstable.109

11 months ago

0.11.1-unstable.73

11 months ago

0.11.1-next.106

11 months ago

0.11.1-unstable.105

11 months ago

0.11.1-unstable.104

11 months ago

0.11.1-unstable.103

11 months ago

0.11.1-unstable.102

11 months ago

0.11.1-unstable.101

11 months ago

0.11.1-next.72

12 months ago

0.11.1-next.70

12 months ago

0.11.1-next.65

1 year ago