@docknetwork/wallet-sdk-core 1.5.14 → 1.7.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.
Files changed (91) hide show
  1. package/generate-docs.js +33 -0
  2. package/jsdoc.conf.json +28 -0
  3. package/lib/biometric-provider.d.ts +123 -31
  4. package/lib/biometric-provider.d.ts.map +1 -1
  5. package/lib/biometric-provider.js +146 -7
  6. package/lib/biometric-provider.js.map +1 -1
  7. package/lib/cloud-wallet.d.ts +7 -3
  8. package/lib/cloud-wallet.d.ts.map +1 -1
  9. package/lib/cloud-wallet.js +29 -18
  10. package/lib/cloud-wallet.js.map +1 -1
  11. package/lib/credential-provider.d.ts +58 -33
  12. package/lib/credential-provider.d.ts.map +1 -1
  13. package/lib/credential-provider.js +214 -13
  14. package/lib/credential-provider.js.map +1 -1
  15. package/lib/credentials/oidvc.js +6 -7
  16. package/lib/credentials/oidvc.js.map +1 -1
  17. package/lib/did-provider.d.ts +102 -36
  18. package/lib/did-provider.d.ts.map +1 -1
  19. package/lib/did-provider.js +186 -28
  20. package/lib/did-provider.js.map +1 -1
  21. package/lib/ecosystem-tools.js +5 -6
  22. package/lib/ecosystem-tools.js.map +1 -1
  23. package/lib/helpers.js +6 -6
  24. package/lib/helpers.js.map +1 -1
  25. package/lib/message-provider.d.ts +39 -13
  26. package/lib/message-provider.d.ts.map +1 -1
  27. package/lib/message-provider.js +146 -20
  28. package/lib/message-provider.js.map +1 -1
  29. package/lib/messages/message-helpers.js +6 -6
  30. package/lib/messages/message-helpers.js.map +1 -1
  31. package/lib/network-resolver.d.ts +1 -1
  32. package/lib/network-resolver.js +5 -5
  33. package/lib/network-resolver.js.map +1 -1
  34. package/lib/qr-handlers/builtin/index.d.ts +30 -0
  35. package/lib/qr-handlers/builtin/index.d.ts.map +1 -0
  36. package/lib/qr-handlers/builtin/index.js +46 -0
  37. package/lib/qr-handlers/builtin/index.js.map +1 -0
  38. package/lib/qr-handlers/builtin/oid4vc-handler.d.ts +137 -0
  39. package/lib/qr-handlers/builtin/oid4vc-handler.d.ts.map +1 -0
  40. package/lib/qr-handlers/builtin/oid4vc-handler.js +134 -0
  41. package/lib/qr-handlers/builtin/oid4vc-handler.js.map +1 -0
  42. package/lib/qr-handlers/index.d.ts +76 -0
  43. package/lib/qr-handlers/index.d.ts.map +1 -0
  44. package/lib/qr-handlers/index.js +92 -0
  45. package/lib/qr-handlers/index.js.map +1 -0
  46. package/lib/qr-handlers/processor.d.ts +110 -0
  47. package/lib/qr-handlers/processor.d.ts.map +1 -0
  48. package/lib/qr-handlers/processor.js +251 -0
  49. package/lib/qr-handlers/processor.js.map +1 -0
  50. package/lib/qr-handlers/types.d.ts +205 -0
  51. package/lib/qr-handlers/types.d.ts.map +1 -0
  52. package/lib/qr-handlers/types.js +10 -0
  53. package/lib/qr-handlers/types.js.map +1 -0
  54. package/lib/types.d.ts +610 -14
  55. package/lib/types.d.ts.map +1 -1
  56. package/lib/types.js +16 -0
  57. package/lib/types.js.map +1 -1
  58. package/lib/verification-controller.d.ts +0 -1
  59. package/lib/verification-controller.d.ts.map +1 -1
  60. package/lib/verification-controller.js +12 -5
  61. package/lib/verification-controller.js.map +1 -1
  62. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts +0 -1
  63. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts.map +1 -1
  64. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js +3 -3
  65. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js.map +1 -1
  66. package/lib/wallet-wasm.d.ts.map +1 -1
  67. package/lib/wallet-wasm.js +13 -14
  68. package/lib/wallet-wasm.js.map +1 -1
  69. package/lib/wallet.d.ts +36 -20
  70. package/lib/wallet.d.ts.map +1 -1
  71. package/lib/wallet.js +174 -28
  72. package/lib/wallet.js.map +1 -1
  73. package/package.json +17 -9
  74. package/src/biometric-provider.ts +157 -42
  75. package/src/cloud-wallet.ts +13 -0
  76. package/src/credential-provider.test.ts +191 -1
  77. package/src/credential-provider.ts +208 -27
  78. package/src/did-provider.ts +183 -34
  79. package/src/message-provider.ts +148 -34
  80. package/src/qr-handlers/builtin/index.ts +30 -0
  81. package/src/qr-handlers/builtin/oid4vc-handler.ts +198 -0
  82. package/src/qr-handlers/index.ts +76 -0
  83. package/src/qr-handlers/processor.test.ts +514 -0
  84. package/src/qr-handlers/processor.ts +311 -0
  85. package/src/qr-handlers/types.ts +228 -0
  86. package/src/types.ts +666 -11
  87. package/src/verification-controller.test.ts +1 -2
  88. package/src/verification-controller.ts +9 -1
  89. package/src/wallet-wasm.ts +1 -3
  90. package/src/wallet.ts +173 -24
  91. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultQRCodeProcessor = void 0;
