@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,137 @@
1
+ import { QRCodeContext, QRCodeHandler, QRCodeHandlerResult } from '../types';
2
+ /**
3
+ * Configuration options for OID4VC handler
4
+ */
5
+ export interface OID4VCHandlerConfig {
6
+ /**
7
+ * URI prefixes to match (default: ['openid-credential-offer://'])
8
+ */
9
+ uriPrefixes?: string[];
10
+ /**
11
+ * Priority for this handler (default: 5)
12
+ */
13
+ priority?: number;
14
+ /**
15
+ * Callback to handle credential import
16
+ * This is where app-specific logic (navigation, UI, etc.) should be implemented
17
+ *
18
+ * @param uri - The OID4VC URI to process
19
+ * @param context - The full QR code context
20
+ * @returns Result of the import operation
21
+ */
22
+ onImportCredential: (uri: string, context: QRCodeContext) => Promise<OID4VCImportResult>;
23
+ }
24
+ /**
25
+ * Result from importing an OID4VC credential
26
+ */
27
+ export interface OID4VCImportResult {
28
+ /**
29
+ * Whether the import was successful
30
+ */
31
+ success: boolean;
32
+ /**
33
+ * Credential data if import succeeded
34
+ */
35
+ credential?: any;
36
+ /**
37
+ * Error if import failed
38
+ */
39
+ error?: Error;
40
+ /**
41
+ * Additional metadata
42
+ */
43
+ metadata?: Record<string, any>;
44
+ }
45
+ /**
46
+ * Built-in handler for OID4VC (OpenID for Verifiable Credentials) URIs
47
+ *
48
+ * This is a generic handler that can be configured with app-specific callbacks
49
+ * for importing credentials. The handler itself only handles protocol detection
50
+ * and delegates the actual import logic to the configured callback.
51
+ *
52
+ * ## Example Usage
53
+ *
54
+ * ```typescript
55
+ * import { OID4VCHandler } from '@docknetwork/wallet-sdk-core/src/qr-handlers/builtin';
56
+ * import { getCredentialProvider } from '@docknetwork/wallet-sdk-react-native';
57
+ *
58
+ * const handler = new OID4VCHandler({
59
+ * onImportCredential: async (uri, context) => {
60
+ * try {
61
+ * // Use SDK to import credential
62
+ * await getCredentialProvider().importCredentialFromURI({
63
+ * uri,
64
+ * didProvider: getDIDProvider(),
65
+ * getAuthCode: async (authUrl) => {
66
+ * // App-specific auth handling
67
+ * return await showAuthWebView(authUrl);
68
+ * },
69
+ * });
70
+ *
71
+ * return { success: true };
72
+ * } catch (error) {
73
+ * return {
74
+ * success: false,
75
+ * error: error instanceof Error ? error : new Error(String(error)),
76
+ * };
77
+ * }
78
+ * },
79
+ * });
80
+ *
81
+ * processor.registerHandler(handler);
82
+ * ```
83
+ *
84
+ * ## Handler Priority
85
+ *
86
+ * Default priority: 5 (very high)
87
+ * This ensures OID4VC URIs are checked before other credential handlers.
88
+ *
89
+ * @category Built-in Handlers
90
+ */
91
+ export declare class OID4VCHandler implements QRCodeHandler {
92
+ id: string;
93
+ priority: number;
94
+ private uriPrefixes;
95
+ private onImportCredential;
96
+ constructor(config: OID4VCHandlerConfig);
97
+ /**
98
+ * Check if this is an OID4VC URI
99
+ *
100
+ * Matches URIs that start with any of the configured prefixes.
101
+ * By default, matches: openid-credential-offer://
102
+ *
103
+ * @param context - The QR code context
104
+ * @returns True if this handler can process the URI
105
+ */
106
+ canHandle(context: QRCodeContext): boolean;
107
+ /**
108
+ * Process the OID4VC credential offer URI
109
+ *
110
+ * Delegates to the configured onImportCredential callback for actual processing.
111
+ * This allows apps to implement their own navigation, UI, and error handling.
112
+ *
113
+ * @param context - The QR code context
114
+ * @returns Result of the processing
115
+ */
116
+ handle(context: QRCodeContext): Promise<QRCodeHandlerResult>;
117
+ }
118
+ /**
119
+ * Create an OID4VC handler with custom configuration
120
+ *
121
+ * This is a convenience factory function for creating an OID4VC handler.
122
+ *
123
+ * @param config - Handler configuration
124
+ * @returns Configured OID4VC handler
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const handler = createOID4VCHandler({
129
+ * onImportCredential: async (uri) => {
130
+ * // Your import logic
131
+ * return { success: true };
132
+ * },
133
+ * });
134
+ * ```
135
+ */
136
+ export declare function createOID4VCHandler(config: OID4VCHandlerConfig): OID4VCHandler;
137
+ //# sourceMappingURL=oid4vc-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oid4vc-handler.d.ts","sourceRoot":"","sources":["../../../src/qr-handlers/builtin/oid4vc-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;;OAOG;IACH,kBAAkB,EAAE,CAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE,GAAG,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,aAAc,YAAW,aAAa;IACjD,EAAE,SAAY;IACd,QAAQ,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,kBAAkB,CAGO;gBAErB,MAAM,EAAE,mBAAmB;IAUvC;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;IAI1C;;;;;;;;OAQG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA0BnE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,mBAAmB,GAC1B,aAAa,CAEf"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OID4VCHandler = void 0;
4
+ exports.createOID4VCHandler = createOID4VCHandler;
5
+ /**
6
+ * Built-in handler for OID4VC (OpenID for Verifiable Credentials) URIs
7
+ *
8
+ * This is a generic handler that can be configured with app-specific callbacks
9
+ * for importing credentials. The handler itself only handles protocol detection
10
+ * and delegates the actual import logic to the configured callback.
11
+ *
12
+ * ## Example Usage
13
+ *
14
+ * ```typescript
15
+ * import { OID4VCHandler } from '@docknetwork/wallet-sdk-core/src/qr-handlers/builtin';
16
+ * import { getCredentialProvider } from '@docknetwork/wallet-sdk-react-native';
17
+ *
18
+ * const handler = new OID4VCHandler({
19
+ * onImportCredential: async (uri, context) => {
20
+ * try {
21
+ * // Use SDK to import credential
22
+ * await getCredentialProvider().importCredentialFromURI({
23
+ * uri,
24
+ * didProvider: getDIDProvider(),
25
+ * getAuthCode: async (authUrl) => {
26
+ * // App-specific auth handling
27
+ * return await showAuthWebView(authUrl);
28
+ * },
29
+ * });
30
+ *
31
+ * return { success: true };
32
+ * } catch (error) {
33
+ * return {
34
+ * success: false,
35
+ * error: error instanceof Error ? error : new Error(String(error)),
36
+ * };
37
+ * }
38
+ * },
39
+ * });
40
+ *
41
+ * processor.registerHandler(handler);
42
+ * ```
43
+ *
44
+ * ## Handler Priority
45
+ *
46
+ * Default priority: 5 (very high)
47
+ * This ensures OID4VC URIs are checked before other credential handlers.
48
+ *
49
+ * @category Built-in Handlers
50
+ */
51
+ class OID4VCHandler {
52
+ id = 'oid4vc';
53
+ priority;
54
+ uriPrefixes;
55
+ onImportCredential;
56
+ constructor(config) {
57
+ if (!config.onImportCredential) {
58
+ throw new Error('onImportCredential callback is required');
59
+ }
60
+ this.priority = config.priority ?? 5;
61
+ this.uriPrefixes = config.uriPrefixes ?? ['openid-credential-offer://'];
62
+ this.onImportCredential = config.onImportCredential;
63
+ }
64
+ /**
65
+ * Check if this is an OID4VC URI
66
+ *
67
+ * Matches URIs that start with any of the configured prefixes.
68
+ * By default, matches: openid-credential-offer://
69
+ *
70
+ * @param context - The QR code context
71
+ * @returns True if this handler can process the URI
72
+ */
73
+ canHandle(context) {
74
+ return this.uriPrefixes.some(prefix => context.data.startsWith(prefix));
75
+ }
76
+ /**
77
+ * Process the OID4VC credential offer URI
78
+ *
79
+ * Delegates to the configured onImportCredential callback for actual processing.
80
+ * This allows apps to implement their own navigation, UI, and error handling.
81
+ *
82
+ * @param context - The QR code context
83
+ * @returns Result of the processing
84
+ */
85
+ async handle(context) {
86
+ try {
87
+ const result = await this.onImportCredential(context.data, context);
88
+ return {
89
+ success: result.success,
90
+ data: result.credential,
91
+ error: result.error,
92
+ metadata: {
93
+ type: 'oid4vc',
94
+ uri: context.data,
95
+ ...result.metadata,
96
+ },
97
+ };
98
+ }
99
+ catch (error) {
100
+ const err = error instanceof Error ? error : new Error(String(error));
101
+ return {
102
+ success: false,
103
+ error: err,
104
+ metadata: {
105
+ type: 'oid4vc',
106
+ uri: context.data,
107
+ },
108
+ };
109
+ }
110
+ }
111
+ }
112
+ exports.OID4VCHandler = OID4VCHandler;
113
+ /**
114
+ * Create an OID4VC handler with custom configuration
115
+ *
116
+ * This is a convenience factory function for creating an OID4VC handler.
117
+ *
118
+ * @param config - Handler configuration
119
+ * @returns Configured OID4VC handler
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const handler = createOID4VCHandler({
124
+ * onImportCredential: async (uri) => {
125
+ * // Your import logic
126
+ * return { success: true };
127
+ * },
128
+ * });
129
+ * ```
130
+ */
131
+ function createOID4VCHandler(config) {
132
+ return new OID4VCHandler(config);
133
+ }
134
+ //# sourceMappingURL=oid4vc-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oid4vc-handler.js","sourceRoot":"","sources":["../../../src/qr-handlers/builtin/oid4vc-handler.ts"],"names":[],"mappings":";;;AAiMA,kDAIC;AA1ID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAa,aAAa;IACxB,EAAE,GAAG,QAAQ,CAAC;IACd,QAAQ,CAAS;IAET,WAAW,CAAW;IACtB,kBAAkB,CAGO;IAEjC,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACxE,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;IACtD,CAAC;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAsB;QAC9B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,CAAC,OAAsB;QACjC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAEpE,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,IAAI,EAAE,MAAM,CAAC,UAAU;gBACvB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,GAAG,EAAE,OAAO,CAAC,IAAI;oBACjB,GAAG,MAAM,CAAC,QAAQ;iBACnB;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACtE,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,GAAG,EAAE,OAAO,CAAC,IAAI;iBAClB;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AApED,sCAoEC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,mBAAmB,CACjC,MAA2B;IAE3B,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * QR Code Handler System
3
+ *
4
+ * This module provides a generic, extensible system for processing QR codes
5
+ * in decentralized identity wallet applications.
6
+ *
7
+ * ## Overview
8
+ *
9
+ * The QR handler system is built around these core concepts:
10
+ *
11
+ * - **QRCodeContext**: Contains parsed QR data (raw string, JSON, URLs)
12
+ * - **QRCodeHandler**: Interface for implementing specific QR code processors
13
+ * - **QRCodeProcessor**: Manages handler registration and execution
14
+ * - **ProcessOptions**: Configuration for how QR codes are processed
15
+ *
16
+ * ## Basic Usage
17
+ *
18
+ * ```typescript
19
+ * import { createQRCodeProcessor } from '@docknetwork/wallet-sdk-core';
20
+ *
21
+ * // Create processor
22
+ * const processor = createQRCodeProcessor();
23
+ *
24
+ * // Register handlers
25
+ * processor.registerHandler({
26
+ * id: 'my-handler',
27
+ * priority: 10,
28
+ * canHandle: (context) => context.data.startsWith('myprotocol://'),
29
+ * handle: async (context) => {
30
+ * // Process the QR code
31
+ * return { success: true };
32
+ * }
33
+ * });
34
+ *
35
+ * // Process QR code
36
+ * const result = await processor.process(scannedData);
37
+ * ```
38
+ *
39
+ * ## Custom Handlers
40
+ *
41
+ * Handlers can be implemented as classes or objects:
42
+ *
43
+ * ```typescript
44
+ * class MyCustomHandler implements QRCodeHandler {
45
+ * id = 'my-custom-handler';
46
+ * priority = 20;
47
+ *
48
+ * canHandle(context: QRCodeContext): boolean {
49
+ * return context.jsonData?.type === 'my-type';
50
+ * }
51
+ *
52
+ * async handle(context: QRCodeContext): Promise<QRCodeHandlerResult> {
53
+ * // Your processing logic
54
+ * return { success: true, data: processedData };
55
+ * }
56
+ * }
57
+ *
58
+ * processor.registerHandler(new MyCustomHandler());
59
+ * ```
60
+ *
61
+ * ## Built-in Handlers
62
+ *
63
+ * The SDK provides built-in handlers for common protocols:
64
+ * - OID4VC (OpenID for Verifiable Credentials)
65
+ * - OID4VP (OpenID for Verifiable Presentations)
66
+ * - DIDComm (Decentralized Identity Communication)
67
+ *
68
+ * These handlers are available in separate modules and can be imported
69
+ * and registered as needed.
70
+ *
71
+ * @module qr-handlers
72
+ */
73
+ export * from './types';
74
+ export * from './processor';
75
+ export * from './builtin';
76
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/qr-handlers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ /**
3
+ * QR Code Handler System
4
+ *
5
+ * This module provides a generic, extensible system for processing QR codes
6
+ * in decentralized identity wallet applications.
7
+ *
8
+ * ## Overview
9
+ *
10
+ * The QR handler system is built around these core concepts:
11
+ *
12
+ * - **QRCodeContext**: Contains parsed QR data (raw string, JSON, URLs)
13
+ * - **QRCodeHandler**: Interface for implementing specific QR code processors
14
+ * - **QRCodeProcessor**: Manages handler registration and execution
15
+ * - **ProcessOptions**: Configuration for how QR codes are processed
16
+ *
17
+ * ## Basic Usage
18
+ *
19
+ * ```typescript
20
+ * import { createQRCodeProcessor } from '@docknetwork/wallet-sdk-core';
21
+ *
22
+ * // Create processor
23
+ * const processor = createQRCodeProcessor();
24
+ *
25
+ * // Register handlers
26
+ * processor.registerHandler({
27
+ * id: 'my-handler',
28
+ * priority: 10,
29
+ * canHandle: (context) => context.data.startsWith('myprotocol://'),
30
+ * handle: async (context) => {
31
+ * // Process the QR code
32
+ * return { success: true };
33
+ * }
34
+ * });
35
+ *
36
+ * // Process QR code
37
+ * const result = await processor.process(scannedData);
38
+ * ```
39
+ *
40
+ * ## Custom Handlers
41
+ *
42
+ * Handlers can be implemented as classes or objects:
43
+ *
44
+ * ```typescript
45
+ * class MyCustomHandler implements QRCodeHandler {
46
+ * id = 'my-custom-handler';
47
+ * priority = 20;
48
+ *
49
+ * canHandle(context: QRCodeContext): boolean {
50
+ * return context.jsonData?.type === 'my-type';
51
+ * }
52
+ *
53
+ * async handle(context: QRCodeContext): Promise<QRCodeHandlerResult> {
54
+ * // Your processing logic
55
+ * return { success: true, data: processedData };
56
+ * }
57
+ * }
58
+ *
59
+ * processor.registerHandler(new MyCustomHandler());
60
+ * ```
61
+ *
62
+ * ## Built-in Handlers
63
+ *
64
+ * The SDK provides built-in handlers for common protocols:
65
+ * - OID4VC (OpenID for Verifiable Credentials)
66
+ * - OID4VP (OpenID for Verifiable Presentations)
67
+ * - DIDComm (Decentralized Identity Communication)
68
+ *
69
+ * These handlers are available in separate modules and can be imported
70
+ * and registered as needed.
71
+ *
72
+ * @module qr-handlers
73
+ */
74
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
75
+ if (k2 === undefined) k2 = k;
76
+ var desc = Object.getOwnPropertyDescriptor(m, k);
77
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
78
+ desc = { enumerable: true, get: function() { return m[k]; } };
79
+ }
80
+ Object.defineProperty(o, k2, desc);
81
+ }) : (function(o, m, k, k2) {
82
+ if (k2 === undefined) k2 = k;
83
+ o[k2] = m[k];
84
+ }));
85
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
86
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
87
+ };
88
+ Object.defineProperty(exports, "__esModule", { value: true });
89
+ __exportStar(require("./types"), exports);
90
+ __exportStar(require("./processor"), exports);
91
+ __exportStar(require("./builtin"), exports);
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/qr-handlers/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,8CAA4B;AAC5B,4CAA0B"}
@@ -0,0 +1,110 @@
1
+ import { QRCodeHandler, QRCodeHandlerResult, QRCodeProcessor, ProcessOptions } from './types';
2
+ /**
3
+ * Default implementation of QRCodeProcessor
4
+ *
5
+ * This processor manages a registry of QR code handlers and executes them
6
+ * in priority order to process scanned QR codes. It provides a flexible,
7
+ * extensible system for handling various types of QR codes in a wallet application.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const processor = new DefaultQRCodeProcessor();
12
+ *
13
+ * // Register handlers
14
+ * processor.registerHandler(new OID4VCHandler());
15
+ * processor.registerHandler(new CredentialHandler());
16
+ *
17
+ * // Process QR code
18
+ * const result = await processor.process(scannedData);
19
+ * if (result.success) {
20
+ * console.log('QR code processed:', result.data);
21
+ * } else {
22
+ * console.error('Failed to process QR code:', result.error);
23
+ * }
24
+ * ```
25
+ */
26
+ export declare class DefaultQRCodeProcessor implements QRCodeProcessor {
27
+ private handlers;
28
+ /**
29
+ * Register a new QR code handler
30
+ *
31
+ * @param handler - The handler to register
32
+ * @throws Error if a handler with the same ID is already registered
33
+ */
34
+ registerHandler(handler: QRCodeHandler): void;
35
+ /**
36
+ * Unregister a QR code handler by its ID
37
+ *
38
+ * @param id - The ID of the handler to unregister
39
+ * @returns True if the handler was found and removed, false otherwise
40
+ */
41
+ unregisterHandler(id: string): boolean;
42
+ /**
43
+ * Get all registered handlers sorted by priority
44
+ *
45
+ * @returns Array of registered handlers sorted by priority (lowest first)
46
+ */
47
+ getHandlers(): QRCodeHandler[];
48
+ /**
49
+ * Get a specific handler by its ID
50
+ *
51
+ * @param id - The ID of the handler to retrieve
52
+ * @returns The handler if found, undefined otherwise
53
+ */
54
+ getHandler(id: string): QRCodeHandler | undefined;
55
+ /**
56
+ * Clear all registered handlers
57
+ */
58
+ clearHandlers(): void;
59
+ /**
60
+ * Process QR code data through registered handlers
61
+ *
62
+ * This method:
63
+ * 1. Prepares the context from raw QR data
64
+ * 2. Executes handlers in priority order
65
+ * 3. Returns the first successful result (or continues if stopOnFirstSuccess is false)
66
+ * 4. Returns an error result if no handler can process the data
67
+ *
68
+ * @param data - Raw QR code data string
69
+ * @param options - Processing options
70
+ * @returns Result of the processing
71
+ */
72
+ process(data: string, options?: ProcessOptions): Promise<QRCodeHandlerResult>;
73
+ /**
74
+ * Default context preparation function
75
+ *
76
+ * This method attempts to parse the raw QR data as JSON or URL.
77
+ * Override this by providing a custom prepareContext function in ProcessOptions.
78
+ *
79
+ * @param data - Raw QR code data string
80
+ * @returns Prepared context object
81
+ */
82
+ private defaultPrepareContext;
83
+ /**
84
+ * Execute a promise with a timeout
85
+ *
86
+ * @param promise - Promise to execute
87
+ * @param timeoutMs - Timeout in milliseconds
88
+ * @returns Result of the promise
89
+ * @throws Error if the promise times out
90
+ */
91
+ private withTimeout;
92
+ }
93
+ /**
94
+ * Create a new QR code processor instance
95
+ *
96
+ * This is a convenience factory function for creating a processor.
97
+ *
98
+ * @param handlers - Optional array of handlers to register immediately
99
+ * @returns New processor instance with handlers registered
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const processor = createQRCodeProcessor([
104
+ * new OID4VCHandler(),
105
+ * new CredentialHandler(),
106
+ * ]);
107
+ * ```
108
+ */
109
+ export declare function createQRCodeProcessor(handlers?: QRCodeHandler[]): QRCodeProcessor;
110
+ //# sourceMappingURL=processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../../src/qr-handlers/processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,QAAQ,CAAyC;IAEzD;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAU7C;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAItC;;;;OAIG;IACH,WAAW,IAAI,aAAa,EAAE;IAM9B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAIjD;;OAEG;IACH,aAAa,IAAI,IAAI;IAIrB;;;;;;;;;;;;OAYG;IACG,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IAsH/B;;;;;;;;OAQG;YACW,qBAAqB;IA0BnC;;;;;;;OAOG;YACW,WAAW;CAc1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,CAAC,EAAE,aAAa,EAAE,GACzB,eAAe,CAUjB"}