@eudi-verify/client 0.1.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.
@@ -0,0 +1,335 @@
1
+ /**
2
+ * @eudi-verify/client - Shared Types
3
+ *
4
+ * Re-exported types from the server package for client-side use.
5
+ * These types define the contract between client and server.
6
+ */
7
+ /**
8
+ * Claims that can be requested from an EUDI Wallet.
9
+ * Each property set to `true` requests that specific claim.
10
+ */
11
+ interface VerificationRequest {
12
+ age_over_18?: true;
13
+ age_over_21?: true;
14
+ nationality?: true;
15
+ given_name?: true;
16
+ family_name?: true;
17
+ birth_date?: true;
18
+ [key: string]: true | undefined;
19
+ }
20
+ /**
21
+ * Session lifecycle states.
22
+ */
23
+ type SessionStatus = 'pending' | 'waiting_for_wallet' | 'verified' | 'rejected' | 'expired' | 'cancelled' | 'error';
24
+ /**
25
+ * Terminal states that cannot transition further.
26
+ */
27
+ declare const TERMINAL_STATUSES: readonly SessionStatus[];
28
+ /**
29
+ * Check if a status is terminal (cannot transition).
30
+ */
31
+ declare function isTerminalStatus(status: SessionStatus): boolean;
32
+ /**
33
+ * Claims extracted from a verified presentation.
34
+ */
35
+ interface VerifiedClaims {
36
+ age_over_18?: boolean;
37
+ age_over_21?: boolean;
38
+ nationality?: string;
39
+ given_name?: string;
40
+ family_name?: string;
41
+ birth_date?: string;
42
+ [key: string]: unknown;
43
+ }
44
+ /**
45
+ * Session as returned by the API.
46
+ */
47
+ interface Session {
48
+ id: string;
49
+ status: SessionStatus;
50
+ qrUrl?: string;
51
+ token?: string;
52
+ claims?: VerifiedClaims;
53
+ error?: string;
54
+ createdAt: string;
55
+ expiresAt: string;
56
+ }
57
+ /**
58
+ * API error response.
59
+ */
60
+ interface ApiError {
61
+ error: string;
62
+ message: string;
63
+ details?: Record<string, unknown>;
64
+ }
65
+
66
+ /**
67
+ * @eudi-verify/client - Polling Utility
68
+ *
69
+ * Exponential backoff polling with configurable intervals.
70
+ */
71
+ /**
72
+ * Configuration for the poller.
73
+ */
74
+ interface PollingConfig {
75
+ /** Initial interval in milliseconds (default: 1000) */
76
+ initialIntervalMs?: number;
77
+ /** Maximum interval in milliseconds (default: 10000) */
78
+ maxIntervalMs?: number;
79
+ /** Backoff multiplier (default: 2) */
80
+ backoffMultiplier?: number;
81
+ }
82
+ /**
83
+ * Poller instance returned by createPoller.
84
+ */
85
+ interface Poller {
86
+ /** Start polling */
87
+ start(): void;
88
+ /** Stop polling */
89
+ stop(): void;
90
+ /** Reset interval to initial value */
91
+ reset(): void;
92
+ }
93
+ /**
94
+ * Create an exponential backoff poller.
95
+ *
96
+ * @param fn - Function to call on each poll. Returns true to stop polling.
97
+ * @param config - Polling configuration.
98
+ * @returns Poller instance with start/stop/reset methods.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const poller = createPoller(async () => {
103
+ * const result = await checkStatus();
104
+ * return result.complete; // true stops polling
105
+ * });
106
+ *
107
+ * poller.start();
108
+ * // ... later
109
+ * poller.stop();
110
+ * ```
111
+ */
112
+ declare function createPoller(fn: () => Promise<boolean>, config?: PollingConfig): Poller;
113
+
114
+ /**
115
+ * @eudi-verify/client - QR Code Generator
116
+ *
117
+ * Minimal QR code generation for OpenID4VP URLs.
118
+ * Implements ISO/IEC 18004 (QR Code) with byte mode encoding.
119
+ */
120
+ interface QRCodeOptions {
121
+ /** Size in pixels (default: 200) */
122
+ size?: number;
123
+ /** Error correction level (default: 'M') */
124
+ errorCorrection?: 'L' | 'M' | 'Q' | 'H';
125
+ /** Quiet zone modules (default: 4) */
126
+ quietZone?: number;
127
+ }
128
+ /**
129
+ * Generate a QR code as an SVG string.
130
+ */
131
+ declare function generateQRSvg(data: string, options?: QRCodeOptions): string;
132
+ /**
133
+ * Generate a QR code as a data URL (PNG via canvas).
134
+ */
135
+ declare function generateQRDataUrl(data: string, options?: QRCodeOptions): string;
136
+
137
+ /**
138
+ * @eudi-verify/client - Verification State Machine
139
+ *
140
+ * Manages the verification flow with state transitions and polling.
141
+ */
142
+
143
+ /**
144
+ * All possible verification states.
145
+ */
146
+ type VerificationState = {
147
+ status: 'idle';
148
+ } | {
149
+ status: 'loading';
150
+ } | {
151
+ status: 'showQR';
152
+ qrDataUrl: string;
153
+ qrUrl: string;
154
+ sessionId: string;
155
+ } | {
156
+ status: 'waitingForWallet';
157
+ sessionId: string;
158
+ } | {
159
+ status: 'verified';
160
+ token: string;
161
+ claims: VerifiedClaims;
162
+ } | {
163
+ status: 'rejected';
164
+ error?: string;
165
+ } | {
166
+ status: 'expired';
167
+ } | {
168
+ status: 'error';
169
+ error: string;
170
+ };
171
+ /**
172
+ * State change callback.
173
+ */
174
+ type StateCallback = (state: VerificationState) => void;
175
+ /**
176
+ * Configuration for the verification flow.
177
+ */
178
+ interface VerificationConfig {
179
+ /** Base URL of the EUDI Verifier API */
180
+ apiUrl: string;
181
+ /** Polling configuration */
182
+ polling?: PollingConfig;
183
+ /** QR code options */
184
+ qr?: QRCodeOptions;
185
+ /** Optional fetch implementation (for testing) */
186
+ fetch?: typeof fetch;
187
+ }
188
+ /**
189
+ * Verification instance for managing a verification flow.
190
+ */
191
+ interface Verification {
192
+ /** Current state (read-only) */
193
+ readonly state: VerificationState;
194
+ /** Start a new verification flow */
195
+ start(request: VerificationRequest): Promise<void>;
196
+ /** Cancel the current verification */
197
+ cancel(): Promise<void>;
198
+ /** Clean up resources */
199
+ destroy(): void;
200
+ /** Subscribe to state changes. Returns unsubscribe function. */
201
+ subscribe(callback: StateCallback): () => void;
202
+ }
203
+ /**
204
+ * Create a new verification instance.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * const verification = createVerification({ apiUrl: 'https://api.example.com' });
209
+ *
210
+ * verification.subscribe((state) => {
211
+ * console.log('State:', state.status);
212
+ * if (state.status === 'verified') {
213
+ * console.log('Token:', state.token);
214
+ * }
215
+ * });
216
+ *
217
+ * await verification.start({ age_over_18: true });
218
+ * ```
219
+ */
220
+ declare function createVerification(config: VerificationConfig): Verification;
221
+
222
+ /**
223
+ * @eudi-verify/client - API Client
224
+ *
225
+ * Typed HTTP client for the EUDI Verifier API using native fetch.
226
+ */
227
+
228
+ /**
229
+ * Configuration for the API client.
230
+ */
231
+ interface ApiClientConfig {
232
+ /** Base URL of the EUDI Verifier API */
233
+ baseUrl: string;
234
+ /** Optional fetch implementation (for testing) */
235
+ fetch?: typeof fetch;
236
+ /** Request timeout in milliseconds (default: 30000) */
237
+ timeoutMs?: number;
238
+ }
239
+ /**
240
+ * Typed API client interface.
241
+ */
242
+ interface EudiApiClient {
243
+ /** Create a new verification session */
244
+ createSession(request: VerificationRequest): Promise<Session>;
245
+ /** Get the current state of a session */
246
+ getSession(sessionId: string): Promise<Session>;
247
+ /** Cancel a pending session */
248
+ cancelSession(sessionId: string): Promise<Session>;
249
+ }
250
+ /**
251
+ * Create a typed API client for the EUDI Verifier API.
252
+ */
253
+ declare function createApiClient(config: ApiClientConfig): EudiApiClient;
254
+
255
+ /**
256
+ * @eudi-verify/client - Error Types
257
+ */
258
+
259
+ /**
260
+ * Base error class for EUDI client errors.
261
+ */
262
+ declare class EudiClientError extends Error {
263
+ constructor(message: string);
264
+ }
265
+ /**
266
+ * Network error (fetch failed, timeout, etc.)
267
+ */
268
+ declare class NetworkError extends EudiClientError {
269
+ readonly cause?: Error;
270
+ constructor(message: string, cause?: Error);
271
+ }
272
+ /**
273
+ * API returned an error response.
274
+ */
275
+ declare class ApiResponseError extends EudiClientError {
276
+ readonly statusCode: number;
277
+ readonly errorCode: string;
278
+ readonly details?: Record<string, unknown>;
279
+ constructor(statusCode: number, response: ApiError);
280
+ }
281
+ /**
282
+ * Session not found (404).
283
+ */
284
+ declare class SessionNotFoundError extends ApiResponseError {
285
+ readonly sessionId: string;
286
+ constructor(sessionId: string);
287
+ }
288
+ /**
289
+ * Rate limit exceeded (429).
290
+ */
291
+ declare class RateLimitError extends ApiResponseError {
292
+ readonly retryAfterMs?: number;
293
+ constructor(retryAfterMs?: number);
294
+ }
295
+ /**
296
+ * Verification was cancelled.
297
+ */
298
+ declare class VerificationCancelledError extends EudiClientError {
299
+ constructor();
300
+ }
301
+ /**
302
+ * Session expired.
303
+ */
304
+ declare class SessionExpiredError extends EudiClientError {
305
+ constructor();
306
+ }
307
+
308
+ /**
309
+ * @eudi-verify/client
310
+ *
311
+ * Vanilla TypeScript client for EUDI Wallet verification flows.
312
+ * Zero framework dependencies.
313
+ *
314
+ * @example
315
+ * ```ts
316
+ * import { createVerification } from '@eudi-verify/client';
317
+ *
318
+ * const verification = createVerification({
319
+ * apiUrl: 'https://api.example.com',
320
+ * });
321
+ *
322
+ * verification.subscribe((state) => {
323
+ * if (state.status === 'showQR') {
324
+ * // Display state.qrDataUrl
325
+ * } else if (state.status === 'verified') {
326
+ * // Use state.token for server-side verification
327
+ * }
328
+ * });
329
+ *
330
+ * await verification.start({ age_over_18: true });
331
+ * ```
332
+ */
333
+ declare const VERSION = "0.1.0";
334
+
335
+ export { type ApiClientConfig, type ApiError, ApiResponseError, type EudiApiClient, EudiClientError, NetworkError, type Poller, type PollingConfig, type QRCodeOptions, RateLimitError, type Session, SessionExpiredError, SessionNotFoundError, type SessionStatus, type StateCallback, TERMINAL_STATUSES, VERSION, type Verification, VerificationCancelledError, type VerificationConfig, type VerificationRequest, type VerificationState, type VerifiedClaims, createApiClient, createPoller, createVerification, generateQRDataUrl, generateQRSvg, isTerminalStatus };