4
+ exports.createQRCodeProcessor = createQRCodeProcessor;
5
+ /**
6
+ * Default implementation of QRCodeProcessor
7
+ *
8
+ * This processor manages a registry of QR code handlers and executes them
9
+ * in priority order to process scanned QR codes. It provides a flexible,
10
+ * extensible system for handling various types of QR codes in a wallet application.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const processor = new DefaultQRCodeProcessor();
15
+ *
16
+ * // Register handlers
17
+ * processor.registerHandler(new OID4VCHandler());
18
+ * processor.registerHandler(new CredentialHandler());
19
+ *
20
+ * // Process QR code
21
+ * const result = await processor.process(scannedData);
22
+ * if (result.success) {
23
+ * console.log('QR code processed:', result.data);
24
+ * } else {
25
+ * console.error('Failed to process QR code:', result.error);
26
+ * }
27
+ * ```
28
+ */
29
+ class DefaultQRCodeProcessor {
30
+ handlers = new Map();
31
+ /**
32
+ * Register a new QR code handler
33
+ *
34
+ * @param handler - The handler to register
35
+ * @throws Error if a handler with the same ID is already registered
36
+ */
37
+ registerHandler(handler) {
38
+ if (this.handlers.has(handler.id)) {
39
+ throw new Error(`Handler with id "${handler.id}" is already registered. ` +
40
+ `Please use a unique ID or unregister the existing handler first.`);
41
+ }
42
+ this.handlers.set(handler.id, handler);
43
+ }
44
+ /**
45
+ * Unregister a QR code handler by its ID
46
+ *
47
+ * @param id - The ID of the handler to unregister
48
+ * @returns True if the handler was found and removed, false otherwise
49
+ */
50
+ unregisterHandler(id) {
51
+ return this.handlers.delete(id);
52
+ }
53
+ /**
54
+ * Get all registered handlers sorted by priority
55
+ *
56
+ * @returns Array of registered handlers sorted by priority (lowest first)
57
+ */
58
+ getHandlers() {
59
+ return Array.from(this.handlers.values()).sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
60
+ }
61
+ /**
62
+ * Get a specific handler by its ID
63
+ *
64
+ * @param id - The ID of the handler to retrieve
65
+ * @returns The handler if found, undefined otherwise
66
+ */
67
+ getHandler(id) {
68
+ return this.handlers.get(id);
69
+ }
70
+ /**
71
+ * Clear all registered handlers
72
+ */
73
+ clearHandlers() {
74
+ this.handlers.clear();
75
+ }
76
+ /**
77
+ * Process QR code data through registered handlers
78
+ *
79
+ * This method:
80
+ * 1. Prepares the context from raw QR data
81
+ * 2. Executes handlers in priority order
82
+ * 3. Returns the first successful result (or continues if stopOnFirstSuccess is false)
83
+ * 4. Returns an error result if no handler can process the data
84
+ *
85
+ * @param data - Raw QR code data string
86
+ * @param options - Processing options
87
+ * @returns Result of the processing
88
+ */
89
+ async process(data, options = {}) {
90
+ const { timeout = 30000, stopOnFirstSuccess = true, prepareContext = this.defaultPrepareContext.bind(this), onError, onSuccess, } = options;
91
+ // Prepare context from raw data
92
+ let context;
93
+ try {
94
+ context = await this.withTimeout(prepareContext(data), timeout);
95
+ }
96
+ catch (error) {
97
+ return {
98
+ success: false,
99
+ error: error instanceof Error ? error : new Error(String(error)),
100
+ metadata: { phase: 'context-preparation' },
101
+ };
102
+ }
103
+ // Get sorted handlers
104
+ const handlers = this.getHandlers();
105
+ if (handlers.length === 0) {
106
+ return {
107
+ success: false,
108
+ error: new Error('No handlers registered'),
109
+ metadata: { phase: 'handler-execution' },
110
+ };
111
+ }
112
+ let lastError;
113
+ const attemptedHandlers = [];
114
+ // Execute handlers in priority order
115
+ for (const handler of handlers) {
116
+ try {
117
+ // Check if handler can process this data
118
+ const canHandle = await this.withTimeout(Promise.resolve(handler.canHandle(context)), timeout);
119
+ if (!canHandle) {
120
+ continue;
121
+ }
122
+ attemptedHandlers.push(handler.id);
123
+ // Execute handler
124
+ const result = await this.withTimeout(handler.handle(context), timeout);
125
+ // Call success callback if provided
126
+ if (result.success && onSuccess) {
127
+ try {
128
+ onSuccess(result, handler);
129
+ }
130
+ catch (callbackError) {
131
+ console.error(`Success callback error for handler ${handler.id}:`, callbackError);
132
+ }
133
+ }
134
+ // Stop on first success if configured
135
+ if (result.success && stopOnFirstSuccess) {
136
+ return {
137
+ ...result,
138
+ metadata: {
139
+ ...result.metadata,
140
+ handlerId: handler.id,
141
+ attemptedHandlers,
142
+ },
143
+ };
144
+ }
145
+ // Store error if handler failed
146
+ if (!result.success && result.error) {
147
+ lastError = result.error;
148
+ }
149
+ }
150
+ catch (error) {
151
+ const handlerError = error instanceof Error ? error : new Error(String(error));
152
+ lastError = handlerError;
153
+ // Call error callback if provided
154
+ if (onError) {
155
+ try {
156
+ onError(handlerError, handler);
157
+ }
158
+ catch (callbackError) {
159
+ console.error(`Error callback error for handler ${handler.id}:`, callbackError);
160
+ }
161
+ }
162
+ // Continue to next handler
163
+ continue;
164
+ }
165
+ }
166
+ // No handler could process the data
167
+ return {
168
+ success: false,
169
+ error: lastError ||
170
+ new Error(`No handler could process the QR code. Attempted handlers: ${attemptedHandlers.join(', ') || 'none'}`),
171
+ metadata: {
172
+ phase: 'handler-execution',
173
+ attemptedHandlers,
174
+ },
175
+ };
176
+ }
177
+ /**
178
+ * Default context preparation function
179
+ *
180
+ * This method attempts to parse the raw QR data as JSON or URL.
181
+ * Override this by providing a custom prepareContext function in ProcessOptions.
182
+ *
183
+ * @param data - Raw QR code data string
184
+ * @returns Prepared context object
185
+ */
186
+ async defaultPrepareContext(data) {
187
+ const context = { data };
188
+ // Try to parse as URL
189
+ try {
190
+ // Basic URL validation
191
+ if (data.startsWith('http://') || data.startsWith('https://')) {
192
+ const url = new URL(data);
193
+ context.url = data;
194
+ context.parsedUrl = data;
195
+ }
196
+ }
197
+ catch {
198
+ // Not a valid URL, continue
199
+ }
200
+ // Try to parse as JSON
201
+ try {
202
+ const parsed = JSON.parse(data);
203
+ context.jsonData = parsed;
204
+ }
205
+ catch {
206
+ // Not valid JSON, continue
207
+ }
208
+ return context;
209
+ }
210
+ /**
211
+ * Execute a promise with a timeout
212
+ *
213
+ * @param promise - Promise to execute
214
+ * @param timeoutMs - Timeout in milliseconds
215
+ * @returns Result of the promise
216
+ * @throws Error if the promise times out
217
+ */
218
+ async withTimeout(promise, timeoutMs) {
219
+ return Promise.race([
220
+ promise,
221
+ new Promise((_, reject) => setTimeout(() => reject(new Error(`Operation timed out after ${timeoutMs}ms`)), timeoutMs)),
222
+ ]);
223
+ }
224
+ }
225
+ exports.DefaultQRCodeProcessor = DefaultQRCodeProcessor;
226
+ /**
227
+ * Create a new QR code processor instance
228
+ *
229
+ * This is a convenience factory function for creating a processor.
230
+ *
231
+ * @param handlers - Optional array of handlers to register immediately
232
+ * @returns New processor instance with handlers registered
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const processor = createQRCodeProcessor([
237
+ * new OID4VCHandler(),
238
+ * new CredentialHandler(),
239
+ * ]);
240
+ * ```
241
+ */
242
+ function createQRCodeProcessor(handlers) {
243
+ const processor = new DefaultQRCodeProcessor();
244
+ if (handlers) {
245
+ for (const handler of handlers) {
246
+ processor.registerHandler(handler);
247
+ }
248
+ }
249
+ return processor;
250
+ }
251
+ //# sourceMappingURL=processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.js","sourceRoot":"","sources":["../../src/qr-handlers/processor.ts"],"names":[],"mappings":";;;AA0SA,sDAYC;AA9SD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,sBAA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KAAK,CAAC,6BAA6B,SAAS,IAAI,CAAC,CAAC,EACnE,SAAS,CACV,CACF;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAxPD,wDAwPC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,qBAAqB,CACnC,QAA0B;IAE1B,MAAM,SAAS,GAAG,IAAI,sBAAsB,EAAE,CAAC;IAE/C,IAAI,QAAQ,EAAE,CAAC;QACb,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,205 @@
1
+ /**
2
+ * QR Code Handler Types
3
+ *
4
+ * This module provides interfaces and types for building a generic,
5
+ * extensible QR code handler system that can process various types
6
+ * of QR codes in a decentralized identity wallet.
7
+ */
8
+ /**
9
+ * Context object containing parsed QR code data and metadata
10
+ *
11
+ * @interface QRCodeContext
12
+ */
13
+ export interface QRCodeContext {
14
+ /**
15
+ * Raw scanned QR code data string
16
+ */
17
+ data: string;
18
+ /**
19
+ * Parsed JSON data if the QR code contained JSON,
20
+ * or data fetched from a URL if the QR code was a URL
21
+ */
22
+ jsonData?: any;
23
+ /**
24
+ * Original URL if the scanned data was a valid URL
25
+ */
26
+ url?: string;
27
+ /**
28
+ * Modified URL after processing (e.g., with authentication parameters added)
29
+ */
30
+ parsedUrl?: string;
31
+ /**
32
+ * Additional metadata that can be attached by context preparation
33
+ * or handlers for passing data between handlers
34
+ */
35
+ metadata?: Record<string, any>;
36
+ }
37
+ /**
38
+ * Result returned by a QR code handler after processing
39
+ *
40
+ * @interface QRCodeHandlerResult
41
+ */
42
+ export interface QRCodeHandlerResult {
43
+ /**
44
+ * Whether the handler successfully processed the QR code data
45
+ */
46
+ success: boolean;
47
+ /**
48
+ * Optional data returned by the handler
49
+ * Can be credentials, presentation requests, or any other processed data
50
+ */
51
+ data?: any;
52
+ /**
53
+ * Error object if processing failed
54
+ */
55
+ error?: Error;
56
+ /**
57
+ * Additional metadata about the processing result
58
+ */
59
+ metadata?: Record<string, any>;
60
+ }
61
+ /**
62
+ * Handler interface for processing specific types of QR codes
63
+ *
64
+ * Handlers are responsible for:
65
+ * 1. Identifying if they can process the QR code (canHandle)
66
+ * 2. Processing the QR code data (handle)
67
+ *
68
+ * @interface QRCodeHandler
69
+ */
70
+ export interface QRCodeHandler {
71
+ /**
72
+ * Unique identifier for this handler
73
+ * Used for registration, unregistration, and debugging
74
+ */
75
+ id: string;
76
+ /**
77
+ * Priority for handler execution (lower number = higher priority)
78
+ * Handlers are executed in priority order until one successfully handles the data
79
+ *
80
+ * @default 100
81
+ */
82
+ priority?: number;
83
+ /**
84
+ * Check if this handler can process the given QR code data
85
+ *
86
+ * This method should be fast and only do basic checks (string matching, type checking)
87
+ * without performing expensive operations like network requests.
88
+ *
89
+ * @param context - The QR code context containing parsed data
90
+ * @returns True if this handler can process the data, false otherwise
91
+ */
92
+ canHandle(context: QRCodeContext): boolean | Promise<boolean>;
93
+ /**
94
+ * Process the QR code data
95
+ *
96
+ * This method is only called if canHandle returns true.
97
+ * It should perform the actual processing logic (navigation, API calls, etc.)
98
+ *
99
+ * @param context - The QR code context containing parsed data
100
+ * @returns Result of the processing including success status and any data/errors
101
+ */
102
+ handle(context: QRCodeContext): Promise<QRCodeHandlerResult>;
103
+ }
104
+ /**
105
+ * Options for processing QR codes
106
+ *
107
+ * @interface ProcessOptions
108
+ */
109
+ export interface ProcessOptions {
110
+ /**
111
+ * Timeout in milliseconds for processing
112
+ * If a handler takes longer than this, it will be skipped
113
+ *
114
+ * @default 30000 (30 seconds)
115
+ */
116
+ timeout?: number;
117
+ /**
118
+ * Whether to stop processing after the first successful handler
119
+ * If false, all handlers will be tried even after one succeeds
120
+ *
121
+ * @default true
122
+ */
123
+ stopOnFirstSuccess?: boolean;
124
+ /**
125
+ * Custom context preparation function
126
+ *
127
+ * This function is called before any handlers to prepare the context
128
+ * from the raw scanned data. It can fetch data from URLs, parse JSON,
129
+ * add metadata, etc.
130
+ *
131
+ * @param data - Raw QR code data string
132
+ * @returns Prepared context object
133
+ */
134
+ prepareContext?: (data: string) => Promise<QRCodeContext>;
135
+ /**
136
+ * Error handler callback
137
+ *
138
+ * Called when a handler throws an error during processing.
139
+ * Useful for logging, analytics, or custom error handling.
140
+ *
141
+ * @param error - The error that was thrown
142
+ * @param handler - The handler that threw the error
143
+ */
144
+ onError?: (error: Error, handler: QRCodeHandler) => void;
145
+ /**
146
+ * Success callback
147
+ *
148
+ * Called when a handler successfully processes the QR code.
149
+ * Useful for logging, analytics, or side effects.
150
+ *
151
+ * @param result - The result returned by the handler
152
+ * @param handler - The handler that processed the data
153
+ */
154
+ onSuccess?: (result: QRCodeHandlerResult, handler: QRCodeHandler) => void;
155
+ }
156
+ /**
157
+ * Main processor interface for managing and executing QR code handlers
158
+ *
159
+ * @interface QRCodeProcessor
160
+ */
161
+ export interface QRCodeProcessor {
162
+ /**
163
+ * Register a new QR code handler
164
+ *
165
+ * @param handler - The handler to register
166
+ * @throws Error if a handler with the same ID is already registered
167
+ */
168
+ registerHandler(handler: QRCodeHandler): void;
169
+ /**
170
+ * Unregister a QR code handler by its ID
171
+ *
172
+ * @param id - The ID of the handler to unregister
173
+ * @returns True if the handler was found and removed, false otherwise
174
+ */
175
+ unregisterHandler(id: string): boolean;
176
+ /**
177
+ * Get all registered handlers sorted by priority
178
+ *
179
+ * @returns Array of registered handlers sorted by priority (lowest first)
180
+ */
181
+ getHandlers(): QRCodeHandler[];
182
+ /**
183
+ * Get a specific handler by its ID
184
+ *
185
+ * @param id - The ID of the handler to retrieve
186
+ * @returns The handler if found, undefined otherwise
187
+ */
188
+ getHandler(id: string): QRCodeHandler | undefined;
189
+ /**
190
+ * Process QR code data through registered handlers
191
+ *
192
+ * Handlers are executed in priority order until one successfully
193
+ * processes the data (or all handlers are tried if stopOnFirstSuccess is false)
194
+ *
195
+ * @param data - Raw QR code data string
196
+ * @param options - Processing options
197
+ * @returns Result of the processing
198
+ */
199
+ process(data: string, options?: ProcessOptions): Promise<QRCodeHandlerResult>;
200
+ /**
201
+ * Clear all registered handlers
202
+ */
203
+ clearHandlers(): void;
204
+ }
205
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/qr-handlers/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC;IAEX;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9D;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAE1D;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAEzD;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3E;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAE9C;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAEvC;;;;OAIG;IACH,WAAW,IAAI,aAAa,EAAE,CAAC;IAE/B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAElD;;;;;;;;;OASG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAE9E;;OAEG;IACH,aAAa,IAAI,IAAI,CAAC;CACvB"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * QR Code Handler Types
4
+ *
5
+ * This module provides interfaces and types for building a generic,
6
+ * extensible QR code handler system that can process various types
7
+ * of QR codes in a decentralized identity wallet.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/qr-handlers/types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}