@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.
- package/generate-docs.js +33 -0
- package/jsdoc.conf.json +28 -0
- package/lib/biometric-provider.d.ts +123 -31
- package/lib/biometric-provider.d.ts.map +1 -1
- package/lib/biometric-provider.js +146 -7
- package/lib/biometric-provider.js.map +1 -1
- package/lib/cloud-wallet.d.ts +7 -3
- package/lib/cloud-wallet.d.ts.map +1 -1
- package/lib/cloud-wallet.js +29 -18
- package/lib/cloud-wallet.js.map +1 -1
- package/lib/credential-provider.d.ts +58 -33
- package/lib/credential-provider.d.ts.map +1 -1
- package/lib/credential-provider.js +214 -13
- package/lib/credential-provider.js.map +1 -1
- package/lib/credentials/oidvc.js +6 -7
- package/lib/credentials/oidvc.js.map +1 -1
- package/lib/did-provider.d.ts +102 -36
- package/lib/did-provider.d.ts.map +1 -1
- package/lib/did-provider.js +186 -28
- package/lib/did-provider.js.map +1 -1
- package/lib/ecosystem-tools.js +5 -6
- package/lib/ecosystem-tools.js.map +1 -1
- package/lib/helpers.js +6 -6
- package/lib/helpers.js.map +1 -1
- package/lib/message-provider.d.ts +39 -13
- package/lib/message-provider.d.ts.map +1 -1
- package/lib/message-provider.js +146 -20
- package/lib/message-provider.js.map +1 -1
- package/lib/messages/message-helpers.js +6 -6
- package/lib/messages/message-helpers.js.map +1 -1
- package/lib/network-resolver.d.ts +1 -1
- package/lib/network-resolver.js +5 -5
- package/lib/network-resolver.js.map +1 -1
- package/lib/qr-handlers/builtin/index.d.ts +30 -0
- package/lib/qr-handlers/builtin/index.d.ts.map +1 -0
- package/lib/qr-handlers/builtin/index.js +46 -0
- package/lib/qr-handlers/builtin/index.js.map +1 -0
- package/lib/qr-handlers/builtin/oid4vc-handler.d.ts +137 -0
- package/lib/qr-handlers/builtin/oid4vc-handler.d.ts.map +1 -0
- package/lib/qr-handlers/builtin/oid4vc-handler.js +134 -0
- package/lib/qr-handlers/builtin/oid4vc-handler.js.map +1 -0
- package/lib/qr-handlers/index.d.ts +76 -0
- package/lib/qr-handlers/index.d.ts.map +1 -0
- package/lib/qr-handlers/index.js +92 -0
- package/lib/qr-handlers/index.js.map +1 -0
- package/lib/qr-handlers/processor.d.ts +110 -0
- package/lib/qr-handlers/processor.d.ts.map +1 -0
- package/lib/qr-handlers/processor.js +251 -0
- package/lib/qr-handlers/processor.js.map +1 -0
- package/lib/qr-handlers/types.d.ts +205 -0
- package/lib/qr-handlers/types.d.ts.map +1 -0
- package/lib/qr-handlers/types.js +10 -0
- package/lib/qr-handlers/types.js.map +1 -0
- package/lib/types.d.ts +610 -14
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +16 -0
- package/lib/types.js.map +1 -1
- package/lib/verification-controller.d.ts +0 -1
- package/lib/verification-controller.d.ts.map +1 -1
- package/lib/verification-controller.js +12 -5
- package/lib/verification-controller.js.map +1 -1
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts +0 -1
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts.map +1 -1
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js +3 -3
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js.map +1 -1
- package/lib/wallet-wasm.d.ts.map +1 -1
- package/lib/wallet-wasm.js +13 -14
- package/lib/wallet-wasm.js.map +1 -1
- package/lib/wallet.d.ts +36 -20
- package/lib/wallet.d.ts.map +1 -1
- package/lib/wallet.js +174 -28
- package/lib/wallet.js.map +1 -1
- package/package.json +17 -9
- package/src/biometric-provider.ts +157 -42
- package/src/cloud-wallet.ts +13 -0
- package/src/credential-provider.test.ts +191 -1
- package/src/credential-provider.ts +208 -27
- package/src/did-provider.ts +183 -34
- package/src/message-provider.ts +148 -34
- package/src/qr-handlers/builtin/index.ts +30 -0
- package/src/qr-handlers/builtin/oid4vc-handler.ts +198 -0
- package/src/qr-handlers/index.ts +76 -0
- package/src/qr-handlers/processor.test.ts +514 -0
- package/src/qr-handlers/processor.ts +311 -0
- package/src/qr-handlers/types.ts +228 -0
- package/src/types.ts +666 -11
- package/src/verification-controller.test.ts +1 -2
- package/src/verification-controller.ts +9 -1
- package/src/wallet-wasm.ts +1 -3
- package/src/wallet.ts +173 -24
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
QRCodeContext,
|
|
3
|
+
QRCodeHandler,
|
|
4
|
+
QRCodeHandlerResult,
|
|
5
|
+
} from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for OID4VC handler
|
|
9
|
+
*/
|
|
10
|
+
export interface OID4VCHandlerConfig {
|
|
11
|
+
/**
|
|
12
|
+
* URI prefixes to match (default: ['openid-credential-offer://'])
|
|
13
|
+
*/
|
|
14
|
+
uriPrefixes?: string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Priority for this handler (default: 5)
|
|
18
|
+
*/
|
|
19
|
+
priority?: number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Callback to handle credential import
|
|
23
|
+
* This is where app-specific logic (navigation, UI, etc.) should be implemented
|
|
24
|
+
*
|
|
25
|
+
* @param uri - The OID4VC URI to process
|
|
26
|
+
* @param context - The full QR code context
|
|
27
|
+
* @returns Result of the import operation
|
|
28
|
+
*/
|
|
29
|
+
onImportCredential: (
|
|
30
|
+
uri: string,
|
|
31
|
+
context: QRCodeContext,
|
|
32
|
+
) => Promise<OID4VCImportResult>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Result from importing an OID4VC credential
|
|
37
|
+
*/
|
|
38
|
+
export interface OID4VCImportResult {
|
|
39
|
+
/**
|
|
40
|
+
* Whether the import was successful
|
|
41
|
+
*/
|
|
42
|
+
success: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Credential data if import succeeded
|
|
46
|
+
*/
|
|
47
|
+
credential?: any;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Error if import failed
|
|
51
|
+
*/
|
|
52
|
+
error?: Error;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Additional metadata
|
|
56
|
+
*/
|
|
57
|
+
metadata?: Record<string, any>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Built-in handler for OID4VC (OpenID for Verifiable Credentials) URIs
|
|
62
|
+
*
|
|
63
|
+
* This is a generic handler that can be configured with app-specific callbacks
|
|
64
|
+
* for importing credentials. The handler itself only handles protocol detection
|
|
65
|
+
* and delegates the actual import logic to the configured callback.
|
|
66
|
+
*
|
|
67
|
+
* ## Example Usage
|
|
68
|
+
*
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { OID4VCHandler } from '@docknetwork/wallet-sdk-core/src/qr-handlers/builtin';
|
|
71
|
+
* import { getCredentialProvider } from '@docknetwork/wallet-sdk-react-native';
|
|
72
|
+
*
|
|
73
|
+
* const handler = new OID4VCHandler({
|
|
74
|
+
* onImportCredential: async (uri, context) => {
|
|
75
|
+
* try {
|
|
76
|
+
* // Use SDK to import credential
|
|
77
|
+
* await getCredentialProvider().importCredentialFromURI({
|
|
78
|
+
* uri,
|
|
79
|
+
* didProvider: getDIDProvider(),
|
|
80
|
+
* getAuthCode: async (authUrl) => {
|
|
81
|
+
* // App-specific auth handling
|
|
82
|
+
* return await showAuthWebView(authUrl);
|
|
83
|
+
* },
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* return { success: true };
|
|
87
|
+
* } catch (error) {
|
|
88
|
+
* return {
|
|
89
|
+
* success: false,
|
|
90
|
+
* error: error instanceof Error ? error : new Error(String(error)),
|
|
91
|
+
* };
|
|
92
|
+
* }
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* processor.registerHandler(handler);
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* ## Handler Priority
|
|
100
|
+
*
|
|
101
|
+
* Default priority: 5 (very high)
|
|
102
|
+
* This ensures OID4VC URIs are checked before other credential handlers.
|
|
103
|
+
*
|
|
104
|
+
* @category Built-in Handlers
|
|
105
|
+
*/
|
|
106
|
+
export class OID4VCHandler implements QRCodeHandler {
|
|
107
|
+
id = 'oid4vc';
|
|
108
|
+
priority: number;
|
|
109
|
+
|
|
110
|
+
private uriPrefixes: string[];
|
|
111
|
+
private onImportCredential: (
|
|
112
|
+
uri: string,
|
|
113
|
+
context: QRCodeContext,
|
|
114
|
+
) => Promise<OID4VCImportResult>;
|
|
115
|
+
|
|
116
|
+
constructor(config: OID4VCHandlerConfig) {
|
|
117
|
+
if (!config.onImportCredential) {
|
|
118
|
+
throw new Error('onImportCredential callback is required');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.priority = config.priority ?? 5;
|
|
122
|
+
this.uriPrefixes = config.uriPrefixes ?? ['openid-credential-offer://'];
|
|
123
|
+
this.onImportCredential = config.onImportCredential;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if this is an OID4VC URI
|
|
128
|
+
*
|
|
129
|
+
* Matches URIs that start with any of the configured prefixes.
|
|
130
|
+
* By default, matches: openid-credential-offer://
|
|
131
|
+
*
|
|
132
|
+
* @param context - The QR code context
|
|
133
|
+
* @returns True if this handler can process the URI
|
|
134
|
+
*/
|
|
135
|
+
canHandle(context: QRCodeContext): boolean {
|
|
136
|
+
return this.uriPrefixes.some(prefix => context.data.startsWith(prefix));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Process the OID4VC credential offer URI
|
|
141
|
+
*
|
|
142
|
+
* Delegates to the configured onImportCredential callback for actual processing.
|
|
143
|
+
* This allows apps to implement their own navigation, UI, and error handling.
|
|
144
|
+
*
|
|
145
|
+
* @param context - The QR code context
|
|
146
|
+
* @returns Result of the processing
|
|
147
|
+
*/
|
|
148
|
+
async handle(context: QRCodeContext): Promise<QRCodeHandlerResult> {
|
|
149
|
+
try {
|
|
150
|
+
const result = await this.onImportCredential(context.data, context);
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
success: result.success,
|
|
154
|
+
data: result.credential,
|
|
155
|
+
error: result.error,
|
|
156
|
+
metadata: {
|
|
157
|
+
type: 'oid4vc',
|
|
158
|
+
uri: context.data,
|
|
159
|
+
...result.metadata,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
} catch (error) {
|
|
163
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
164
|
+
return {
|
|
165
|
+
success: false,
|
|
166
|
+
error: err,
|
|
167
|
+
metadata: {
|
|
168
|
+
type: 'oid4vc',
|
|
169
|
+
uri: context.data,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Create an OID4VC handler with custom configuration
|
|
178
|
+
*
|
|
179
|
+
* This is a convenience factory function for creating an OID4VC handler.
|
|
180
|
+
*
|
|
181
|
+
* @param config - Handler configuration
|
|
182
|
+
* @returns Configured OID4VC handler
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const handler = createOID4VCHandler({
|
|
187
|
+
* onImportCredential: async (uri) => {
|
|
188
|
+
* // Your import logic
|
|
189
|
+
* return { success: true };
|
|
190
|
+
* },
|
|
191
|
+
* });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export function createOID4VCHandler(
|
|
195
|
+
config: OID4VCHandlerConfig,
|
|
196
|
+
): OID4VCHandler {
|
|
197
|
+
return new OID4VCHandler(config);
|
|
198
|
+
}
|
|
@@ -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
|
+
|
|
74
|
+
export * from './types';
|
|
75
|
+
export * from './processor';
|
|
76
|
+
export * from './builtin';
|