@gramota/qr 0.3.0

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @gramota/qr
2
+
3
+ > QR-code rendering for EUDIW deep links. Strategy-pluggable renderer, three input shapes (any URL, OID4VP authorization request, OID4VCI credential offer), three output formats (data URL, SVG, raw PNG bytes).
4
+
5
+ Part of [Gramota](https://github.com/gramota-org/gramota) — the TypeScript
6
+ SDK for the EU Digital Identity Wallet.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pnpm add @gramota/qr
12
+ # or: npm install @gramota/qr
13
+ ```
14
+
15
+ ## Quick example
16
+
17
+ ```ts
18
+ import { qr } from "@gramota/qr";
19
+
20
+ const code = qr.fromUrl("openid4vp://?client_id=...&request_uri=...");
21
+
22
+ const dataUrl = await code.toDataUrl(); // <img src={dataUrl} />
23
+ const svg = await code.toSvg(); // for innerHTML / SSR
24
+ const png = await code.toPng(); // Uint8Array — fs.writeFile, multipart upload
25
+ ```
26
+
27
+ ## Three input shapes
28
+
29
+ `qr.fromUrl(url, options?)` — most general. Any string with a `<scheme>:` prefix.
30
+
31
+ `qr.fromAuthorizationRequest(request, options?)` — composes with
32
+ `@gramota/oid4vp`. Takes a typed `AuthorizationRequest`, builds the
33
+ `openid4vp://` deep link, renders the QR. Override the scheme via
34
+ `{ scheme: "haip://" }` for vendor-specific wallets.
35
+
36
+ `qr.fromCredentialOffer(offer, options?)` — composes with
37
+ `@gramota/oid4vci`. Takes a typed `CredentialOffer`, builds the
38
+ `openid-credential-offer://` deep link, renders the QR.
39
+
40
+ ## Three output formats — lazy + memoised
41
+
42
+ `code.toDataUrl()`, `code.toSvg()`, `code.toPng()` each invoke the
43
+ configured renderer on first call and cache the result. Concurrent
44
+ first-callers share the in-flight render — no thundering herd. Pay
45
+ the encode cost once per format, only for the formats you actually use.
46
+
47
+ ## Pluggable renderer (Strategy pattern)
48
+
49
+ The default is `DefaultQrRenderer` — an Adapter over the [`qrcode`](https://www.npmjs.com/package/qrcode)
50
+ npm package. Want logo embedding, branded colours, a browser-native
51
+ canvas renderer? Implement `QrRenderer`:
52
+
53
+ ```ts
54
+ import type { QrRenderer, QrFormat, QrOptions } from "@gramota/qr";
55
+
56
+ class BrandedQrRenderer implements QrRenderer {
57
+ async render(url: string, format: QrFormat, opts: QrOptions) {
58
+ // …your renderer (e.g. with a logo overlaid in the centre)…
59
+ }
60
+ }
61
+
62
+ const code = qr.fromUrl(url, { renderer: new BrandedQrRenderer() });
63
+ ```
64
+
65
+ The orchestrator depends only on the `QrRenderer` interface, never on
66
+ `qrcode` directly. You can swap the rendering backend without touching
67
+ your verifier or issuer code.
68
+
69
+ ## Design
70
+
71
+ `@gramota/qr` is small but follows the same patterns as the rest of the SDK:
72
+
73
+ - **Strategy** (GoF) — `QrRenderer` interface with a default Adapter
74
+ over `qrcode`. Add new renderers by implementing the interface.
75
+ - **Factory Method** (GoF) — `qr.from*` family creates `QrCode`
76
+ instances from different input shapes; new sources add as siblings,
77
+ no existing factory changes.
78
+ - **Adapter** (GoF) — `DefaultQrRenderer` adapts `qrcode`'s API to
79
+ ours. Replacing `qrcode` later means a one-file change here, zero
80
+ changes for consumers.
81
+ - **Lazy + memoisation** — output formats render on first call only;
82
+ concurrent first-callers share the promise.
83
+ - **Open/Closed, Dependency Inversion** — the orchestrator depends
84
+ on the abstraction; concrete implementations plug in via DI.
85
+
86
+ For the high-level wallet + verifier counterparts, see the
87
+ [main repo](https://github.com/gramota-org/gramota).
88
+
89
+ ## License
90
+
91
+ [Apache 2.0](https://github.com/gramota-org/gramota/blob/main/LICENSE)
@@ -0,0 +1,59 @@
1
+ import type { AuthorizationRequest } from "@gramota/oid4vp";
2
+ import type { CredentialOffer } from "@gramota/oid4vci";
3
+ import { type QrOptions } from "./types.js";
4
+ import { type QrRenderer } from "./renderer.js";
5
+ import { QrCode } from "./qr-code.js";
6
+ /** Construction-time options for {@link QrClient}. */
7
+ export interface QrClientOptions extends QrOptions {
8
+ /** Override the rendering Strategy. Defaults to a singleton
9
+ * {@link DefaultQrRenderer} backed by the `qrcode` npm package. */
10
+ readonly renderer?: QrRenderer;
11
+ }
12
+ export declare class QrClient {
13
+ private readonly renderer;
14
+ private readonly defaults;
15
+ constructor(options?: QrClientOptions);
16
+ /**
17
+ * Render any URL as a QR code.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const code = qr.fromUrl("openid4vp://?client_id=…");
22
+ * const dataUrl = await code.toDataUrl();
23
+ * ```
24
+ *
25
+ * @throws {@link QrError} with `qr.invalid_url` if the input isn't a
26
+ * non-empty string with a `<scheme>:` prefix.
27
+ */
28
+ fromUrl(url: string, options?: QrOptions): QrCode;
29
+ /**
30
+ * Render an OID4VP {@link AuthorizationRequest} as a QR code. Default
31
+ * scheme is `openid4vp://`. Override via `{ scheme }` for HAIP /
32
+ * country-specific wallet schemes.
33
+ */
34
+ fromAuthorizationRequest(request: AuthorizationRequest, options?: QrOptions & {
35
+ readonly scheme?: string;
36
+ }): QrCode;
37
+ /**
38
+ * Render an OID4VCI {@link CredentialOffer} as a QR code. Default
39
+ * scheme is `openid-credential-offer://` per OID4VCI §4.1.
40
+ */
41
+ fromCredentialOffer(offer: CredentialOffer, options?: QrOptions & {
42
+ readonly scheme?: string;
43
+ }): QrCode;
44
+ private merge;
45
+ }
46
+ /**
47
+ * Default singleton {@link QrClient} with the default renderer.
48
+ *
49
+ * Most consumers want this — no construction, no options, just
50
+ * `qr.fromUrl(deepLink)`. Pass a custom renderer or default options
51
+ * by constructing your own `new QrClient({...})`.
52
+ */
53
+ export declare const qr: QrClient;
54
+ export declare const fromUrl: QrClient["fromUrl"];
55
+ export declare const fromAuthorizationRequest: QrClient["fromAuthorizationRequest"];
56
+ export declare const fromCredentialOffer: QrClient["fromCredentialOffer"];
57
+ /** @deprecated alias for {@link QrClientOptions} — kept for source compat. */
58
+ export type QrFactoryOptions = QrClientOptions;
59
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,sDAAsD;AACtD,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAChD;uEACmE;IACnE,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;CAChC;AAMD,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAY;gBAEzB,OAAO,CAAC,EAAE,eAAe;IAOrC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM;IAgBjD;;;;OAIG;IACH,wBAAwB,CACtB,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE,SAAS,GAAG;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACjD,MAAM;IAMT;;;OAGG;IACH,mBAAmB,CACjB,KAAK,EAAE,eAAe,EACtB,OAAO,CAAC,EAAE,SAAS,GAAG;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACjD,MAAM;IAQT,OAAO,CAAC,KAAK;CAMd;AAED;;;;;;GAMG;AACH,eAAO,MAAM,EAAE,EAAE,QAAyB,CAAC;AAU3C,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,SAAS,CACd,CAAC;AAC3B,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,0BAA0B,CAGxB,CAAC;AACnD,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,qBAAqB,CAGrB,CAAC;AAE5C,8EAA8E;AAC9E,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,113 @@
1
+ /**
2
+ * `QrClient` — Stripe-shaped class entry point for `@gramota/qr`.
3
+ *
4
+ * Three factory methods (Factory Method, GoF), each accepting a
5
+ * different shape of input and all returning a {@link QrCode}:
6
+ *
7
+ * - {@link QrClient.fromUrl} — a raw deep-link URL.
8
+ * - {@link QrClient.fromAuthorizationRequest} — an OID4VP request.
9
+ * - {@link QrClient.fromCredentialOffer} — an OID4VCI offer.
10
+ *
11
+ * The renderer (Strategy, GoF) and default {@link QrOptions} are
12
+ * carried by the instance. Pass them once at construction; every
13
+ * `from*` call layers per-call overrides on top:
14
+ *
15
+ * ```ts
16
+ * const qr = new QrClient({
17
+ * errorCorrection: "H", // default for all codes
18
+ * renderer: new DefaultQrRenderer(), // strategy override
19
+ * });
20
+ *
21
+ * const code = qr.fromUrl("openid4vp://…", { width: 512 }); // call-level override
22
+ * const dataUrl = await code.toDataUrl();
23
+ * ```
24
+ *
25
+ * Adding a new input shape (e.g. `fromMdocPresentationRequest`) means
26
+ * adding a new method here without touching the existing ones (Open/
27
+ * Closed). The orchestrator depends only on {@link QrRenderer},
28
+ * never on the `qrcode` npm package directly.
29
+ */
30
+ import { buildAuthorizationRequestUrl } from "@gramota/oid4vp";
31
+ import { buildCredentialOfferUrl } from "@gramota/oid4vci";
32
+ import { QrError } from "./types.js";
33
+ import { DefaultQrRenderer } from "./renderer.js";
34
+ import { QrCode } from "./qr-code.js";
35
+ /** Module-level default renderer — created once, reused by every
36
+ * QrClient instance that doesn't pass its own. */
37
+ const defaultRenderer = new DefaultQrRenderer();
38
+ export class QrClient {
39
+ renderer;
40
+ defaults;
41
+ constructor(options) {
42
+ this.renderer = options?.renderer ?? defaultRenderer;
43
+ const { renderer: _renderer, ...defaults } = options ?? {};
44
+ void _renderer;
45
+ this.defaults = defaults;
46
+ }
47
+ /**
48
+ * Render any URL as a QR code.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const code = qr.fromUrl("openid4vp://?client_id=…");
53
+ * const dataUrl = await code.toDataUrl();
54
+ * ```
55
+ *
56
+ * @throws {@link QrError} with `qr.invalid_url` if the input isn't a
57
+ * non-empty string with a `<scheme>:` prefix.
58
+ */
59
+ fromUrl(url, options) {
60
+ if (typeof url !== "string" || url.length === 0) {
61
+ throw new QrError("qr.invalid_url", "qr.fromUrl: url must be a non-empty string");
62
+ }
63
+ if (!/^[a-z][a-z0-9+.-]*:/i.test(url)) {
64
+ throw new QrError("qr.invalid_url", `qr.fromUrl: "${url.slice(0, 40)}…" doesn't look like a URI`);
65
+ }
66
+ return new QrCode(url, this.renderer, this.merge(options));
67
+ }
68
+ /**
69
+ * Render an OID4VP {@link AuthorizationRequest} as a QR code. Default
70
+ * scheme is `openid4vp://`. Override via `{ scheme }` for HAIP /
71
+ * country-specific wallet schemes.
72
+ */
73
+ fromAuthorizationRequest(request, options) {
74
+ const scheme = options?.scheme ?? "openid4vp://";
75
+ const url = buildAuthorizationRequestUrl(scheme, request);
76
+ return new QrCode(url, this.renderer, this.merge(options));
77
+ }
78
+ /**
79
+ * Render an OID4VCI {@link CredentialOffer} as a QR code. Default
80
+ * scheme is `openid-credential-offer://` per OID4VCI §4.1.
81
+ */
82
+ fromCredentialOffer(offer, options) {
83
+ const url = buildCredentialOfferUrl(offer, options?.scheme !== undefined ? { scheme: options.scheme } : {});
84
+ return new QrCode(url, this.renderer, this.merge(options));
85
+ }
86
+ merge(options) {
87
+ if (!options)
88
+ return this.defaults;
89
+ const { scheme: _scheme, ...rest } = options;
90
+ void _scheme;
91
+ return { ...this.defaults, ...rest };
92
+ }
93
+ }
94
+ /**
95
+ * Default singleton {@link QrClient} with the default renderer.
96
+ *
97
+ * Most consumers want this — no construction, no options, just
98
+ * `qr.fromUrl(deepLink)`. Pass a custom renderer or default options
99
+ * by constructing your own `new QrClient({...})`.
100
+ */
101
+ export const qr = new QrClient();
102
+ /* ------------------------------------------------------------------
103
+ * Back-compat re-exports.
104
+ *
105
+ * Pre-0.2.0 the public surface was three named functions plus a
106
+ * frozen `qr` object literal. Both shapes still work — the named
107
+ * functions delegate to the singleton, and `qr` is now a class
108
+ * instance with the same method names.
109
+ * ------------------------------------------------------------------ */
110
+ export const fromUrl = (url, options) => qr.fromUrl(url, options);
111
+ export const fromAuthorizationRequest = (request, options) => qr.fromAuthorizationRequest(request, options);
112
+ export const fromCredentialOffer = (offer, options) => qr.fromCredentialOffer(offer, options);
113
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `@gramota/qr` public API.
3
+ *
4
+ * Two patterns work — pick whichever fits:
5
+ *
6
+ * 1. **Default singleton** (zero config):
7
+ * ```ts
8
+ * import { qr } from "@gramota/qr";
9
+ * const code = qr.fromUrl("openid4vp://…");
10
+ * ```
11
+ *
12
+ * 2. **Custom client** (custom renderer, default options):
13
+ * ```ts
14
+ * import { QrClient } from "@gramota/qr";
15
+ * const qr = new QrClient({ errorCorrection: "H", width: 512 });
16
+ * const code = qr.fromUrl("openid4vp://…");
17
+ * ```
18
+ *
19
+ * Tree-shakers can also import the named factories directly
20
+ * (`fromUrl`, `fromAuthorizationRequest`, `fromCredentialOffer`) —
21
+ * they delegate to the singleton.
22
+ */
23
+ export { QrClient, qr, fromUrl, fromAuthorizationRequest, fromCredentialOffer, type QrClientOptions, type QrFactoryOptions, } from "./client.js";
24
+ export { QrCode } from "./qr-code.js";
25
+ export { DefaultQrRenderer, type QrRenderer, } from "./renderer.js";
26
+ export { QrError, type QrErrorCode, type QrFormat, type QrOptions, } from "./types.js";
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EACL,QAAQ,EACR,EAAE,EACF,OAAO,EACP,wBAAwB,EACxB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,iBAAiB,EACjB,KAAK,UAAU,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,OAAO,EACP,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `@gramota/qr` public API.
3
+ *
4
+ * Two patterns work — pick whichever fits:
5
+ *
6
+ * 1. **Default singleton** (zero config):
7
+ * ```ts
8
+ * import { qr } from "@gramota/qr";
9
+ * const code = qr.fromUrl("openid4vp://…");
10
+ * ```
11
+ *
12
+ * 2. **Custom client** (custom renderer, default options):
13
+ * ```ts
14
+ * import { QrClient } from "@gramota/qr";
15
+ * const qr = new QrClient({ errorCorrection: "H", width: 512 });
16
+ * const code = qr.fromUrl("openid4vp://…");
17
+ * ```
18
+ *
19
+ * Tree-shakers can also import the named factories directly
20
+ * (`fromUrl`, `fromAuthorizationRequest`, `fromCredentialOffer`) —
21
+ * they delegate to the singleton.
22
+ */
23
+ export { QrClient, qr, fromUrl, fromAuthorizationRequest, fromCredentialOffer, } from "./client.js";
24
+ export { QrCode } from "./qr-code.js";
25
+ export { DefaultQrRenderer, } from "./renderer.js";
26
+ export { QrError, } from "./types.js";
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EACL,QAAQ,EACR,EAAE,EACF,OAAO,EACP,wBAAwB,EACxB,mBAAmB,GAGpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,iBAAiB,GAElB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,OAAO,GAIR,MAAM,YAAY,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The {@link QrCode} result type — what every `qr.from*` factory returns.
3
+ *
4
+ * Holds the source URL plus a memoised cache for each output format.
5
+ * Consumers ask for whichever shape they need (`toDataUrl`, `toSvg`,
6
+ * `toPng`) — the renderer is invoked on first call only; subsequent
7
+ * calls return the cached buffer/string.
8
+ *
9
+ * Lazy + memoised because rendering isn't free (the PNG path costs a
10
+ * Reed-Solomon encode per call) and most consumers want exactly one
11
+ * output format. Pay once, reuse.
12
+ */
13
+ import type { QrOptions } from "./types.js";
14
+ import type { QrRenderer } from "./renderer.js";
15
+ export declare class QrCode {
16
+ /** The URL encoded in the QR matrix — exactly what scanners will read. */
17
+ readonly url: string;
18
+ private readonly renderer;
19
+ private readonly options;
20
+ private dataUrlCache?;
21
+ private svgCache?;
22
+ private pngCache?;
23
+ /** @internal — construct via the {@link qr} factories, not directly. */
24
+ constructor(url: string, renderer: QrRenderer, options?: QrOptions);
25
+ /**
26
+ * PNG as a `data:image/png;base64,…` URL — drop directly into an
27
+ * `<img src>` attribute. Best for fast inline rendering in HTML
28
+ * emails and dashboards.
29
+ */
30
+ toDataUrl(): Promise<string>;
31
+ /**
32
+ * Raw SVG markup — drop into `innerHTML` (or Angular `[innerHTML]`).
33
+ * Scales without quality loss, good for print and high-DPI screens.
34
+ */
35
+ toSvg(): Promise<string>;
36
+ /**
37
+ * Raw PNG bytes — `Uint8Array` for portability (Node `Buffer`
38
+ * extends it). Use for `fs.writeFile`, multipart uploads, and
39
+ * binary-channel transports.
40
+ */
41
+ toPng(): Promise<Uint8Array>;
42
+ }
43
+ //# sourceMappingURL=qr-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qr-code.d.ts","sourceRoot":"","sources":["../src/qr-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,qBAAa,MAAM;IACjB,0EAA0E;IAC1E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IAIpC,OAAO,CAAC,YAAY,CAAC,CAAkB;IACvC,OAAO,CAAC,QAAQ,CAAC,CAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,CAAsB;IAEvC,wEAAwE;gBAC5D,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,GAAE,SAAc;IAMtE;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAM5B;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAMxB;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC;CAK7B"}
@@ -0,0 +1,47 @@
1
+ export class QrCode {
2
+ /** The URL encoded in the QR matrix — exactly what scanners will read. */
3
+ url;
4
+ renderer;
5
+ options;
6
+ // Lazy / memoised caches. Promise-typed so concurrent first-callers
7
+ // share the same in-flight render.
8
+ dataUrlCache;
9
+ svgCache;
10
+ pngCache;
11
+ /** @internal — construct via the {@link qr} factories, not directly. */
12
+ constructor(url, renderer, options = {}) {
13
+ this.url = url;
14
+ this.renderer = renderer;
15
+ this.options = options;
16
+ }
17
+ /**
18
+ * PNG as a `data:image/png;base64,…` URL — drop directly into an
19
+ * `<img src>` attribute. Best for fast inline rendering in HTML
20
+ * emails and dashboards.
21
+ */
22
+ toDataUrl() {
23
+ return (this.dataUrlCache ??= this.renderer
24
+ .render(this.url, "dataUrl", this.options)
25
+ .then((v) => v));
26
+ }
27
+ /**
28
+ * Raw SVG markup — drop into `innerHTML` (or Angular `[innerHTML]`).
29
+ * Scales without quality loss, good for print and high-DPI screens.
30
+ */
31
+ toSvg() {
32
+ return (this.svgCache ??= this.renderer
33
+ .render(this.url, "svg", this.options)
34
+ .then((v) => v));
35
+ }
36
+ /**
37
+ * Raw PNG bytes — `Uint8Array` for portability (Node `Buffer`
38
+ * extends it). Use for `fs.writeFile`, multipart uploads, and
39
+ * binary-channel transports.
40
+ */
41
+ toPng() {
42
+ return (this.pngCache ??= this.renderer
43
+ .render(this.url, "png", this.options)
44
+ .then((v) => v));
45
+ }
46
+ }
47
+ //# sourceMappingURL=qr-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qr-code.js","sourceRoot":"","sources":["../src/qr-code.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,MAAM;IACjB,0EAA0E;IACjE,GAAG,CAAS;IAEJ,QAAQ,CAAa;IACrB,OAAO,CAAY;IAEpC,oEAAoE;IACpE,mCAAmC;IAC3B,YAAY,CAAmB;IAC/B,QAAQ,CAAmB;IAC3B,QAAQ,CAAuB;IAEvC,wEAAwE;IACxE,YAAY,GAAW,EAAE,QAAoB,EAAE,UAAqB,EAAE;QACpE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,CAAC,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,QAAQ;aACxC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC;aACzC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAW,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ;aACpC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;aACrC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAW,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ;aACpC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;aACrC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAe,CAAC,CAAC,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ import { type QrFormat, type QrOptions } from "./types.js";
2
+ /** Strategy interface. Implementations decide HOW to render; the
3
+ * orchestrator decides WHEN. */
4
+ export interface QrRenderer {
5
+ /**
6
+ * Render the given URL as a QR code in `format`.
7
+ *
8
+ * Return type depends on `format`:
9
+ * - `"dataUrl"` → `string` (a `data:image/png;base64,...` URL)
10
+ * - `"svg"` → `string` (the raw `<svg>...</svg>` markup)
11
+ * - `"png"` → `Uint8Array` (raw PNG bytes — `Buffer` in Node, but
12
+ * typed as `Uint8Array` so this is portable).
13
+ *
14
+ * Throw {@link QrError} with `qr.unsupported_format` if the
15
+ * renderer can't produce the requested format, or
16
+ * `qr.render_failed` for any other failure.
17
+ */
18
+ render(url: string, format: QrFormat, options: QrOptions): Promise<string | Uint8Array>;
19
+ }
20
+ /**
21
+ * Default renderer — Adapter (GoF) over the `qrcode` npm package.
22
+ *
23
+ * Maps our {@link QrOptions} shape onto `qrcode`'s, dispatches based
24
+ * on `format`, and surfaces failures as {@link QrError}. Swappable
25
+ * via {@link QrRenderer}: anyone with stricter requirements
26
+ * (Trust-on-first-use logo embedding, brand-coloured QR with a styled
27
+ * data-pattern, etc.) writes their own implementation.
28
+ */
29
+ export declare class DefaultQrRenderer implements QrRenderer {
30
+ render(url: string, format: QrFormat, options: QrOptions): Promise<string | Uint8Array>;
31
+ }
32
+ //# sourceMappingURL=renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAcA,OAAO,EAAW,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEpE;gCACgC;AAChC,MAAM,WAAW,UAAU;IACzB;;;;;;;;;;;;OAYG;IACH,MAAM,CACJ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,YAAW,UAAU;IAC5C,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC;CA4ChC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The {@link QrRenderer} Strategy + the default Adapter implementation.
3
+ *
4
+ * Strategy (GoF): consumers swap renderers without touching the
5
+ * orchestrator. Default = {@link DefaultQrRenderer}, which Adapts the
6
+ * `qrcode` npm package to our shape. Want logo embedding, custom corner
7
+ * shapes, or a browser-native renderer using `canvas`? Implement
8
+ * {@link QrRenderer} and pass it via `qr.fromUrl(url, { renderer })`.
9
+ *
10
+ * Dependency-inversion: the rest of the package depends on this
11
+ * abstraction — never on `qrcode` directly. The concrete `qrcode`
12
+ * import is fully isolated to {@link DefaultQrRenderer}.
13
+ */
14
+ import qrcode from "qrcode";
15
+ import { QrError } from "./types.js";
16
+ /**
17
+ * Default renderer — Adapter (GoF) over the `qrcode` npm package.
18
+ *
19
+ * Maps our {@link QrOptions} shape onto `qrcode`'s, dispatches based
20
+ * on `format`, and surfaces failures as {@link QrError}. Swappable
21
+ * via {@link QrRenderer}: anyone with stricter requirements
22
+ * (Trust-on-first-use logo embedding, brand-coloured QR with a styled
23
+ * data-pattern, etc.) writes their own implementation.
24
+ */
25
+ export class DefaultQrRenderer {
26
+ async render(url, format, options) {
27
+ const opts = {
28
+ width: options.width ?? 300,
29
+ margin: options.margin ?? 1,
30
+ errorCorrectionLevel: options.errorCorrection ?? "M",
31
+ color: {
32
+ dark: options.colors?.dark ?? "#000000",
33
+ light: options.colors?.light ?? "#ffffff",
34
+ },
35
+ };
36
+ try {
37
+ switch (format) {
38
+ case "dataUrl":
39
+ return await qrcode.toDataURL(url, opts);
40
+ case "svg":
41
+ return await qrcode.toString(url, { ...opts, type: "svg" });
42
+ case "png": {
43
+ // toBuffer is Node-only; throws in pure-browser bundles.
44
+ const buf = await qrcode.toBuffer(url, opts);
45
+ // Return Uint8Array (the portable shape) — Buffer extends it.
46
+ return new Uint8Array(buf);
47
+ }
48
+ default: {
49
+ // Exhaustive-check assertion. If a new QrFormat is added to
50
+ // the type union without a matching `case` here, TypeScript
51
+ // fails at compile time on this line.
52
+ const _exhaustive = format;
53
+ throw new QrError("qr.unsupported_format", `format ${String(_exhaustive)} is not supported by DefaultQrRenderer`);
54
+ }
55
+ }
56
+ }
57
+ catch (err) {
58
+ // Don't double-wrap our own errors.
59
+ if (err instanceof QrError)
60
+ throw err;
61
+ throw new QrError("qr.render_failed", `qrcode failed to render ${format}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
62
+ }
63
+ }
64
+ }
65
+ //# sourceMappingURL=renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAiC,MAAM,YAAY,CAAC;AAyBpE;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAiB;IAC5B,KAAK,CAAC,MAAM,CACV,GAAW,EACX,MAAgB,EAChB,OAAkB;QAElB,MAAM,IAAI,GAAG;YACX,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,GAAG;YAC3B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC;YAC3B,oBAAoB,EAAE,OAAO,CAAC,eAAe,IAAI,GAAG;YACpD,KAAK,EAAE;gBACL,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,SAAS;gBACvC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,SAAS;aAC1C;SACO,CAAC;QAEX,IAAI,CAAC;YACH,QAAQ,MAAM,EAAE,CAAC;gBACf,KAAK,SAAS;oBACZ,OAAO,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;gBAC3C,KAAK,KAAK;oBACR,OAAO,MAAM,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC9D,KAAK,KAAK,CAAC,CAAC,CAAC;oBACX,yDAAyD;oBACzD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;oBAC7C,8DAA8D;oBAC9D,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;gBAC7B,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACR,4DAA4D;oBAC5D,4DAA4D;oBAC5D,sCAAsC;oBACtC,MAAM,WAAW,GAAU,MAAM,CAAC;oBAClC,MAAM,IAAI,OAAO,CACf,uBAAuB,EACvB,UAAU,MAAM,CAAC,WAAW,CAAC,wCAAwC,CACtE,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,oCAAoC;YACpC,IAAI,GAAG,YAAY,OAAO;gBAAE,MAAM,GAAG,CAAC;YACtC,MAAM,IAAI,OAAO,CACf,kBAAkB,EAClB,2BAA2B,MAAM,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EACxF,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,59 @@
1
+ import { GramotaError } from "@gramota/core";
2
+ /**
3
+ * Public types and the {@link QrError} class for `@gramota/qr`.
4
+ *
5
+ * These are intentionally narrow — the package's surface area is small
6
+ * (one Strategy interface, one result type, one error class). New
7
+ * variations (other output formats, decorated renderers) are added by
8
+ * implementing {@link QrRenderer} and passing it via
9
+ * {@link QrFactoryOptions.renderer}, NOT by widening these types.
10
+ */
11
+ /** Output formats a {@link QrRenderer} may be asked to produce. */
12
+ export type QrFormat = "dataUrl" | "svg" | "png";
13
+ /**
14
+ * Stable error codes for {@link QrError}. Pinned strings (not
15
+ * descriptions) so callers can branch on them in switch statements.
16
+ */
17
+ export type QrErrorCode =
18
+ /** Input wasn't a non-empty string / well-formed URL. */
19
+ "qr.invalid_url"
20
+ /** The configured {@link QrRenderer} couldn't produce the requested format. */
21
+ | "qr.render_failed"
22
+ /** The format requested isn't supported by this renderer. */
23
+ | "qr.unsupported_format";
24
+ /**
25
+ * Errors thrown anywhere in `@gramota/qr` carry one of these codes
26
+ * plus a free-form message. Caught upstream, the code is stable
27
+ * across releases — log it in audit trails, branch on it in handlers.
28
+ */
29
+ export declare class QrError extends GramotaError {
30
+ readonly code: QrErrorCode;
31
+ constructor(code: QrErrorCode, message: string, options?: {
32
+ cause?: unknown;
33
+ });
34
+ }
35
+ /**
36
+ * Layout options forwarded to the renderer. Specific renderers may
37
+ * accept additional knobs (logo embedding, custom corner shapes, …)
38
+ * via their own constructor options — these four are the universal
39
+ * subset every renderer is expected to honour.
40
+ */
41
+ export interface QrOptions {
42
+ /** Pixel width of the rendered QR. PNG uses this directly; SVG
43
+ * scales to fit. Default: 300. */
44
+ readonly width?: number;
45
+ /** Quiet-zone modules around the matrix. Default: 1. */
46
+ readonly margin?: number;
47
+ /** Foreground / background colours. CSS colour strings (e.g.
48
+ * `"#0b1220"`). Default: black on white. */
49
+ readonly colors?: {
50
+ readonly dark?: string;
51
+ readonly light?: string;
52
+ };
53
+ /** Reed-Solomon error-correction level. Higher = more redundant
54
+ * data, larger matrix, more tolerant of dirt / partial occlusion.
55
+ * Default: `"M"` (15% recovery — the QR-spec recommendation for
56
+ * general use). */
57
+ readonly errorCorrection?: "L" | "M" | "Q" | "H";
58
+ }
59
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;GAQG;AAEH,mEAAmE;AACnE,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,WAAW;AACrB,yDAAyD;AACvD,gBAAgB;AAClB,+EAA+E;GAC7E,kBAAkB;AACpB,6DAA6D;GAC3D,uBAAuB,CAAC;AAE5B;;;;GAIG;AACH,qBAAa,OAAQ,SAAQ,YAAY;IACvC,SAAkB,IAAI,EAAE,WAAW,CAAC;gBAGlC,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAMhC;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB;sCACkC;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;gDAC4C;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IACF;;;uBAGmB;IACnB,QAAQ,CAAC,eAAe,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAClD"}
package/dist/types.js ADDED
@@ -0,0 +1,15 @@
1
+ import { GramotaError } from "@gramota/core";
2
+ /**
3
+ * Errors thrown anywhere in `@gramota/qr` carry one of these codes
4
+ * plus a free-form message. Caught upstream, the code is stable
5
+ * across releases — log it in audit trails, branch on it in handlers.
6
+ */
7
+ export class QrError extends GramotaError {
8
+ code;
9
+ constructor(code, message, options) {
10
+ super(message, code, options);
11
+ this.name = "QrError";
12
+ this.code = code;
13
+ }
14
+ }
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA2B7C;;;;GAIG;AACH,MAAM,OAAO,OAAQ,SAAQ,YAAY;IACrB,IAAI,CAAc;IAEpC,YACE,IAAiB,EACjB,OAAe,EACf,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@gramota/qr",
3
+ "version": "0.3.0",
4
+ "description": "QR-code rendering for EUDIW deep links — OID4VP authorization requests and OID4VCI credential offers, with Strategy-pluggable renderers.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "qrcode": "^1.5.4",
20
+ "@gramota/core": "0.2.0",
21
+ "@gramota/oid4vci": "0.3.0",
22
+ "@gramota/oid4vp": "0.2.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/qrcode": "^1.5.6",
26
+ "vitest": "^2.1.0"
27
+ },
28
+ "author": "Petromil Pavlov <petromilpavlov@gmail.com>",
29
+ "homepage": "https://github.com/gramota-org/gramota#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/gramota-org/gramota/issues"
32
+ },
33
+ "engines": {
34
+ "node": ">=20"
35
+ },
36
+ "sideEffects": false,
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://registry.npmjs.org/"
40
+ },
41
+ "keywords": [
42
+ "qr-code",
43
+ "qr",
44
+ "openid4vp",
45
+ "oid4vci",
46
+ "credential-offer",
47
+ "verifiable-presentation",
48
+ "eudi",
49
+ "deep-link"
50
+ ],
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/gramota-org/gramota.git",
54
+ "directory": "packages/qr"
55
+ },
56
+ "scripts": {
57
+ "build": "tsc -p tsconfig.json",
58
+ "typecheck": "tsc -p tsconfig.json --noEmit"
59
+ }
60
+ }