@sphereon/ssi-sdk.qr-code-generator 0.30.1-unstable.0 → 0.30.1-unstable.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.qr-code-generator",
3
- "version": "0.30.1-unstable.0",
3
+ "version": "0.30.1-unstable.2",
4
4
  "description": "QR Code provider (react)",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "@inrupt/jest-jsdom-polyfills": "^1.8.0",
25
- "@sphereon/ssi-sdk.agent-config": "0.30.1-unstable.0",
25
+ "@sphereon/ssi-sdk.agent-config": "0.30.1-unstable.2",
26
26
  "@testing-library/jest-dom": "^5.17.0",
27
27
  "@testing-library/react": "^14.3.1",
28
28
  "@types/jest": "^27.5.2",
@@ -58,5 +58,5 @@
58
58
  "OpenID4VCI",
59
59
  "QR Code"
60
60
  ],
61
- "gitHead": "2c333b01781741ce1d90cd0c63ab789445a62718"
61
+ "gitHead": "d1025655375142525533f5386107883cddaaa069"
62
62
  }
@@ -1,126 +1,126 @@
1
- import { IAgentPlugin } from '@veramo/core'
2
-
3
- import {
4
- CreateElementArgs,
5
- CreateValueArgs,
6
- DIDCommV2OOBInvitationData,
7
- IQRCodeGenerator,
8
- IRequiredContext,
9
- OpenID4VCIDataWithScheme,
10
- QRType,
11
- SIOPv2DataWithScheme,
12
- URIData,
13
- } from '../types/IQRCodeGenerator'
14
- import { DidCommOutOfBandMessage, generateQRCodeReactElement } from './utils'
15
- import { generateQRCodeReactElementImpl } from './utils/react-qr'
16
-
17
- /**
18
- * {@inheritDoc IQRCodeGenerator}
19
- */
20
- export class QrCodeProvider implements IAgentPlugin {
21
- readonly methods: IQRCodeGenerator = {
22
- qrDIDCommOobInvitationElement: QrCodeProvider.qrDIDCommOobInvitationElement.bind(this),
23
- qrDIDCommOobInvitationValue: QrCodeProvider.qrDIDCommOobInvitationValue.bind(this),
24
- qrSIOPv2Element: QrCodeProvider.qrSIOPv2Element.bind(this),
25
- qrSIOPv2Value: QrCodeProvider.qrSIOPv2Value.bind(this),
26
- qrURIElement: QrCodeProvider.qrURIElement.bind(this),
27
- qrOpenID4VCIElement: QrCodeProvider.qrOpenID4VCIElement.bind(this),
28
- qrOpenID4VCIValue: QrCodeProvider.qrOpenID4VCIValue.bind(this),
29
- }
30
-
31
- /** {@inheritDoc IQRCodeGenerator.uriElement} */
32
-
33
- private static async qrURIElement(args: CreateElementArgs<QRType.URI, URIData>, context: IRequiredContext): Promise<JSX.Element> {
34
- return generateQRCodeReactElement(args, context)
35
- }
36
-
37
- /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationValue} */
38
- private static async qrDIDCommOobInvitationValue(
39
- args: CreateValueArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
40
- context: IRequiredContext,
41
- ): Promise<string> {
42
- const { object } = args.data
43
- const encoded = DidCommOutOfBandMessage.urlEncode(object.oobInvitation)
44
- const delim = object.baseURI.includes('?') ? '&' : '?'
45
- return object.baseURI.includes('oob=') ? object.baseURI.replace('oob=', `oob=${encoded}`) : `${object.baseURI}${delim}_oob=${encoded}`
46
- }
47
-
48
- /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationElement} */
49
- private static async qrDIDCommOobInvitationElement(
50
- args: CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
51
- context: IRequiredContext,
52
- ): Promise<JSX.Element> {
53
- const content = await QrCodeProvider.qrDIDCommOobInvitationValue(args, context)
54
- return generateQRCodeReactElementImpl(
55
- {
56
- ...args,
57
- data: { ...args.data, object: content },
58
- } as CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, string>,
59
- args,
60
- context,
61
- )
62
- }
63
-
64
- /** {@inheritDoc IQRCodeGenerator.siopv2Value} */
65
- private static async qrSIOPv2Value(args: CreateValueArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<string> {
66
- const { object } = args.data
67
- if (typeof object === 'string') {
68
- return object
69
- }
70
-
71
- const scheme = (object.scheme ?? 'openid-vc://').replace('://?', '').replace('://', '') + '://'
72
- const requestUri = `request_uri=${object.requestUri.replace('request_uri=', '')}`
73
- return `${scheme}?${requestUri}`
74
- }
75
-
76
- /** {@inheritDoc IQRCodeGenerator.siopv2Element} */
77
- private static async qrSIOPv2Element(
78
- args: CreateElementArgs<QRType.SIOPV2, SIOPv2DataWithScheme>,
79
- context: IRequiredContext,
80
- ): Promise<JSX.Element> {
81
- const content = await QrCodeProvider.qrSIOPv2Value(args, context)
82
- return generateQRCodeReactElementImpl(
83
- { ...args, data: { ...args.data, object: content } } as CreateElementArgs<QRType.SIOPV2, string>,
84
- args,
85
- context,
86
- )
87
- }
88
-
89
- /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIElement} */
90
- private static async qrOpenID4VCIElement(args: CreateElementArgs<QRType.OpenID4VCI, any>, context: IRequiredContext): Promise<JSX.Element> {
91
- const content = await QrCodeProvider.qrOpenID4VCIValue(args, context)
92
- return generateQRCodeReactElementImpl(
93
- { ...args, data: { ...args.data, object: content } } as CreateElementArgs<QRType.OpenID4VCI, string>,
94
- args,
95
- context,
96
- )
97
- }
98
-
99
- /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIValue} */
100
- private static async qrOpenID4VCIValue(
101
- args: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>,
102
- context: IRequiredContext,
103
- ): Promise<string> {
104
- const { object } = args.data
105
- if (!object.credentialOffer && !object.credentialOfferUri) {
106
- throw new Error('Please provide credential_offer or credential_offer_uri')
107
- }
108
- const scheme = (object.scheme ?? 'openid-credential-offer://').replace('://?', '').replace('://', '') + '://'
109
- const baseUri = object.baseUri ?? ''
110
- let url
111
- const splitBaseUri = baseUri.split('://')
112
- const hasScheme = splitBaseUri.length > 1
113
- if (hasScheme && object.scheme) {
114
- if (splitBaseUri[0] !== object.scheme) {
115
- throw new Error('The uri must contain the same scheme or omit it')
116
- }
117
- url = `${baseUri}`
118
- } else {
119
- url = `${scheme}${baseUri}`
120
- }
121
- const credentialOfferUri = `?credential_offer_uri=${object.credentialOfferUri?.replace('credential_offer_uri=', '')}`
122
- const credentialOffer = `?credential_offer=${object.credentialOffer?.replace('credential_offer=', '')}`
123
- const value = object.credentialOffer ? credentialOffer : credentialOfferUri
124
- return `${url}${value}`
125
- }
126
- }
1
+ import { IAgentPlugin } from '@veramo/core'
2
+
3
+ import {
4
+ CreateElementArgs,
5
+ CreateValueArgs,
6
+ DIDCommV2OOBInvitationData,
7
+ IQRCodeGenerator,
8
+ IRequiredContext,
9
+ OpenID4VCIDataWithScheme,
10
+ QRType,
11
+ SIOPv2DataWithScheme,
12
+ URIData,
13
+ } from '../types/IQRCodeGenerator'
14
+ import { DidCommOutOfBandMessage, generateQRCodeReactElement } from './utils'
15
+ import { generateQRCodeReactElementImpl } from './utils/react-qr'
16
+
17
+ /**
18
+ * {@inheritDoc IQRCodeGenerator}
19
+ */
20
+ export class QrCodeProvider implements IAgentPlugin {
21
+ readonly methods: IQRCodeGenerator = {
22
+ qrDIDCommOobInvitationElement: QrCodeProvider.qrDIDCommOobInvitationElement.bind(this),
23
+ qrDIDCommOobInvitationValue: QrCodeProvider.qrDIDCommOobInvitationValue.bind(this),
24
+ qrSIOPv2Element: QrCodeProvider.qrSIOPv2Element.bind(this),
25
+ qrSIOPv2Value: QrCodeProvider.qrSIOPv2Value.bind(this),
26
+ qrURIElement: QrCodeProvider.qrURIElement.bind(this),
27
+ qrOpenID4VCIElement: QrCodeProvider.qrOpenID4VCIElement.bind(this),
28
+ qrOpenID4VCIValue: QrCodeProvider.qrOpenID4VCIValue.bind(this),
29
+ }
30
+
31
+ /** {@inheritDoc IQRCodeGenerator.uriElement} */
32
+
33
+ private static async qrURIElement(args: CreateElementArgs<QRType.URI, URIData>, context: IRequiredContext): Promise<JSX.Element> {
34
+ return generateQRCodeReactElement(args, context)
35
+ }
36
+
37
+ /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationValue} */
38
+ private static async qrDIDCommOobInvitationValue(
39
+ args: CreateValueArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
40
+ context: IRequiredContext,
41
+ ): Promise<string> {
42
+ const { object } = args.data
43
+ const encoded = DidCommOutOfBandMessage.urlEncode(object.oobInvitation)
44
+ const delim = object.baseURI.includes('?') ? '&' : '?'
45
+ return object.baseURI.includes('oob=') ? object.baseURI.replace('oob=', `oob=${encoded}`) : `${object.baseURI}${delim}_oob=${encoded}`
46
+ }
47
+
48
+ /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationElement} */
49
+ private static async qrDIDCommOobInvitationElement(
50
+ args: CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
51
+ context: IRequiredContext,
52
+ ): Promise<JSX.Element> {
53
+ const content = await QrCodeProvider.qrDIDCommOobInvitationValue(args, context)
54
+ return generateQRCodeReactElementImpl(
55
+ {
56
+ ...args,
57
+ data: { ...args.data, object: content },
58
+ } as CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, string>,
59
+ args,
60
+ context,
61
+ )
62
+ }
63
+
64
+ /** {@inheritDoc IQRCodeGenerator.siopv2Value} */
65
+ private static async qrSIOPv2Value(args: CreateValueArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<string> {
66
+ const { object } = args.data
67
+ if (typeof object === 'string') {
68
+ return object
69
+ }
70
+
71
+ const scheme = (object.scheme ?? 'openid-vc://').replace('://?', '').replace('://', '') + '://'
72
+ const requestUri = `request_uri=${object.requestUri.replace('request_uri=', '')}`
73
+ return `${scheme}?${requestUri}`
74
+ }
75
+
76
+ /** {@inheritDoc IQRCodeGenerator.siopv2Element} */
77
+ private static async qrSIOPv2Element(
78
+ args: CreateElementArgs<QRType.SIOPV2, SIOPv2DataWithScheme>,
79
+ context: IRequiredContext,
80
+ ): Promise<JSX.Element> {
81
+ const content = await QrCodeProvider.qrSIOPv2Value(args, context)
82
+ return generateQRCodeReactElementImpl(
83
+ { ...args, data: { ...args.data, object: content } } as CreateElementArgs<QRType.SIOPV2, string>,
84
+ args,
85
+ context,
86
+ )
87
+ }
88
+
89
+ /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIElement} */
90
+ private static async qrOpenID4VCIElement(args: CreateElementArgs<QRType.OpenID4VCI, any>, context: IRequiredContext): Promise<JSX.Element> {
91
+ const content = await QrCodeProvider.qrOpenID4VCIValue(args, context)
92
+ return generateQRCodeReactElementImpl(
93
+ { ...args, data: { ...args.data, object: content } } as CreateElementArgs<QRType.OpenID4VCI, string>,
94
+ args,
95
+ context,
96
+ )
97
+ }
98
+
99
+ /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIValue} */
100
+ private static async qrOpenID4VCIValue(
101
+ args: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>,
102
+ context: IRequiredContext,
103
+ ): Promise<string> {
104
+ const { object } = args.data
105
+ if (!object.credentialOffer && !object.credentialOfferUri) {
106
+ throw new Error('Please provide credential_offer or credential_offer_uri')
107
+ }
108
+ const scheme = (object.scheme ?? 'openid-credential-offer://').replace('://?', '').replace('://', '') + '://'
109
+ const baseUri = object.baseUri ?? ''
110
+ let url
111
+ const splitBaseUri = baseUri.split('://')
112
+ const hasScheme = splitBaseUri.length > 1
113
+ if (hasScheme && object.scheme) {
114
+ if (splitBaseUri[0] !== object.scheme) {
115
+ throw new Error('The uri must contain the same scheme or omit it')
116
+ }
117
+ url = `${baseUri}`
118
+ } else {
119
+ url = `${scheme}${baseUri}`
120
+ }
121
+ const credentialOfferUri = `?credential_offer_uri=${object.credentialOfferUri?.replace('credential_offer_uri=', '')}`
122
+ const credentialOffer = `?credential_offer=${object.credentialOffer?.replace('credential_offer=', '')}`
123
+ const value = object.credentialOffer ? credentialOffer : credentialOfferUri
124
+ return `${url}${value}`
125
+ }
126
+ }
@@ -1,58 +1,58 @@
1
- import { CreateElementArgs, CreateValueArgs, events, IRequiredContext, QRType, ValueResult } from '../../types/IQRCodeGenerator'
2
- import QRCode from 'react-qr-code'
3
- import React from 'react'
4
-
5
- export async function generateQRCodeValue<T extends QRType>(
6
- args: CreateValueArgs<T, string> | CreateElementArgs<T, string>,
7
- context?: IRequiredContext,
8
- ): Promise<ValueResult<T, string>> {
9
- return generateQRCodeValueImpl(args, args, context)
10
- }
11
-
12
- export async function generateQRCodeValueImpl<T extends QRType>(
13
- args: CreateValueArgs<T, string> | CreateElementArgs<T, string>,
14
- orig: CreateValueArgs<T, any> | CreateElementArgs<T, any>,
15
- context?: IRequiredContext,
16
- ): Promise<ValueResult<T, string>> {
17
- const { onGenerate } = orig
18
- const { id } = orig.data
19
-
20
- const value = args.data.object
21
-
22
- const result: ValueResult<T, string> = {
23
- id,
24
- value,
25
- data: orig.data,
26
- renderingProps: 'renderingProps' in orig ? orig.renderingProps : undefined,
27
- context,
28
- }
29
-
30
- if (onGenerate) {
31
- onGenerate(result)
32
- }
33
- if (context) {
34
- context.agent.emit(events.QR_CODE_CODE_CREATED, result)
35
- }
36
-
37
- return result
38
- }
39
-
40
- export async function generateQRCodeReactElement<T extends QRType>(
41
- args: CreateElementArgs<T, string>,
42
- context: IRequiredContext,
43
- ): Promise<JSX.Element> {
44
- return generateQRCodeReactElementImpl(args, args, context)
45
- }
46
-
47
- export async function generateQRCodeReactElementImpl<T extends QRType>(
48
- args: CreateElementArgs<T, string>,
49
- orig: CreateElementArgs<T, any>,
50
- context: IRequiredContext,
51
- ): Promise<JSX.Element> {
52
- const { renderingProps } = args
53
- const { bgColor, fgColor, level, size, title } = renderingProps
54
- const result: ValueResult<T, string> = await generateQRCodeValueImpl(args, orig, context)
55
-
56
- // @ts-ignore
57
- return <QRCode value={result.value} bgColor={bgColor} fgColor={fgColor} level={level} size={size} title={title} />
58
- }
1
+ import { CreateElementArgs, CreateValueArgs, events, IRequiredContext, QRType, ValueResult } from '../../types/IQRCodeGenerator'
2
+ import QRCode from 'react-qr-code'
3
+ import React from 'react'
4
+
5
+ export async function generateQRCodeValue<T extends QRType>(
6
+ args: CreateValueArgs<T, string> | CreateElementArgs<T, string>,
7
+ context?: IRequiredContext,
8
+ ): Promise<ValueResult<T, string>> {
9
+ return generateQRCodeValueImpl(args, args, context)
10
+ }
11
+
12
+ export async function generateQRCodeValueImpl<T extends QRType>(
13
+ args: CreateValueArgs<T, string> | CreateElementArgs<T, string>,
14
+ orig: CreateValueArgs<T, any> | CreateElementArgs<T, any>,
15
+ context?: IRequiredContext,
16
+ ): Promise<ValueResult<T, string>> {
17
+ const { onGenerate } = orig
18
+ const { id } = orig.data
19
+
20
+ const value = args.data.object
21
+
22
+ const result: ValueResult<T, string> = {
23
+ id,
24
+ value,
25
+ data: orig.data,
26
+ renderingProps: 'renderingProps' in orig ? orig.renderingProps : undefined,
27
+ context,
28
+ }
29
+
30
+ if (onGenerate) {
31
+ onGenerate(result)
32
+ }
33
+ if (context) {
34
+ context.agent.emit(events.QR_CODE_CODE_CREATED, result)
35
+ }
36
+
37
+ return result
38
+ }
39
+
40
+ export async function generateQRCodeReactElement<T extends QRType>(
41
+ args: CreateElementArgs<T, string>,
42
+ context: IRequiredContext,
43
+ ): Promise<JSX.Element> {
44
+ return generateQRCodeReactElementImpl(args, args, context)
45
+ }
46
+
47
+ export async function generateQRCodeReactElementImpl<T extends QRType>(
48
+ args: CreateElementArgs<T, string>,
49
+ orig: CreateElementArgs<T, any>,
50
+ context: IRequiredContext,
51
+ ): Promise<JSX.Element> {
52
+ const { renderingProps } = args
53
+ const { bgColor, fgColor, level, size, title } = renderingProps
54
+ const result: ValueResult<T, string> = await generateQRCodeValueImpl(args, orig, context)
55
+
56
+ // @ts-ignore
57
+ return <QRCode value={result.value} bgColor={bgColor} fgColor={fgColor} level={level} size={size} title={title} />
58
+ }
@@ -1,126 +1,126 @@
1
- import { IAgentContext, IPluginMethodMap } from '@veramo/core'
2
-
3
- export interface IQRCodeGenerator extends IPluginMethodMap {
4
- qrDIDCommOobInvitationElement(
5
- args: CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
6
- context: IRequiredContext,
7
- ): Promise<JSX.Element>
8
-
9
- qrDIDCommOobInvitationValue(
10
- args: CreateValueArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
11
- context: IRequiredContext,
12
- ): Promise<string>
13
-
14
- qrSIOPv2Element(args: CreateElementArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<JSX.Element>
15
-
16
- qrSIOPv2Value(args: CreateValueArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<string>
17
-
18
- qrURIElement(args: CreateElementArgs<QRType.URI, URIData>, context: IRequiredContext): Promise<JSX.Element>
19
-
20
- qrOpenID4VCIElement(args: CreateElementArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<JSX.Element>
21
- qrOpenID4VCIValue(args: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<string>
22
- }
23
-
24
- export interface CreateValueArgs<T extends QRType, D> {
25
- onGenerate?: (result: ValueResult<T, D>) => void
26
- data: QRData<T, D>
27
- }
28
-
29
- export interface CreateElementArgs<T extends QRType, D> extends CreateValueArgs<T, D> {
30
- renderingProps: QRRenderingProps
31
- }
32
-
33
- export interface ValueResult<T extends QRType, D> {
34
- id: string
35
- value: string
36
- data: QRData<T, D>
37
- renderingProps?: QRRenderingProps
38
- context?: IRequiredContext
39
- }
40
-
41
- export enum QRType {
42
- URI = 'uri',
43
- SIOPV2 = 'openid-vc',
44
- DIDCOMM_V2_OOB_INVITATION = 'https://didcomm.org/out-of-band/2.0/invitation',
45
- OpenID4VCI = 'openid-credential-offer',
46
- }
47
-
48
- export type SIOPv2Scheme = 'openid' | 'openid-vc' | string
49
- export interface SIOPv2DataWithScheme {
50
- scheme?: SIOPv2Scheme
51
- requestUri: string
52
- }
53
-
54
- export type OpenID4VCIScheme = 'openid-credential-offer' | 'https' | string
55
- export interface OpenID4VCIDataWithScheme {
56
- scheme?: OpenID4VCIScheme
57
- baseUri?: string
58
- credentialOfferUri?: string
59
- credentialOffer?: string
60
- }
61
-
62
- export interface DIDCommV2OOBInvitationData {
63
- baseURI: string
64
- oobInvitation: DIDCommV2OOBInvitation
65
- }
66
-
67
- /**
68
- * {
69
- * "type": "https://didcomm.org/out-of-band/2.0/invitation",
70
- * "id": "599f3638-b563-4937-9487-dfe55099d900",
71
- * "from": "did:example:verifier",
72
- * "body": {
73
- * "goal_code": "streamlined-vp",
74
- * "accept": ['didcomm/v2']
75
- * }
76
- * }
77
- */
78
- export interface DIDCommV2OOBInvitation {
79
- type: 'https://didcomm.org/out-of-band/2.0/invitation'
80
- id: string
81
- from: DID
82
-
83
- body: Body
84
- }
85
-
86
- export type URIData = string
87
-
88
- export type DID = string
89
-
90
- export interface Body {
91
- goal_code: GoalCode
92
- accept: [AcceptMode]
93
- }
94
-
95
- export type GoalCode = 'streamlined-vp' | 'streamlined-vc'
96
-
97
- export type AcceptMode = 'didcomm/v2' | string
98
-
99
- /*OIDC4VP = 'oidc4vp',
100
- SIOPV2_WITH_OIDC4VP = 'siopv2+oidc4vp',
101
- SIOP_V2 = 'siopv2',*/
102
-
103
- export enum StatusCode {
104
- OK = 'OK',
105
- CREATED = 'CREATED',
106
- }
107
-
108
- export interface QRData<T extends QRType, D> {
109
- id: string
110
- type: T
111
- object: D
112
- }
113
-
114
- export interface QRRenderingProps {
115
- bgColor?: string
116
- fgColor?: string
117
- level?: 'L' | 'M' | 'Q' | 'H'
118
- size?: number
119
- title?: string
120
- }
121
-
122
- export enum events {
123
- QR_CODE_CODE_CREATED = 'QrCodeCreated',
124
- }
125
-
126
- export type IRequiredContext = IAgentContext<Record<string, never>>
1
+ import { IAgentContext, IPluginMethodMap } from '@veramo/core'
2
+
3
+ export interface IQRCodeGenerator extends IPluginMethodMap {
4
+ qrDIDCommOobInvitationElement(
5
+ args: CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
6
+ context: IRequiredContext,
7
+ ): Promise<JSX.Element>
8
+
9
+ qrDIDCommOobInvitationValue(
10
+ args: CreateValueArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>,
11
+ context: IRequiredContext,
12
+ ): Promise<string>
13
+
14
+ qrSIOPv2Element(args: CreateElementArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<JSX.Element>
15
+
16
+ qrSIOPv2Value(args: CreateValueArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<string>
17
+
18
+ qrURIElement(args: CreateElementArgs<QRType.URI, URIData>, context: IRequiredContext): Promise<JSX.Element>
19
+
20
+ qrOpenID4VCIElement(args: CreateElementArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<JSX.Element>
21
+ qrOpenID4VCIValue(args: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<string>
22
+ }
23
+
24
+ export interface CreateValueArgs<T extends QRType, D> {
25
+ onGenerate?: (result: ValueResult<T, D>) => void
26
+ data: QRData<T, D>
27
+ }
28
+
29
+ export interface CreateElementArgs<T extends QRType, D> extends CreateValueArgs<T, D> {
30
+ renderingProps: QRRenderingProps
31
+ }
32
+
33
+ export interface ValueResult<T extends QRType, D> {
34
+ id: string
35
+ value: string
36
+ data: QRData<T, D>
37
+ renderingProps?: QRRenderingProps
38
+ context?: IRequiredContext
39
+ }
40
+
41
+ export enum QRType {
42
+ URI = 'uri',
43
+ SIOPV2 = 'openid-vc',
44
+ DIDCOMM_V2_OOB_INVITATION = 'https://didcomm.org/out-of-band/2.0/invitation',
45
+ OpenID4VCI = 'openid-credential-offer',
46
+ }
47
+
48
+ export type SIOPv2Scheme = 'openid' | 'openid-vc' | string
49
+ export interface SIOPv2DataWithScheme {
50
+ scheme?: SIOPv2Scheme
51
+ requestUri: string
52
+ }
53
+
54
+ export type OpenID4VCIScheme = 'openid-credential-offer' | 'https' | string
55
+ export interface OpenID4VCIDataWithScheme {
56
+ scheme?: OpenID4VCIScheme
57
+ baseUri?: string
58
+ credentialOfferUri?: string
59
+ credentialOffer?: string
60
+ }
61
+
62
+ export interface DIDCommV2OOBInvitationData {
63
+ baseURI: string
64
+ oobInvitation: DIDCommV2OOBInvitation
65
+ }
66
+
67
+ /**
68
+ * {
69
+ * "type": "https://didcomm.org/out-of-band/2.0/invitation",
70
+ * "id": "599f3638-b563-4937-9487-dfe55099d900",
71
+ * "from": "did:example:verifier",
72
+ * "body": {
73
+ * "goal_code": "streamlined-vp",
74
+ * "accept": ['didcomm/v2']
75
+ * }
76
+ * }
77
+ */
78
+ export interface DIDCommV2OOBInvitation {
79
+ type: 'https://didcomm.org/out-of-band/2.0/invitation'
80
+ id: string
81
+ from: DID
82
+
83
+ body: Body
84
+ }
85
+
86
+ export type URIData = string
87
+
88
+ export type DID = string
89
+
90
+ export interface Body {
91
+ goal_code: GoalCode
92
+ accept: [AcceptMode]
93
+ }
94
+
95
+ export type GoalCode = 'streamlined-vp' | 'streamlined-vc'
96
+
97
+ export type AcceptMode = 'didcomm/v2' | string
98
+
99
+ /*OIDC4VP = 'oidc4vp',
100
+ SIOPV2_WITH_OIDC4VP = 'siopv2+oidc4vp',
101
+ SIOP_V2 = 'siopv2',*/
102
+
103
+ export enum StatusCode {
104
+ OK = 'OK',
105
+ CREATED = 'CREATED',
106
+ }
107
+
108
+ export interface QRData<T extends QRType, D> {
109
+ id: string
110
+ type: T
111
+ object: D
112
+ }
113
+
114
+ export interface QRRenderingProps {
115
+ bgColor?: string
116
+ fgColor?: string
117
+ level?: 'L' | 'M' | 'Q' | 'H'
118
+ size?: number
119
+ title?: string
120
+ }
121
+
122
+ export enum events {
123
+ QR_CODE_CODE_CREATED = 'QrCodeCreated',
124
+ }
125
+
126
+ export type IRequiredContext = IAgentContext<Record<string, never>>