@sphereon/ssi-sdk.qr-code-generator 0.30.1-unstable.4 → 0.30.1
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/dist/agent/QrCodeProvider.d.ts +22 -22
- package/dist/agent/QrCodeProvider.js +108 -108
- package/dist/agent/QrCodeProvider.js.map +1 -1
- package/dist/agent/utils/didcomm-oob-message.d.ts +5 -5
- package/dist/agent/utils/didcomm-oob-message.js +16 -16
- package/dist/agent/utils/index.d.ts +2 -2
- package/dist/agent/utils/index.js +21 -21
- package/dist/agent/utils/react-qr.d.ts +6 -6
- package/dist/agent/utils/react-qr.js +62 -62
- package/dist/agent/utils/react-qr.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -21
- package/dist/types/IQRCodeGenerator.d.ts +92 -92
- package/dist/types/IQRCodeGenerator.js +22 -22
- package/dist/types/IQRCodeGenerator.js.map +1 -1
- package/package.json +3 -3
- package/src/agent/QrCodeProvider.tsx +126 -126
- package/src/agent/utils/react-qr.tsx +58 -58
- package/src/types/IQRCodeGenerator.ts +126 -126
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { IAgentContext, IPluginMethodMap } from '@veramo/core';
|
|
3
|
-
export interface IQRCodeGenerator extends IPluginMethodMap {
|
|
4
|
-
qrDIDCommOobInvitationElement(args: CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>, context: IRequiredContext): Promise<JSX.Element>;
|
|
5
|
-
qrDIDCommOobInvitationValue(args: CreateValueArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>, context: IRequiredContext): Promise<string>;
|
|
6
|
-
qrSIOPv2Element(args: CreateElementArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<JSX.Element>;
|
|
7
|
-
qrSIOPv2Value(args: CreateValueArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<string>;
|
|
8
|
-
qrURIElement(args: CreateElementArgs<QRType.URI, URIData>, context: IRequiredContext): Promise<JSX.Element>;
|
|
9
|
-
qrOpenID4VCIElement(args: CreateElementArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<JSX.Element>;
|
|
10
|
-
qrOpenID4VCIValue(args: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<string>;
|
|
11
|
-
}
|
|
12
|
-
export interface CreateValueArgs<T extends QRType, D> {
|
|
13
|
-
onGenerate?: (result: ValueResult<T, D>) => void;
|
|
14
|
-
data: QRData<T, D>;
|
|
15
|
-
}
|
|
16
|
-
export interface CreateElementArgs<T extends QRType, D> extends CreateValueArgs<T, D> {
|
|
17
|
-
renderingProps: QRRenderingProps;
|
|
18
|
-
}
|
|
19
|
-
export interface ValueResult<T extends QRType, D> {
|
|
20
|
-
id: string;
|
|
21
|
-
value: string;
|
|
22
|
-
data: QRData<T, D>;
|
|
23
|
-
renderingProps?: QRRenderingProps;
|
|
24
|
-
context?: IRequiredContext;
|
|
25
|
-
}
|
|
26
|
-
export declare enum QRType {
|
|
27
|
-
URI = "uri",
|
|
28
|
-
SIOPV2 = "openid-vc",
|
|
29
|
-
DIDCOMM_V2_OOB_INVITATION = "https://didcomm.org/out-of-band/2.0/invitation",
|
|
30
|
-
OpenID4VCI = "openid-credential-offer"
|
|
31
|
-
}
|
|
32
|
-
export type SIOPv2Scheme = 'openid' | 'openid-vc' | string;
|
|
33
|
-
export interface SIOPv2DataWithScheme {
|
|
34
|
-
scheme?: SIOPv2Scheme;
|
|
35
|
-
requestUri: string;
|
|
36
|
-
}
|
|
37
|
-
export type OpenID4VCIScheme = 'openid-credential-offer' | 'https' | string;
|
|
38
|
-
export interface OpenID4VCIDataWithScheme {
|
|
39
|
-
scheme?: OpenID4VCIScheme;
|
|
40
|
-
baseUri?: string;
|
|
41
|
-
credentialOfferUri?: string;
|
|
42
|
-
credentialOffer?: string;
|
|
43
|
-
}
|
|
44
|
-
export interface DIDCommV2OOBInvitationData {
|
|
45
|
-
baseURI: string;
|
|
46
|
-
oobInvitation: DIDCommV2OOBInvitation;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* {
|
|
50
|
-
* "type": "https://didcomm.org/out-of-band/2.0/invitation",
|
|
51
|
-
* "id": "599f3638-b563-4937-9487-dfe55099d900",
|
|
52
|
-
* "from": "did:example:verifier",
|
|
53
|
-
* "body": {
|
|
54
|
-
* "goal_code": "streamlined-vp",
|
|
55
|
-
* "accept": ['didcomm/v2']
|
|
56
|
-
* }
|
|
57
|
-
* }
|
|
58
|
-
*/
|
|
59
|
-
export interface DIDCommV2OOBInvitation {
|
|
60
|
-
type: 'https://didcomm.org/out-of-band/2.0/invitation';
|
|
61
|
-
id: string;
|
|
62
|
-
from: DID;
|
|
63
|
-
body: Body;
|
|
64
|
-
}
|
|
65
|
-
export type URIData = string;
|
|
66
|
-
export type DID = string;
|
|
67
|
-
export interface Body {
|
|
68
|
-
goal_code: GoalCode;
|
|
69
|
-
accept: [AcceptMode];
|
|
70
|
-
}
|
|
71
|
-
export type GoalCode = 'streamlined-vp' | 'streamlined-vc';
|
|
72
|
-
export type AcceptMode = 'didcomm/v2' | string;
|
|
73
|
-
export declare enum StatusCode {
|
|
74
|
-
OK = "OK",
|
|
75
|
-
CREATED = "CREATED"
|
|
76
|
-
}
|
|
77
|
-
export interface QRData<T extends QRType, D> {
|
|
78
|
-
id: string;
|
|
79
|
-
type: T;
|
|
80
|
-
object: D;
|
|
81
|
-
}
|
|
82
|
-
export interface QRRenderingProps {
|
|
83
|
-
bgColor?: string;
|
|
84
|
-
fgColor?: string;
|
|
85
|
-
level?: 'L' | 'M' | 'Q' | 'H';
|
|
86
|
-
size?: number;
|
|
87
|
-
title?: string;
|
|
88
|
-
}
|
|
89
|
-
export declare enum events {
|
|
90
|
-
QR_CODE_CODE_CREATED = "QrCodeCreated"
|
|
91
|
-
}
|
|
92
|
-
export type IRequiredContext = IAgentContext<Record<string, never>>;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IAgentContext, IPluginMethodMap } from '@veramo/core';
|
|
3
|
+
export interface IQRCodeGenerator extends IPluginMethodMap {
|
|
4
|
+
qrDIDCommOobInvitationElement(args: CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>, context: IRequiredContext): Promise<JSX.Element>;
|
|
5
|
+
qrDIDCommOobInvitationValue(args: CreateValueArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>, context: IRequiredContext): Promise<string>;
|
|
6
|
+
qrSIOPv2Element(args: CreateElementArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<JSX.Element>;
|
|
7
|
+
qrSIOPv2Value(args: CreateValueArgs<QRType.SIOPV2, SIOPv2DataWithScheme>, context: IRequiredContext): Promise<string>;
|
|
8
|
+
qrURIElement(args: CreateElementArgs<QRType.URI, URIData>, context: IRequiredContext): Promise<JSX.Element>;
|
|
9
|
+
qrOpenID4VCIElement(args: CreateElementArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<JSX.Element>;
|
|
10
|
+
qrOpenID4VCIValue(args: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>, context: IRequiredContext): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateValueArgs<T extends QRType, D> {
|
|
13
|
+
onGenerate?: (result: ValueResult<T, D>) => void;
|
|
14
|
+
data: QRData<T, D>;
|
|
15
|
+
}
|
|
16
|
+
export interface CreateElementArgs<T extends QRType, D> extends CreateValueArgs<T, D> {
|
|
17
|
+
renderingProps: QRRenderingProps;
|
|
18
|
+
}
|
|
19
|
+
export interface ValueResult<T extends QRType, D> {
|
|
20
|
+
id: string;
|
|
21
|
+
value: string;
|
|
22
|
+
data: QRData<T, D>;
|
|
23
|
+
renderingProps?: QRRenderingProps;
|
|
24
|
+
context?: IRequiredContext;
|
|
25
|
+
}
|
|
26
|
+
export declare enum QRType {
|
|
27
|
+
URI = "uri",
|
|
28
|
+
SIOPV2 = "openid-vc",
|
|
29
|
+
DIDCOMM_V2_OOB_INVITATION = "https://didcomm.org/out-of-band/2.0/invitation",
|
|
30
|
+
OpenID4VCI = "openid-credential-offer"
|
|
31
|
+
}
|
|
32
|
+
export type SIOPv2Scheme = 'openid' | 'openid-vc' | string;
|
|
33
|
+
export interface SIOPv2DataWithScheme {
|
|
34
|
+
scheme?: SIOPv2Scheme;
|
|
35
|
+
requestUri: string;
|
|
36
|
+
}
|
|
37
|
+
export type OpenID4VCIScheme = 'openid-credential-offer' | 'https' | string;
|
|
38
|
+
export interface OpenID4VCIDataWithScheme {
|
|
39
|
+
scheme?: OpenID4VCIScheme;
|
|
40
|
+
baseUri?: string;
|
|
41
|
+
credentialOfferUri?: string;
|
|
42
|
+
credentialOffer?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface DIDCommV2OOBInvitationData {
|
|
45
|
+
baseURI: string;
|
|
46
|
+
oobInvitation: DIDCommV2OOBInvitation;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* {
|
|
50
|
+
* "type": "https://didcomm.org/out-of-band/2.0/invitation",
|
|
51
|
+
* "id": "599f3638-b563-4937-9487-dfe55099d900",
|
|
52
|
+
* "from": "did:example:verifier",
|
|
53
|
+
* "body": {
|
|
54
|
+
* "goal_code": "streamlined-vp",
|
|
55
|
+
* "accept": ['didcomm/v2']
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
*/
|
|
59
|
+
export interface DIDCommV2OOBInvitation {
|
|
60
|
+
type: 'https://didcomm.org/out-of-band/2.0/invitation';
|
|
61
|
+
id: string;
|
|
62
|
+
from: DID;
|
|
63
|
+
body: Body;
|
|
64
|
+
}
|
|
65
|
+
export type URIData = string;
|
|
66
|
+
export type DID = string;
|
|
67
|
+
export interface Body {
|
|
68
|
+
goal_code: GoalCode;
|
|
69
|
+
accept: [AcceptMode];
|
|
70
|
+
}
|
|
71
|
+
export type GoalCode = 'streamlined-vp' | 'streamlined-vc';
|
|
72
|
+
export type AcceptMode = 'didcomm/v2' | string;
|
|
73
|
+
export declare enum StatusCode {
|
|
74
|
+
OK = "OK",
|
|
75
|
+
CREATED = "CREATED"
|
|
76
|
+
}
|
|
77
|
+
export interface QRData<T extends QRType, D> {
|
|
78
|
+
id: string;
|
|
79
|
+
type: T;
|
|
80
|
+
object: D;
|
|
81
|
+
}
|
|
82
|
+
export interface QRRenderingProps {
|
|
83
|
+
bgColor?: string;
|
|
84
|
+
fgColor?: string;
|
|
85
|
+
level?: 'L' | 'M' | 'Q' | 'H';
|
|
86
|
+
size?: number;
|
|
87
|
+
title?: string;
|
|
88
|
+
}
|
|
89
|
+
export declare enum events {
|
|
90
|
+
QR_CODE_CODE_CREATED = "QrCodeCreated"
|
|
91
|
+
}
|
|
92
|
+
export type IRequiredContext = IAgentContext<Record<string, never>>;
|
|
93
93
|
//# sourceMappingURL=IQRCodeGenerator.d.ts.map
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.events = exports.StatusCode = exports.QRType = void 0;
|
|
4
|
-
var QRType;
|
|
5
|
-
(function (QRType) {
|
|
6
|
-
QRType["URI"] = "uri";
|
|
7
|
-
QRType["SIOPV2"] = "openid-vc";
|
|
8
|
-
QRType["DIDCOMM_V2_OOB_INVITATION"] = "https://didcomm.org/out-of-band/2.0/invitation";
|
|
9
|
-
QRType["OpenID4VCI"] = "openid-credential-offer";
|
|
10
|
-
})(QRType
|
|
11
|
-
/*OIDC4VP = 'oidc4vp',
|
|
12
|
-
SIOPV2_WITH_OIDC4VP = 'siopv2+oidc4vp',
|
|
13
|
-
SIOP_V2 = 'siopv2',*/
|
|
14
|
-
var StatusCode;
|
|
15
|
-
(function (StatusCode) {
|
|
16
|
-
StatusCode["OK"] = "OK";
|
|
17
|
-
StatusCode["CREATED"] = "CREATED";
|
|
18
|
-
})(StatusCode
|
|
19
|
-
var events;
|
|
20
|
-
(function (events) {
|
|
21
|
-
events["QR_CODE_CODE_CREATED"] = "QrCodeCreated";
|
|
22
|
-
})(events
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.events = exports.StatusCode = exports.QRType = void 0;
|
|
4
|
+
var QRType;
|
|
5
|
+
(function (QRType) {
|
|
6
|
+
QRType["URI"] = "uri";
|
|
7
|
+
QRType["SIOPV2"] = "openid-vc";
|
|
8
|
+
QRType["DIDCOMM_V2_OOB_INVITATION"] = "https://didcomm.org/out-of-band/2.0/invitation";
|
|
9
|
+
QRType["OpenID4VCI"] = "openid-credential-offer";
|
|
10
|
+
})(QRType || (exports.QRType = QRType = {}));
|
|
11
|
+
/*OIDC4VP = 'oidc4vp',
|
|
12
|
+
SIOPV2_WITH_OIDC4VP = 'siopv2+oidc4vp',
|
|
13
|
+
SIOP_V2 = 'siopv2',*/
|
|
14
|
+
var StatusCode;
|
|
15
|
+
(function (StatusCode) {
|
|
16
|
+
StatusCode["OK"] = "OK";
|
|
17
|
+
StatusCode["CREATED"] = "CREATED";
|
|
18
|
+
})(StatusCode || (exports.StatusCode = StatusCode = {}));
|
|
19
|
+
var events;
|
|
20
|
+
(function (events) {
|
|
21
|
+
events["QR_CODE_CODE_CREATED"] = "QrCodeCreated";
|
|
22
|
+
})(events || (exports.events = events = {}));
|
|
23
23
|
//# sourceMappingURL=IQRCodeGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IQRCodeGenerator.js","sourceRoot":"","sources":["../../src/types/IQRCodeGenerator.ts"],"names":[],"mappings":";;;AAwCA,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,8BAAoB,CAAA;IACpB,sFAA4E,CAAA;IAC5E,gDAAsC,CAAA;AACxC,CAAC,EALW,MAAM,
|
|
1
|
+
{"version":3,"file":"IQRCodeGenerator.js","sourceRoot":"","sources":["../../src/types/IQRCodeGenerator.ts"],"names":[],"mappings":";;;AAwCA,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,8BAAoB,CAAA;IACpB,sFAA4E,CAAA;IAC5E,gDAAsC,CAAA;AACxC,CAAC,EALW,MAAM,sBAAN,MAAM,QAKjB;AAqDD;;qBAEqB;AAErB,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,uBAAS,CAAA;IACT,iCAAmB,CAAA;AACrB,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AAgBD,IAAY,MAEX;AAFD,WAAY,MAAM;IAChB,gDAAsC,CAAA;AACxC,CAAC,EAFW,MAAM,sBAAN,MAAM,QAEjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.qr-code-generator",
|
|
3
|
-
"version": "0.30.1
|
|
3
|
+
"version": "0.30.1",
|
|
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
|
|
25
|
+
"@sphereon/ssi-sdk.agent-config": "0.30.1",
|
|
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": "
|
|
61
|
+
"gitHead": "c41d295c136cc35d7be3ea650fc610cf05aaf1a3"
|
|
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
|
+
}
|