0.34.0 • Published 7 months ago

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

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
7 months 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.30.2-next.394

1 year ago

0.30.2-next.395

1 year ago

0.30.2-fix.364

1 year ago

0.30.2-fix.363

1 year ago

0.30.2-fix.368

1 year ago

0.30.2-fix.367

1 year ago

0.30.2-next.373

1 year ago

0.31.1-fix.4

1 year ago

0.31.1-fix.5

1 year ago

0.33.0

9 months ago

0.30.2-next.148

1 year ago

0.30.2-next.145

1 year ago

0.31.1-next.4

1 year ago

0.30.2-next.390

1 year ago

0.31.0

1 year ago

0.30.2-next.191

1 year ago

0.30.2-fix.199

1 year ago

0.30.2-fix.198

1 year ago

0.30.2-next.328

1 year ago

0.30.2-next.329

1 year ago

0.32.1-next.291

9 months ago

0.32.1-next.287

9 months ago

0.30.2-fix.395

1 year ago

0.30.2-fix.393

1 year ago

0.30.2-next.365

1 year ago

0.30.2-next.367

1 year ago

0.30.2-next.362

1 year ago

0.30.2-next.363

1 year ago

0.30.2-fix.139

1 year ago

0.30.2-fix.140

1 year ago

0.31.1-fix.20

1 year ago

0.30.2-next.276

1 year ago

0.30.2-next.279

1 year ago

0.30.2-next.273

1 year ago

0.30.2-next.275

1 year ago

0.30.2-next.281

1 year ago

0.32.0

1 year ago

0.30.2-next.285

1 year ago

0.30.2-next.259

1 year ago

0.32.1-next.113

11 months ago

0.30.2-next.269

1 year ago

0.30.2-next.267

1 year ago

0.31.1-next.44

1 year ago

0.31.1-next.42

1 year ago

0.31.1-next.41

1 year ago

0.31.1-next.39

1 year ago

0.31.1-next.33

1 year ago

0.31.1-next.32

1 year ago

0.32.1-fix.160

10 months ago

0.31.1-next.30

1 year ago

0.32.1-next.161

10 months ago

0.30.2-next.297

1 year ago

0.33.1-next.3

8 months ago

0.33.1-next.2

8 months ago

0.31.1-next.62

1 year ago

0.32.1-next.54

11 months ago

0.32.1-next.157

10 months ago

0.31.1-next.60

1 year ago

0.32.1-next.150

10 months ago

0.32.1-next.141

10 months ago

0.32.1-next.145

10 months ago

0.33.1-next.73

7 months ago

0.32.1-fix.143

10 months ago

0.32.1-fix.142

10 months ago

0.33.1-next.68

7 months ago

0.30.2-next.200

1 year ago

0.31.1-next.29

1 year ago

0.31.1-next.26

1 year ago

0.31.1-next.28

1 year ago

0.31.1-next.21

1 year ago

0.31.1-next.24

1 year ago

0.31.1-next.23

1 year ago

0.31.1-next.19

1 year ago

0.31.1-next.14

1 year ago

0.31.1-next.17

1 year ago

0.31.1-next.13

1 year ago

0.34.0

7 months ago

0.30.2-fix.278

1 year ago

0.30.2-fix.270

1 year ago

0.30.2-fix.280

1 year ago

0.30.2-next.215

1 year ago

0.30.2-next.221

1 year ago

0.30.2-next.223

1 year ago

0.30.2-fix.266

1 year ago

0.30.2-fix.265

1 year ago

0.30.2-fix.263

1 year ago

0.30.2-fix.262

1 year ago

0.32.1-fix.15

12 months ago

0.32.1-next.13

12 months ago

0.32.1-next.17

12 months ago

0.32.1-next.18

12 months ago

0.32.1-next.12

1 year ago

0.32.1-next.20

11 months ago

0.30.2-fix.138

1 year ago

