@sphereon/ssi-sdk.qr-code-generator 0.11.1-next.65

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2022] [Sphereon BV, info@sphereon.com]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ <!--suppress HtmlDeprecatedAttribute -->
2
+ <h1 align="center">
3
+ <br>
4
+ <a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a>
5
+ <br>qr-code-generator (Typescript)
6
+ <br>
7
+ </h1>
8
+
9
+ # qr-code-generator
10
+
11
+ A `Sphereon SSI-SDK` plugin to create an QR codes for `SIOPv2/OpenID4VP`, `DIDCommv2` and `OpenID4VCI`.
12
+ Next to the above specific QR types, of course you can also generate generic QR codes with this package.
13
+
14
+ It is tailored towards React and React-Native but also provides textual representations.
15
+
16
+ ### Installation
17
+
18
+ ```shell
19
+ yarn add @sphereon/ssi-sdk.qr-code-generator
20
+ ```
21
+
22
+ ### Build
23
+
24
+ ```shell
25
+ yarn build
26
+ ```
27
+
28
+ ### Usage
29
+
30
+ The usage scenario will include the plugin code to be integrated in the client code. A party will be requesting the
31
+ recipient to either:
32
+
33
+ 1. authenticate itself to the requester
34
+ 2. inviting the issuer to issue a credential
35
+
36
+ #### Importing the plugin
37
+
38
+ ```typescript
39
+ import { QrCodeProvider } from '@sphereon/ssi-sdk.qr-code-generator'
40
+
41
+ // Include in the interface
42
+ // const agent = createAgent<... QrCodeProvider>
43
+ ```
44
+
45
+ #### Adding plugin to the agent
46
+
47
+ ```typescript
48
+ plugins: [...new QrCodeProvider()]
49
+ ```
50
+
51
+ #### Inside the component we can declare or get the values to pass to QR Code plugin
52
+
53
+ ```typescript
54
+ import { WaciOobProps } from '@sphereon/ssi-sdk.qr-code-generator'
55
+
56
+ function getOobQrCodeProps(): QRRenderingProps {
57
+ return {
58
+ baseUrl: 'https://example.com/?oob=',
59
+ type: QRType.SIOPV2,
60
+ id: '599f3638-b563-4937-9487-dfe55099d900',
61
+ from: 'did:key:zrfdjkgfjgfdjk',
62
+ object: {
63
+ goalCode: GoalCode.STREAMLINED_VP,
64
+ accept: [AcceptMode.SIOPV2_WITH_OIDC4VP],
65
+ },
66
+ onGenerate: (oobQRProps: QRRenderingProps, payload: WaciOobProps) => {
67
+ console.log(payload)
68
+ },
69
+ bgColor: 'white',
70
+ fgColor: 'black',
71
+ level: 'L',
72
+ size: 128,
73
+ title: 'title2021120903',
74
+ }
75
+ }
76
+
77
+ delegateCreateOobQRCode = () => {
78
+ let qrCode = createQrCode(this.getOobQrCodeProps())
79
+ return qrCode.then((qrCodeResolved) => {
80
+ return qrCodeResolved
81
+ })
82
+ }
83
+ ```
84
+
85
+ On generate gives the following (example) output
86
+
87
+ ```json lines
88
+ {
89
+ "type": "openid",
90
+ "id": "599f3638-b563-4937-9487-dfe55099d900",
91
+ "from": "did:key:zrfdjkgfjgfdjk",
92
+ "object": {
93
+ "goal-code": "streamlined-vp",
94
+ "accept": ["siopv2+oidc4vp"]
95
+ }
96
+ }
97
+ ```
98
+
99
+ If you want to create the payload manually and want to do serialization yourself you can use:
100
+
101
+ ```typescript
102
+ const payload = DidCommOutOfBandMessage.createPayload(getOobQrCodeProps())
103
+ const encoded = DidCommOutOfBandMessage.urlEncode(payload)
104
+ const url = oobQRProps.baseUrl + encoded
105
+ console.log(url) // https://example.com/?oob=eyJ0eXBlIjoic2lvcHYyIiwiaWQiOiI1OTlmMzYzOC1iNTYzLTQ5MzctOTQ4Ny1kZmU1NTA5OWQ5MDAiLCJmcm9tIjoiZGlkOmtleTp6cmZkamtnZmpnZmRqayIsImJvZHkiOnsiZ29hbC1jb2RlIjoic3RyZWFtbGluZWQtdnAiLCJhY2NlcHQiOlsic2lvcHYyK29pZGM0dnAiXX19
106
+ ```
107
+
108
+ #### For rendering add to the view
109
+
110
+ ```jsx
111
+ <View>
112
+ //...
113
+ {this.delegateCreateOobQRCode()}
114
+ </View>
115
+ ```
116
+
117
+ ### OpenID4VCI example:
118
+
119
+ This is the credential offer
120
+
121
+ ```typescript
122
+ export const credentialOffer = JSON.stringify({
123
+ credential_issuer: 'https://credential-issuer.example.com',
124
+ credentials: [
125
+ 'UniversityDegree_JWT',
126
+ {
127
+ format: 'mso_mdoc',
128
+ doctype: 'org.iso.18013.5.1.mDL',
129
+ },
130
+ ],
131
+ grants: {
132
+ authorization_code: {
133
+ issuer_state: 'eyJhbGciOiJSU0Et...FYUaBy',
134
+ },
135
+ 'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
136
+ 'pre-authorized_code': 'adhjhdjajkdkhjhdj',
137
+ user_pin_required: true,
138
+ },
139
+ },
140
+ })
141
+ ```
142
+
143
+ It needs to be assigned to the credentialOffer field in the data scheme. The same can be
144
+ done using a reference, this will require to use the credentialOfferUri property and assign
145
+ the uri of the credential offer to it. Notice that the scheme defaults to `openid-credential-offer`
146
+ and baseUri is optional.
147
+
148
+ ```typescript
149
+ const openid4vcObjectValue: OpenID4VCIDataWithScheme = {
150
+ scheme: 'https',
151
+ baseUri: 'test.com/credential-offer',
152
+ credentialOffer,
153
+ }
154
+ ```
155
+
156
+ Now the data scheme needs to be added to the QR code data
157
+
158
+ ```typescript
159
+ const openid4vciDataValue: QRData<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
160
+ object: openid4vcObjectValue,
161
+ type: QRType.OpenID4VCI,
162
+ id: '568',
163
+ }
164
+ ```
165
+
166
+ So the QR code can be generated
167
+
168
+ ```typescript
169
+ export const openid4vciCreateValue: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
170
+ data: openid4vciDataValue,
171
+ onGenerate: (result: ValueResult<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>) => {
172
+ console.log(result, null, 2)
173
+ },
174
+ }
175
+ ```
176
+
177
+ And eventually added to an app
178
+
179
+ ```typescript
180
+ export const openid4vciCreateElement: CreateElementArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
181
+ data: openid4vciDataValue,
182
+ renderingProps,
183
+ onGenerate: (result: ValueResult<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>) => {
184
+ render(<div data-testid="test-div-openid4vci">{result.data.object.credentialOffer}</div>)
185
+ console.log(result.value)
186
+ },
187
+ }
188
+ ```
@@ -0,0 +1,23 @@
1
+ import { IAgentPlugin } from '@veramo/core';
2
+ import { IQRCodeGenerator } from '../types/IQRCodeGenerator';
3
+ /**
4
+ * {@inheritDoc IQRCodeGenerator}
5
+ */
6
+ export declare class QrCodeProvider implements IAgentPlugin {
7
+ readonly methods: IQRCodeGenerator;
8
+ /** {@inheritDoc IQRCodeGenerator.uriElement} */
9
+ private static qrURIElement;
10
+ /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationValue} */
11
+ private static qrDIDCommOobInvitationValue;
12
+ /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationElement} */
13
+ private static qrDIDCommOobInvitationElement;
14
+ /** {@inheritDoc IQRCodeGenerator.siopv2Value} */
15
+ private static qrSIOPv2Value;
16
+ /** {@inheritDoc IQRCodeGenerator.siopv2Element} */
17
+ private static qrSIOPv2Element;
18
+ /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIElement} */
19
+ private static qrOpenID4VCIElement;
20
+ /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIValue} */
21
+ private static qrOpenID4VCIValue;
22
+ }
23
+ //# sourceMappingURL=QrCodeProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QrCodeProvider.d.ts","sourceRoot":"","sources":["../../src/agent/QrCodeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAIL,gBAAgB,EAMjB,MAAM,2BAA2B,CAAA;AAIlC;;GAEG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAQjC;IAED,gDAAgD;mBAE3B,YAAY;IAIjC,+DAA+D;mBAC1C,2BAA2B;IAUhD,iEAAiE;mBAC5C,6BAA6B;IAelD,iDAAiD;mBAC5B,aAAa;IAWlC,mDAAmD;mBAC9B,eAAe;IAYpC,yDAAyD;mBACpC,mBAAmB;IASxC,uDAAuD;mBAClC,iBAAiB;CA0BvC"}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.QrCodeProvider = void 0;
13
+ const utils_1 = require("./utils");
14
+ const react_qr_1 = require("./utils/react-qr");
15
+ /**
16
+ * {@inheritDoc IQRCodeGenerator}
17
+ */
18
+ class QrCodeProvider {
19
+ constructor() {
20
+ this.methods = {
21
+ qrDIDCommOobInvitationElement: QrCodeProvider.qrDIDCommOobInvitationElement.bind(this),
22
+ qrDIDCommOobInvitationValue: QrCodeProvider.qrDIDCommOobInvitationValue.bind(this),
23
+ qrSIOPv2Element: QrCodeProvider.qrSIOPv2Element.bind(this),
24
+ qrSIOPv2Value: QrCodeProvider.qrSIOPv2Value.bind(this),
25
+ qrURIElement: QrCodeProvider.qrURIElement.bind(this),
26
+ qrOpenID4VCIElement: QrCodeProvider.qrOpenID4VCIElement.bind(this),
27
+ qrOpenID4VCIValue: QrCodeProvider.qrOpenID4VCIValue.bind(this),
28
+ };
29
+ }
30
+ /** {@inheritDoc IQRCodeGenerator.uriElement} */
31
+ static qrURIElement(args, context) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return (0, utils_1.generateQRCodeReactElement)(args, context);
34
+ });
35
+ }
36
+ /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationValue} */
37
+ static qrDIDCommOobInvitationValue(args, context) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const { object } = args.data;
40
+ const encoded = utils_1.DidCommOutOfBandMessage.urlEncode(object.oobInvitation);
41
+ const delim = object.baseURI.includes('?') ? '&' : '?';
42
+ return object.baseURI.includes('oob=') ? object.baseURI.replace('oob=', `oob=${encoded}`) : `${object.baseURI}${delim}_oob=${encoded}`;
43
+ });
44
+ }
45
+ /** {@inheritDoc IQRCodeGenerator.didCommOobInvitationElement} */
46
+ static qrDIDCommOobInvitationElement(args, context) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const content = yield QrCodeProvider.qrDIDCommOobInvitationValue(args, context);
49
+ return (0, react_qr_1.generateQRCodeReactElementImpl)(Object.assign(Object.assign({}, args), { data: Object.assign(Object.assign({}, args.data), { object: content }) }), args, context);
50
+ });
51
+ }
52
+ /** {@inheritDoc IQRCodeGenerator.siopv2Value} */
53
+ static qrSIOPv2Value(args, context) {
54
+ var _a;
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const { object } = args.data;
57
+ if (typeof object === 'string') {
58
+ return object;
59
+ }
60
+ const scheme = ((_a = object.scheme) !== null && _a !== void 0 ? _a : 'openid-vc://').replace('://?', '').replace('://', '') + '://';
61
+ const requestUri = `request_uri=${object.requestUri.replace('request_uri=', '')}`;
62
+ return `${scheme}?${requestUri}`;
63
+ });
64
+ }
65
+ /** {@inheritDoc IQRCodeGenerator.siopv2Element} */
66
+ static qrSIOPv2Element(args, context) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const content = yield QrCodeProvider.qrSIOPv2Value(args, context);
69
+ return (0, react_qr_1.generateQRCodeReactElementImpl)(Object.assign(Object.assign({}, args), { data: Object.assign(Object.assign({}, args.data), { object: content }) }), args, context);
70
+ });
71
+ }
72
+ /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIElement} */
73
+ static qrOpenID4VCIElement(args, context) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const content = yield QrCodeProvider.qrOpenID4VCIValue(args, context);
76
+ return (0, react_qr_1.generateQRCodeReactElementImpl)(Object.assign(Object.assign({}, args), { data: Object.assign(Object.assign({}, args.data), { object: content }) }), args, context);
77
+ });
78
+ }
79
+ /** {@inheritDoc IQRCodeGenerator.qrOpenID4VCIValue} */
80
+ static qrOpenID4VCIValue(args, context) {
81
+ var _a, _b, _c, _d;
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const { object } = args.data;
84
+ if (!object.credentialOffer && !object.credentialOfferUri) {
85
+ throw new Error('Please provide credential_offer or credential_offer_uri');
86
+ }
87
+ const scheme = ((_a = object.scheme) !== null && _a !== void 0 ? _a : 'openid-credential-offer://').replace('://?', '').replace('://', '') + '://';
88
+ const baseUri = (_b = object.baseUri) !== null && _b !== void 0 ? _b : '';
89
+ let url;
90
+ const splitBaseUri = baseUri.split('://');
91
+ const hasScheme = splitBaseUri.length > 1;
92
+ if (hasScheme && object.scheme) {
93
+ if (splitBaseUri[0] !== object.scheme) {
94
+ throw new Error('The uri must contain the same scheme or omit it');
95
+ }
96
+ url = `${baseUri}`;
97
+ }
98
+ else {
99
+ url = `${scheme}${baseUri}`;
100
+ }
101
+ const credentialOfferUri = `?credential_offer_uri=${(_c = object.credentialOfferUri) === null || _c === void 0 ? void 0 : _c.replace('credential_offer_uri=', '')}`;
102
+ const credentialOffer = `?credential_offer=${(_d = object.credentialOffer) === null || _d === void 0 ? void 0 : _d.replace('credential_offer=', '')}`;
103
+ const value = object.credentialOffer ? credentialOffer : credentialOfferUri;
104
+ return `${url}${value}`;
105
+ });
106
+ }
107
+ }
108
+ exports.QrCodeProvider = QrCodeProvider;
109
+ //# s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AAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE;oBACrC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;iBACnE;gBACD,GAAG,GAAG,GAAG,OAAO,EAAE,CAAA;aACnB;iBAAM;gBACL,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO,EAAE,CAAA;aAC5B;YACD,MAAM,kBAAkB,GAAG,yBAAyB,MAAA,MAAM,CAAC,kBAAkB,0CAAE,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,EAAE,CAAA;YACrH,MAAM,eAAe,GAAG,qBAAqB,MAAA,MAAM,CAAC,eAAe,0CAAE,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,EAAE,CAAA;YACvG,MAAM,KAAK,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,kBAAkB,CAAA;YAC3E,OAAO,GAAG,GAAG,GAAG,KAAK,EAAE,CAAA;;KACxB;CACF;AA1GD,wCA0GC"}
@@ -0,0 +1,6 @@
1
+ import { DIDCommV2OOBInvitation } from '../../types/IQRCodeGenerator';
2
+ export declare class DidCommOutOfBandMessage {
3
+ static toJson(props: DIDCommV2OOBInvitation): string;
4
+ static urlEncode(payload: DIDCommV2OOBInvitation): string;
5
+ }
6
+ //# sourceMappingURL=didcomm-oob-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"didcomm-oob-message.d.ts","sourceRoot":"","sources":["../../../src/agent/utils/didcomm-oob-message.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAGrE,qBAAa,uBAAuB;WACpB,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM;WAI7C,SAAS,CAAC,OAAO,EAAE,sBAAsB;CAGxD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DidCommOutOfBandMessage = void 0;
7
+ const base64url_1 = __importDefault(require("base64url"));
8
+ class DidCommOutOfBandMessage {
9
+ static toJson(props) {
10
+ return JSON.stringify(props).replace('goalCode', 'goal-code');
11
+ }
12
+ static urlEncode(payload) {
13
+ return (0, base64url_1.default)(this.toJson(payload));
14
+ }
15
+ }
16
+ exports.DidCommOutOfBandMessage = DidCommOutOfBandMessage;
17
+ //# sourceMappingURL=didcomm-oob-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"didcomm-oob-message.js","sourceRoot":"","sources":["../../../src/agent/utils/didcomm-oob-message.tsx"],"names":[],"mappings":";;;;;;AACA,0DAAiC;AAEjC,MAAa,uBAAuB;IAC3B,MAAM,CAAC,MAAM,CAAC,KAA6B;QAChD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;IAC/D,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,OAA+B;QACrD,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IACxC,CAAC;CACF;AARD,0DAQC"}
@@ -0,0 +1,3 @@
1
+ export { generateQRCodeReactElement, generateQRCodeValue } from './react-qr';
2
+ export * from './didcomm-oob-message';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAC5E,cAAc,uBAAuB,CAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.generateQRCodeValue = exports.generateQRCodeReactElement = void 0;
18
+ var react_qr_1 = require("./react-qr");
19
+ Object.defineProperty(exports, "generateQRCodeReactElement", { enumerable: true, get: function () { return react_qr_1.generateQRCodeReactElement; } });
20
+ Object.defineProperty(exports, "generateQRCodeValue", { enumerable: true, get: function () { return react_qr_1.generateQRCodeValue; } });
21
+ __exportStar(require("./didcomm-oob-message"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAA4E;AAAnE,sHAAA,0BAA0B,OAAA;AAAE,+GAAA,mBAAmB,OAAA;AACxD,wDAAqC"}
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { CreateElementArgs, CreateValueArgs, IRequiredContext, QRType, ValueResult } from '../../types/IQRCodeGenerator';
3
+ export declare function generateQRCodeValue<T extends QRType>(args: CreateValueArgs<T, string> | CreateElementArgs<T, string>, context?: IRequiredContext): Promise<ValueResult<T, string>>;
4
+ export declare function generateQRCodeValueImpl<T extends QRType>(args: CreateValueArgs<T, string> | CreateElementArgs<T, string>, orig: CreateValueArgs<T, any> | CreateElementArgs<T, any>, context?: IRequiredContext): Promise<ValueResult<T, string>>;
5
+ export declare function generateQRCodeReactElement<T extends QRType>(args: CreateElementArgs<T, string>, context: IRequiredContext): Promise<JSX.Element>;
6
+ export declare function generateQRCodeReactElementImpl<T extends QRType>(args: CreateElementArgs<T, string>, orig: CreateElementArgs<T, any>, context: IRequiredContext): Promise<JSX.Element>;
7
+ //# sourceMappingURL=react-qr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-qr.d.ts","sourceRoot":"","sources":["../../../src/agent/utils/react-qr.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAU,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAIhI,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EACxD,IAAI,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC,EAC/D,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAEjC;AAED,wBAAsB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAC5D,IAAI,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC,EAC/D,IAAI,EAAE,eAAe,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,EACzD,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAsBjC;AAED,wBAAsB,0BAA0B,CAAC,CAAC,SAAS,MAAM,EAC/D,IAAI,EAAE,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC,EAClC,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAEtB;AAED,wBAAsB,8BAA8B,CAAC,CAAC,SAAS,MAAM,EACnE,IAAI,EAAE,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC,EAClC,IAAI,EAAE,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,EAC/B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAOtB"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.generateQRCodeReactElementImpl = exports.generateQRCodeReactElement = exports.generateQRCodeValueImpl = exports.generateQRCodeValue = void 0;
16
+ const IQRCodeGenerator_1 = require("../../types/IQRCodeGenerator");
17
+ const react_qr_code_1 = __importDefault(require("react-qr-code"));
18
+ const react_1 = __importDefault(require("react"));
19
+ function generateQRCodeValue(args, context) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return generateQRCodeValueImpl(args, args, context);
22
+ });
23
+ }
24
+ exports.generateQRCodeValue = generateQRCodeValue;
25
+ function generateQRCodeValueImpl(args, orig, context) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const { onGenerate } = orig;
28
+ const { id } = orig.data;
29
+ const value = args.data.object;
30
+ const result = {
31
+ id,
32
+ value,
33
+ data: orig.data,
34
+ renderingProps: 'renderingProps' in orig ? orig.renderingProps : undefined,
35
+ context,
36
+ };
37
+ if (onGenerate) {
38
+ onGenerate(result);
39
+ }
40
+ if (context) {
41
+ context.agent.emit(IQRCodeGenerator_1.events.QR_CODE_CODE_CREATED, result);
42
+ }
43
+ return result;
44
+ });
45
+ }
46
+ exports.generateQRCodeValueImpl = generateQRCodeValueImpl;
47
+ function generateQRCodeReactElement(args, context) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return generateQRCodeReactElementImpl(args, args, context);
50
+ });
51
+ }
52
+ exports.generateQRCodeReactElement = generateQRCodeReactElement;
53
+ function generateQRCodeReactElementImpl(args, orig, context) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const { renderingProps } = args;
56
+ const { bgColor, fgColor, level, size, title } = renderingProps;
57
+ const result = yield generateQRCodeValueImpl(args, orig, context);
58
+ // @ts-ignore
59
+ return react_1.default.createElement(react_qr_code_1.default, { value: result.value, bgColor: bgColor, fgColor: fgColor, level: level, size: size, title: title });
60
+ });
61
+ }
62
+ exports.generateQRCodeReactElementImpl = generateQRCodeReactElementImpl;
63
+ //# sourceMappingURL=react-qr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-qr.js","sourceRoot":"","sources":["../../../src/agent/utils/react-qr.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAAgI;AAChI,kEAAkC;AAClC,kDAAyB;AAEzB,SAAsB,mBAAmB,CACvC,IAA+D,EAC/D,OAA0B;;QAE1B,OAAO,uBAAuB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACrD,CAAC;CAAA;AALD,kDAKC;AAED,SAAsB,uBAAuB,CAC3C,IAA+D,EAC/D,IAAyD,EACzD,OAA0B;;QAE1B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;QAC3B,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,CAAA;QAExB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAA;QAE9B,MAAM,MAAM,GAA2B;YACrC,EAAE;YACF,KAAK;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc,EAAE,gBAAgB,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;YAC1E,OAAO;SACR,CAAA;QAED,IAAI,UAAU,EAAE;YACd,UAAU,CAAC,MAAM,CAAC,CAAA;SACnB;QACD,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,yBAAM,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAA;SACxD;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CAAA;AA1BD,0DA0BC;AAED,SAAsB,0BAA0B,CAC9C,IAAkC,EAClC,OAAyB;;QAEzB,OAAO,8BAA8B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAC5D,CAAC;CAAA;AALD,gEAKC;AAED,SAAsB,8BAA8B,CAClD,IAAkC,EAClC,IAA+B,EAC/B,OAAyB;;QAEzB,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAA;QAC/B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,cAAc,CAAA;QAC/D,MAAM,MAAM,GAA2B,MAAM,uBAAuB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QAEzF,aAAa;QACb,OAAO,8BAAC,uBAAM,IAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAI,CAAA;IACpH,CAAC;CAAA;AAXD,wEAWC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export * from './agent/QrCodeProvider';
5
+ export * from './types/IQRCodeGenerator';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * @public
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./agent/QrCodeProvider"), exports);
21
+ __exportStar(require("./types/IQRCodeGenerator"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,yDAAsC;AACtC,2DAAwC"}
@@ -0,0 +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>>;
93
+ //# sourceMappingURL=IQRCodeGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IQRCodeGenerator.d.ts","sourceRoot":"","sources":["../../src/types/IQRCodeGenerator.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE9D,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,6BAA6B,CAC3B,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,yBAAyB,EAAE,0BAA0B,CAAC,EACrF,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAEvB,2BA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,CAAA;IACnB,MAAM,EAAE,CAAC,UAAU,CAAC,CAAA;CACrB;AAED,MAAM,MAAM,QAAQ,GAAG,gBAAgB,GAAG,gBAAgB,CAAA;AAE1D,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,MAAM,CAAA;AAM9C,oBAAY,UAAU;IACpB,EAAE,OAAO;IACT,OAAO,YAAY;CACpB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC;IACzC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,CAAC,CAAA;CACV;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,oBAAY,MAAM;IAChB,oBAAoB,kBAAkB;CACvC;AAED,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +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 = exports.QRType || (exports.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 || (exports.StatusCode = {}));
19
+ var events;
20
+ (function (events) {
21
+ events["QR_CODE_CODE_CREATED"] = "QrCodeCreated";
22
+ })(events = exports.events || (exports.events = {}));
23
+ //# sourceMappingURL=IQRCodeGenerator.js.map
@@ -0,0 +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,GAAN,cAAM,KAAN,cAAM,QAKjB;AAqDD;;qBAEqB;AAErB,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,uBAAS,CAAA;IACT,iCAAmB,CAAA;AACrB,CAAC,EAHW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAGrB;AAgBD,IAAY,MAEX;AAFD,WAAY,MAAM;IAChB,gDAAsC,CAAA;AACxC,CAAC,EAFW,MAAM,GAAN,cAAM,KAAN,cAAM,QAEjB"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@sphereon/ssi-sdk.qr-code-generator",
3
+ "version": "0.11.1-next.65+0d0575e",
4
+ "description": "QR Code provider (react)",
5
+ "source": "src/index.ts",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "veramo": {
9
+ "pluginInterfaces": {
10
+ "IQRCodeGenerator": "./src/types/IQRCodeGenerator.ts"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build": "tsc --build",
15
+ "build:clean": "tsc --build --clean && tsc --build"
16
+ },
17
+ "dependencies": {
18
+ "@veramo/core": "4.2.0",
19
+ "base64url": "^3.0.1",
20
+ "react": "^18.2.0",
21
+ "react-qr-code": "^2.0.11"
22
+ },
23
+ "devDependencies": {
24
+ "@inrupt/jest-jsdom-polyfills": "^1.5.5",
25
+ "@sphereon/ssi-sdk.agent-config": "0.11.1-next.65+0d0575e",
26
+ "@testing-library/jest-dom": "^5.16.5",
27
+ "@testing-library/react": "^14.0.0",
28
+ "@types/jest": "^27.5.2",
29
+ "@types/react": "^18.0.28",
30
+ "@types/uuid": "^8.3.4",
31
+ "global-jsdom": "^8.7.0",
32
+ "jest": "^27.5.1",
33
+ "jest-environment-jsdom": "^27.5.1",
34
+ "jsdom": "^21.1.0",
35
+ "react-dom": "^18.2.0",
36
+ "ts-jest": "^27.1.5"
37
+ },
38
+ "files": [
39
+ "dist/**/*",
40
+ "src/**/*",
41
+ "README.md",
42
+ "LICENSE"
43
+ ],
44
+ "private": false,
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "repository": "git@github.com:Sphereon-Opensource/SSI-SDK.git",
49
+ "author": "Sphereon <dev@sphereon.com>",
50
+ "license": "Apache-2.0",
51
+ "keywords": [
52
+ "Sphereon",
53
+ "SSI",
54
+ "React",
55
+ "WACI",
56
+ "OpenID",
57
+ "OpenID4VP",
58
+ "OpenID4VCI",
59
+ "QR Code"
60
+ ],
61
+ "gitHead": "0d0575e7320859beb4857ebe0f995aff9d259ca1"
62
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,12 @@
1
+ import { DIDCommV2OOBInvitation } from '../../types/IQRCodeGenerator'
2
+ import base64url from 'base64url'
3
+
4
+ export class DidCommOutOfBandMessage {
5
+ public static toJson(props: DIDCommV2OOBInvitation): string {
6
+ return JSON.stringify(props).replace('goalCode', 'goal-code')
7
+ }
8
+
9
+ public static urlEncode(payload: DIDCommV2OOBInvitation) {
10
+ return base64url(this.toJson(payload))
11
+ }
12
+ }
@@ -0,0 +1,2 @@
1
+ export { generateQRCodeReactElement, generateQRCodeValue } from './react-qr'
2
+ export * from './didcomm-oob-message'
@@ -0,0 +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
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @public
3
+ */
4
+
5
+ export * from './agent/QrCodeProvider'
6
+ export * from './types/IQRCodeGenerator'
@@ -0,0 +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>>