0.30.2-next.133

1 year ago

0.30.2-next.135

1 year ago

0.30.2-fix.136

1 year ago

0.30.2-next.129

1 year ago

0.30.2-next.125

1 year ago

0.30.2-next.103

1 year ago

0.30.2-fix.50

1 year ago

0.30.2-fix.48

1 year ago

0.30.2-fix.49

1 year ago

0.30.2-next.58

1 year ago

0.30.2-next.66

1 year ago

0.30.2-next.47

1 year ago

0.30.2-next.4

1 year ago

0.30.2-next.5

1 year ago

0.30.2-next.6

1 year ago

0.29.1-next.185

1 year ago

0.30.1

1 year ago

0.29.1-next.175

1 year ago

0.29.1-next.174

1 year ago

0.29.1-next.177

1 year ago

0.29.1-next.176

1 year ago

0.27.1-next.20

1 year ago

0.27.1-next.24

1 year ago

0.27.1-next.25

1 year ago

0.29.1-next.80

1 year ago

0.27.1-next.28

1 year ago

0.27.1-next.29

1 year ago

0.27.1-next.26

1 year ago

0.29.1-next.82

1 year ago

0.28.1-next.51

1 year ago

0.28.1-next.50

1 year ago

0.28.1-next.53

1 year ago

0.28.1-next.52

1 year ago

0.27.1-next.31

1 year ago

0.27.1-next.33

1 year ago

0.27.1-next.39

1 year ago

0.27.1-next.38

1 year ago

0.28.1-next.48

1 year ago

0.28.1-next.49

1 year ago

0.28.1-next.44

1 year ago

0.29.1-next.5

1 year ago

0.28.1-next.40

1 year ago

0.26.1-next.6

1 year ago

0.29.1-next.4

1 year ago

0.26.1-next.4

1 year ago

0.29.1-next.2

1 year ago

0.28.1-next.41

1 year ago

0.26.1-next.140

1 year ago

0.29.1-next.61

1 year ago

0.28.1-next.60

1 year ago

0.26.1-next.129

1 year ago

0.26.1-next.127

1 year ago

0.26.1-next.131

1 year ago

0.26.1-next.132

1 year ago

0.26.1-next.115

1 year ago

0.26.1-next.113

1 year ago

0.26.1-next.108

1 year ago

0.26.1-next.106

1 year ago

0.25.0

1 year ago

0.27.1-next.8

1 year ago

0.27.1-next.9

1 year ago

0.27.1-next.6

1 year ago

0.27.1-next.7

1 year ago

0.27.1-next.4

1 year ago

0.27.1-next.2

1 year ago

0.26.0

1 year ago

0.28.1-next.11

1 year ago

0.28.1-next.10

1 year ago

0.28.1-next.13

1 year ago

0.25.1-next.118

1 year ago

0.28.1-next.39

1 year ago

0.24.0

2 years ago

0.29.0

1 year ago

0.24.1-next.98

2 years ago

0.27.0

1 year ago

0.24.1-next.42

2 years ago

0.28.0

1 year ago

0.29.1-next.122

1 year ago

0.25.1-next.29

1 year ago

0.25.1-next.28

1 year ago

0.28.1-next.9

1 year ago

0.28.1-next.5

1 year ago

0.28.1-next.6

1 year ago

0.28.1-next.8

1 year ago

0.23.5-next.24

2 years ago

0.29.1-next.104

1 year ago

0.29.1-next.103

1 year ago

0.29.1-next.47

1 year ago

0.29.1-next.46

1 year ago

0.29.1-next.106

1 year ago

0.29.1-next.105

1 year ago

0.24.1-next.100

2 years ago

0.27.1-next.10

1 year ago

0.27.1-next.12

1 year ago

0.24.1-next.113

1 year ago

0.24.1-next.112

2 years ago

0.24.1-next.118

1 year ago

0.24.1-next.116

1 year ago

0.23.5-next.22

2 years ago

0.23.5-next.12

2 years ago

0.23.5-next.11

2 years ago

0.23.5-next.10

2 years ago

0.23.1-next.7

2 years ago

0.23.3-next.3

2 years ago

0.23.4

2 years ago

0.23.2-next.4

2 years ago

0.23.1-next.2

2 years ago

0.23.0

2 years ago

0.21.2-next.25

2 years ago

0.21.2-next.23

2 years ago

0.21.2-next.8

2 years ago

0.21.2-next.7

2 years ago

0.21.2-next.6

2 years ago

0.21.2-next.17

2 years ago

0.22.0

2 years ago

0.21.1-next.8

2 years ago

0.21.1-next.4

2 years ago

0.19.1-next.125

2 years ago

0.19.1-next.126

2 years ago

0.21.0

2 years ago

0.19.1-next.119

2 years ago

0.19.1-next.135

2 years ago

0.21.1-next.2

2 years ago

0.19.1-next.117

2 years ago

0.19.1-next.113

2 years ago

0.19.1-next.114

2 years ago

0.19.1-next.115

2 years ago

0.19.1-next.116

2 years ago

0.19.1-next.111

2 years ago

0.19.1-next.112

2 years ago

0.19.1-next.105

2 years ago

0.19.1-next.110

2 years ago

0.19.1-next.106

2 years ago

0.19.1-next.108

2 years ago

0.19.1-next.109

2 years ago

0.19.1-next.98

2 years ago

0.19.1-next.99

2 years ago

0.19.1-next.102

2 years ago

0.19.1-next.100

2 years ago

0.19.1-next.101

2 years ago

0.19.1-next.96

2 years ago

0.19.1-next.75

2 years ago

0.19.1-next.2

2 years ago

0.19.1-next.24

2 years ago

0.19.0

2 years ago

0.18.2-next.96

2 years ago

0.18.2-next.95

2 years ago

0.18.2-next.94

2 years ago

0.18.2-next.92

2 years ago

0.18.2-next.58

2 years ago

0.18.2-next.62

2 years ago

0.18.2-next.77

2 years ago

0.18.2-next.57

2 years ago

0.18.2-next.47

2 years ago

0.18.2-next.15

2 years ago

0.18.2-next.17

2 years ago

0.18.2-next.14

2 years ago

0.18.2-next.12

2 years ago

0.18.2-next.9

2 years ago

0.18.2-next.3

2 years ago

0.18.1

2 years ago

0.18.1-next.8

2 years ago

0.18.1-next.3

2 years ago

0.18.1-next.2

2 years ago

0.18.1-next.4

2 years ago

0.17.6-next.61

2 years ago

0.18.0

2 years ago

0.17.6-next.58

2 years ago

0.17.6-next.57

2 years ago

0.17.6-next.56

2 years ago

0.17.6-next.52

2 years ago

0.17.2

2 years ago

0.17.3

2 years ago

0.17.4

2 years ago

0.17.5

2 years ago

0.16.1-next.3

2 years ago

0.17.0

2 years ago

0.17.1

2 years ago

0.17.2-next.2

2 years ago

0.17.2-next.4

2 years ago

0.15.2-next.96

2 years ago

0.15.2-next.95

2 years ago

0.15.2-next.97

2 years ago

0.13.1-next.3

2 years ago

0.13.1-next.4

2 years ago

0.13.1-next.5

2 years ago

0.13.1-next.6

2 years ago

0.13.1-next.7

2 years ago

0.13.1-next.8

2 years ago

0.13.1-next.32

2 years ago

0.17.1-next.2

2 years ago

0.13.1-next.33

2 years ago

0.15.0

2 years ago

0.15.1

2 years ago

0.13.1-next.17

2 years ago

0.13.1-next.14

2 years ago

0.13.1-next.15

2 years ago

0.13.1-next.10

2 years ago

0.13.1-next.18

2 years ago

0.16.0

2 years ago

0.13.1-next.27

2 years ago

0.13.1-next.28

2 years ago

0.13.1-next.25

2 years ago

0.13.1-next.26

2 years ago

0.13.1-next.23

2 years ago

0.13.1-next.24

2 years ago

0.15.1-next.2

2 years ago

0.17.3-next.2

2 years ago

0.15.2-next.39

2 years ago

0.15.2-next.32

2 years ago

0.15.2-next.33

2 years ago

0.15.2-next.113

2 years ago

0.15.2-next.110

2 years ago

0.15.2-next.111

2 years ago

0.17.6-next.7

2 years ago

0.17.6-next.6

2 years ago

0.17.6-next.9

2 years ago

0.17.6-next.3

2 years ago

0.17.6-next.2

2 years ago

0.17.6-next.5

2 years ago

0.17.6-next.4

2 years ago

0.14.2-next.28

2 years ago

0.14.2-next.27

2 years ago

0.14.2-next.29

2 years ago

0.14.2-next.23

2 years ago

0.15.2-next.103

2 years ago

0.14.2-next.26

2 years ago

0.15.2-next.104

2 years ago

0.14.2-next.25

2 years ago

0.14.0

2 years ago

0.15.2-next.109

2 years ago

0.14.1

2 years ago

0.15.2-next.124

2 years ago

0.15.2-next.121

2 years ago

0.15.2-next.29

2 years ago

0.14.2-next.18

2 years ago

0.15.2-next.116

2 years ago

0.15.2-next.117

2 years ago

0.15.2-next.114

2 years ago

0.14.2-next.14

2 years ago

0.15.2-next.118

2 years ago

0.14.2-next.40

2 years ago

0.15.2-next.4

2 years ago

0.15.2-next.5

2 years ago

0.15.2-next.6

2 years ago

0.14.2-next.49

2 years ago

0.14.2-next.45

2 years ago

0.14.2-next.48

2 years ago

0.14.2-next.47

2 years ago

0.14.2-next.42

2 years ago

0.15.2-next.77

2 years ago

0.14.2-next.41

2 years ago

0.14.2-next.43

2 years ago

0.15.2-next.101

2 years ago

0.14.2-next.39

2 years ago

0.14.2-next.38

2 years ago

0.14.1-next.2

2 years ago

0.14.2-next.35

2 years ago

0.14.2-next.34

2 years ago

0.14.2-next.37

2 years ago

0.14.2-next.36

2 years ago

0.14.2-next.31

2 years ago

0.14.2-next.30

2 years ago

0.14.2-next.33

2 years ago

0.14.2-next.32

2 years ago

0.14.2-next.51

2 years ago

0.14.2-next.50

2 years ago

0.17.6-next.16

2 years ago

0.15.2-next.3

2 years ago

0.14.2-next.58

2 years ago

0.13.0

2 years ago

0.12.1-next.21

2 years ago

0.12.1-next.20

2 years ago

0.12.1-next.19

2 years ago

0.12.0

2 years ago

0.11.1-next.154

2 years ago

0.11.1-next.153

2 years ago

0.11.1-next.152

2 years ago

0.11.1-next.162

2 years ago

0.11.1-next.151

2 years ago

0.11.1-next.150

2 years ago

0.11.1-next.149

2 years ago

0.11.1-next.148

2 years ago

0.11.1-next.147

2 years ago

0.11.1-next.146

2 years ago

0.11.1-next.145

2 years ago

0.11.1-next.144

2 years ago

0.11.1-next.142

2 years ago

0.11.1-next.141

2 years ago

0.11.1-next.140

2 years ago

0.11.1-next.131

2 years ago

0.11.1-next.112

3 years ago

0.11.1-next.106

3 years ago

0.11.1-next.72

3 years ago

0.11.1-next.70

3 years ago

0.11.1-next.65

3 years ago