@sparkvault/sdk 1.0.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 (50) hide show
  1. package/README.md +720 -0
  2. package/dist/auto-init.d.ts +51 -0
  3. package/dist/config.d.ts +25 -0
  4. package/dist/errors.d.ts +30 -0
  5. package/dist/http.d.ts +48 -0
  6. package/dist/identity/api.d.ts +101 -0
  7. package/dist/identity/container.d.ts +49 -0
  8. package/dist/identity/handlers/index.d.ts +9 -0
  9. package/dist/identity/handlers/passkey-handler.d.ts +52 -0
  10. package/dist/identity/handlers/sparklink-handler.d.ts +43 -0
  11. package/dist/identity/handlers/totp-handler.d.ts +52 -0
  12. package/dist/identity/index.d.ts +69 -0
  13. package/dist/identity/inline-container.d.ts +60 -0
  14. package/dist/identity/methods.d.ts +23 -0
  15. package/dist/identity/modal.d.ts +74 -0
  16. package/dist/identity/renderer.d.ts +97 -0
  17. package/dist/identity/state.d.ts +95 -0
  18. package/dist/identity/styles.d.ts +22 -0
  19. package/dist/identity/types.d.ts +183 -0
  20. package/dist/identity/utils/cooldown-timer.d.ts +73 -0
  21. package/dist/identity/utils/index.d.ts +5 -0
  22. package/dist/identity/utils.d.ts +27 -0
  23. package/dist/identity/views/base.d.ts +62 -0
  24. package/dist/identity/views/error.d.ts +25 -0
  25. package/dist/identity/views/icons.d.ts +34 -0
  26. package/dist/identity/views/identity-input.d.ts +48 -0
  27. package/dist/identity/views/index.d.ts +14 -0
  28. package/dist/identity/views/loading.d.ts +15 -0
  29. package/dist/identity/views/method-select.d.ts +29 -0
  30. package/dist/identity/views/passkey-prompt.d.ts +22 -0
  31. package/dist/identity/views/passkey.d.ts +38 -0
  32. package/dist/identity/views/sparklink-waiting.d.ts +33 -0
  33. package/dist/identity/views/totp-verify.d.ts +58 -0
  34. package/dist/index.d.ts +658 -0
  35. package/dist/logger.d.ts +45 -0
  36. package/dist/rng/index.d.ts +54 -0
  37. package/dist/rng/types.d.ts +26 -0
  38. package/dist/sparks/index.d.ts +37 -0
  39. package/dist/sparks/types.d.ts +56 -0
  40. package/dist/sparkvault.cjs.js +6152 -0
  41. package/dist/sparkvault.cjs.js.map +1 -0
  42. package/dist/sparkvault.esm.js +6137 -0
  43. package/dist/sparkvault.esm.js.map +1 -0
  44. package/dist/sparkvault.js +2 -0
  45. package/dist/sparkvault.js.map +1 -0
  46. package/dist/utils/base64url.d.ts +49 -0
  47. package/dist/utils/retry.d.ts +32 -0
  48. package/dist/vaults/index.d.ts +83 -0
  49. package/dist/vaults/types.d.ts +120 -0
  50. package/package.json +64 -0
@@ -0,0 +1,658 @@
1
+ /**
2
+ * SparkVault SDK Configuration
3
+ */
4
+ interface SparkVaultConfig {
5
+ /** Account ID for Identity operations */
6
+ accountId: string;
7
+ /** Request timeout in milliseconds (default: 30000) */
8
+ timeout?: number;
9
+ /**
10
+ * Preload Identity configuration on SDK init (default: true).
11
+ * When enabled, the /config call is made immediately when the SDK initializes,
12
+ * so verify() opens instantly without waiting for the config fetch.
13
+ * Set to false to defer config loading until verify() is called.
14
+ */
15
+ preloadConfig?: boolean;
16
+ }
17
+ interface ResolvedConfig {
18
+ accountId: string;
19
+ timeout: number;
20
+ apiBaseUrl: string;
21
+ identityBaseUrl: string;
22
+ preloadConfig: boolean;
23
+ }
24
+
25
+ /**
26
+ * Identity Module Types
27
+ */
28
+ type AuthMethod = 'passkey' | 'totp_email' | 'totp_sms' | 'totp_voice' | 'magic_link' | 'sparklink' | 'google' | 'apple' | 'microsoft' | 'github' | 'facebook' | 'linkedin' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
29
+ type Theme = 'light' | 'dark';
30
+ interface VerifyOptions {
31
+ /** Pre-fill email address (mutually exclusive with phone) */
32
+ email?: string;
33
+ /** Pre-fill phone number in E.164 format, e.g. "+14155551234" (mutually exclusive with email) */
34
+ phone?: string;
35
+ /** Override backdrop blur setting from app config */
36
+ backdropBlur?: boolean;
37
+ /** Called when user cancels */
38
+ onCancel?: () => void;
39
+ /** Called when verification completes (before promise resolves) */
40
+ onSuccess?: (result: VerifyResult) => void;
41
+ /** Called on error (before promise rejects) */
42
+ onError?: (error: Error) => void;
43
+ }
44
+ interface RenderOptions extends VerifyOptions {
45
+ /** Target element to render inline UI into (required) */
46
+ target: HTMLElement;
47
+ /** Show header with branding and close button (default: true) */
48
+ showHeader?: boolean;
49
+ /** Show close button in header (default: true, requires showHeader) */
50
+ showCloseButton?: boolean;
51
+ /** Show footer with SparkVault branding (default: true) */
52
+ showFooter?: boolean;
53
+ }
54
+ interface VerifyResult {
55
+ /** Signed JWT token */
56
+ token: string;
57
+ /** Verified identity (email or phone) */
58
+ identity: string;
59
+ /** Type of identity verified */
60
+ identityType: 'email' | 'phone';
61
+ }
62
+ interface TokenClaims {
63
+ /** Issuer */
64
+ iss: string;
65
+ /** Subject (hashed identity) */
66
+ sub: string;
67
+ /** Audience (account ID for simple tokens, client ID for OIDC) */
68
+ aud: string;
69
+ /** Expiry (Unix seconds) */
70
+ exp: number;
71
+ /** Issued at (Unix seconds) */
72
+ iat: number;
73
+ /** Unique token ID for replay protection */
74
+ jti?: string;
75
+ /** Verified identity (email or phone) */
76
+ identity: string;
77
+ /** Identity type */
78
+ identity_type: 'email' | 'phone';
79
+ /** Verification timestamp (Unix seconds) */
80
+ verified_at: number;
81
+ /** Authentication method used */
82
+ method: string;
83
+ }
84
+
85
+ /**
86
+ * Identity Module
87
+ *
88
+ * Provides identity verification through a DOM-based modal interface.
89
+ * Supports passkey, TOTP, magic link, and social authentication.
90
+ */
91
+
92
+ declare class IdentityModule {
93
+ private readonly config;
94
+ private readonly api;
95
+ private renderer;
96
+ constructor(config: ResolvedConfig);
97
+ /**
98
+ * Open the identity verification modal (popup).
99
+ * Returns when user successfully verifies their identity.
100
+ *
101
+ * @example
102
+ * const result = await sv.identity.pop({
103
+ * email: 'user@example.com'
104
+ * });
105
+ * console.log(result.token, result.identity, result.identityType);
106
+ */
107
+ pop(options?: VerifyOptions): Promise<VerifyResult>;
108
+ /**
109
+ * Render identity verification inline within a target element.
110
+ * Unlike verify() which opens a modal popup, this embeds the UI
111
+ * directly into the specified element.
112
+ *
113
+ * @example
114
+ * // Render in a div
115
+ * const result = await sv.identity.render({
116
+ * target: document.getElementById('auth-container'),
117
+ * email: 'user@example.com'
118
+ * });
119
+ *
120
+ * @example
121
+ * // Render in a custom dialog without header/footer
122
+ * const result = await sv.identity.render({
123
+ * target: dialogContentElement,
124
+ * showHeader: false,
125
+ * showFooter: false
126
+ * });
127
+ */
128
+ render(options: RenderOptions): Promise<VerifyResult>;
129
+ /**
130
+ * Verify and decode an identity token.
131
+ * Validates the token structure, expiry, and issuer.
132
+ *
133
+ * Note: For production use, verify the Ed25519 signature server-side
134
+ * using the JWKS endpoint.
135
+ *
136
+ * @example
137
+ * const claims = await sv.identity.verifyToken(token);
138
+ * console.log(claims.identity, claims.identity_type, claims.method);
139
+ */
140
+ verifyToken(token: string): Promise<TokenClaims>;
141
+ /**
142
+ * Close the identity modal if open.
143
+ */
144
+ close(): void;
145
+ /**
146
+ * @deprecated Use `pop()` instead. Will be removed in v2.0.
147
+ */
148
+ verify(options?: VerifyOptions): Promise<VerifyResult>;
149
+ }
150
+
151
+ /**
152
+ * Retry Utility with Exponential Backoff
153
+ *
154
+ * Per CLAUDE.md §7: Retries allowed only if idempotent, MUST use exponential backoff.
155
+ */
156
+ interface RetryOptions {
157
+ /** Maximum number of retry attempts (default: 3) */
158
+ maxAttempts?: number;
159
+ /** Base delay in milliseconds (default: 200) */
160
+ baseDelayMs?: number;
161
+ /** Maximum delay in milliseconds (default: 5000) */
162
+ maxDelayMs?: number;
163
+ /** Jitter factor 0-1 to randomize delays (default: 0.2) */
164
+ jitterFactor?: number;
165
+ /** Function to determine if error is retryable (default: checks for network/timeout/5xx) */
166
+ isRetryable?: (error: unknown) => boolean;
167
+ }
168
+
169
+ /**
170
+ * SparkVault SDK HTTP Client
171
+ */
172
+
173
+ interface RequestOptions {
174
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
175
+ headers?: Record<string, string>;
176
+ body?: unknown;
177
+ timeout?: number;
178
+ /** Enable automatic retry with exponential backoff (per CLAUDE.md §7) */
179
+ retry?: boolean | RetryOptions;
180
+ }
181
+ interface ApiResponse<T = unknown> {
182
+ data: T;
183
+ status: number;
184
+ headers: Headers;
185
+ }
186
+ declare class HttpClient {
187
+ private readonly config;
188
+ constructor(config: ResolvedConfig);
189
+ request<T = unknown>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
190
+ /**
191
+ * Execute the actual HTTP request (internal implementation)
192
+ */
193
+ private executeRequest;
194
+ /**
195
+ * Check if an error is safe to retry
196
+ * Per CLAUDE.md §7: Only retry on transient/network errors, not client errors
197
+ */
198
+ private isRetryableError;
199
+ private parseResponse;
200
+ private createErrorFromResponse;
201
+ get<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
202
+ post<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
203
+ put<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
204
+ patch<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
205
+ delete<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
206
+ /**
207
+ * Request raw binary data (e.g., file downloads).
208
+ * Returns a Blob instead of parsed JSON.
209
+ */
210
+ requestRaw(path: string, options?: RequestOptions): Promise<Blob>;
211
+ /**
212
+ * Execute the actual raw HTTP request (internal implementation)
213
+ */
214
+ private executeRequestRaw;
215
+ }
216
+
217
+ /**
218
+ * Sparks Module Types
219
+ */
220
+ interface CreateSparkOptions {
221
+ /** Secret payload to encrypt */
222
+ payload: string | Uint8Array;
223
+ /** Time-to-live in seconds (default: 3600) */
224
+ ttl?: number;
225
+ /** Maximum number of reads before destruction (default: 1) */
226
+ maxReads?: number;
227
+ /** Optional password protection */
228
+ password?: string;
229
+ /** Optional name/label for the spark */
230
+ name?: string;
231
+ }
232
+ interface Spark {
233
+ /** Spark ID */
234
+ id: string;
235
+ /** Direct URL to read the spark */
236
+ url: string;
237
+ /** Expiry timestamp (Unix seconds) */
238
+ expiresAt: number;
239
+ /** Maximum reads remaining */
240
+ maxReads: number;
241
+ /** Name/label if provided */
242
+ name?: string;
243
+ }
244
+ interface SparkPayload {
245
+ /** Decrypted data */
246
+ data: string | Uint8Array;
247
+ /** When the spark was read (Unix seconds) */
248
+ readAt: number;
249
+ /** Whether the spark was destroyed after reading */
250
+ burned: boolean;
251
+ /** Reads remaining (0 if burned) */
252
+ readsRemaining: number;
253
+ }
254
+
255
+ /**
256
+ * Sparks Module
257
+ *
258
+ * Create and read ephemeral encrypted secrets.
259
+ * Sparks are destroyed after being read (burn-on-read).
260
+ */
261
+
262
+ declare class SparksModule {
263
+ private readonly http;
264
+ constructor(http: HttpClient);
265
+ /**
266
+ * Create an ephemeral encrypted secret.
267
+ *
268
+ * @example
269
+ * const spark = await sv.sparks.create({
270
+ * payload: 'my secret data',
271
+ * ttl: 3600,
272
+ * maxReads: 1
273
+ * });
274
+ * console.log(spark.url);
275
+ */
276
+ create(options: CreateSparkOptions): Promise<Spark>;
277
+ /**
278
+ * Read and burn a spark.
279
+ * The spark is destroyed after the configured number of reads.
280
+ *
281
+ * @example
282
+ * const payload = await sv.sparks.read('spk_abc123');
283
+ * console.log(payload.data);
284
+ */
285
+ read(id: string, password?: string): Promise<SparkPayload>;
286
+ private validateCreateOptions;
287
+ private encodePayload;
288
+ private decodePayload;
289
+ }
290
+
291
+ /**
292
+ * Vaults Module Types
293
+ */
294
+ interface CreateVaultOptions {
295
+ /** Vault name */
296
+ name: string;
297
+ /** Store VMK server-side (less secure, more convenient) */
298
+ hostedVmk?: boolean;
299
+ }
300
+ interface Vault {
301
+ /** Vault ID */
302
+ id: string;
303
+ /** Vault name */
304
+ name: string;
305
+ /** Vault Master Key (24 chars) - STORE SECURELY! */
306
+ vmk: string;
307
+ /** Creation timestamp (Unix seconds) */
308
+ createdAt: number;
309
+ /** Whether VMK is hosted server-side */
310
+ hostedVmk: boolean;
311
+ }
312
+ interface UnsealedVault {
313
+ /** Vault ID */
314
+ id: string;
315
+ /** Vault name */
316
+ name: string;
317
+ /** Vault Access Token (short-lived session) */
318
+ vatToken: string;
319
+ /** VAT expiry timestamp (Unix seconds) */
320
+ expiresAt: number;
321
+ /** Number of ingots in vault */
322
+ ingotCount: number;
323
+ /** Total storage used in bytes */
324
+ storageBytes: number;
325
+ }
326
+ interface VaultSummary {
327
+ /** Vault ID */
328
+ id: string;
329
+ /** Vault name */
330
+ name: string;
331
+ /** Creation timestamp (Unix seconds) */
332
+ createdAt: number;
333
+ /** Number of ingots */
334
+ ingotCount: number;
335
+ /** Total storage used in bytes */
336
+ storageBytes: number;
337
+ /** Whether VMK is hosted server-side */
338
+ hostedVmk: boolean;
339
+ }
340
+ interface Ingot {
341
+ /** Ingot ID */
342
+ id: string;
343
+ /** Ingot name */
344
+ name: string;
345
+ /** Content type (MIME) */
346
+ contentType: string;
347
+ /** Size in bytes */
348
+ size: number;
349
+ /** Creation timestamp (Unix seconds) */
350
+ createdAt: number;
351
+ /** Ingot type: 'standard' or 'structured' */
352
+ type: 'standard' | 'structured';
353
+ }
354
+ interface UploadIngotOptions {
355
+ /** File to upload */
356
+ file: File | Blob;
357
+ /** Optional name (defaults to file name) */
358
+ name?: string;
359
+ /** Content type (auto-detected if not provided) */
360
+ contentType?: string;
361
+ }
362
+
363
+ /**
364
+ * Vaults Module
365
+ *
366
+ * Create and manage encrypted vaults and ingots.
367
+ * Uses Triple Zero-Trust encryption (SVMK + AMK + VMK).
368
+ */
369
+
370
+ declare class VaultsModule {
371
+ private readonly http;
372
+ constructor(_config: ResolvedConfig, http: HttpClient);
373
+ /**
374
+ * Create a new encrypted vault.
375
+ * IMPORTANT: Store the VMK securely - it cannot be recovered!
376
+ *
377
+ * @example
378
+ * const vault = await sv.vaults.create({ name: 'My Vault' });
379
+ * console.log('Save this VMK:', vault.vmk);
380
+ */
381
+ create(options: CreateVaultOptions): Promise<Vault>;
382
+ /**
383
+ * Unseal a vault to access its contents.
384
+ * Returns a short-lived Vault Access Token (VAT).
385
+ *
386
+ * @example
387
+ * const unsealed = await sv.vaults.unseal('vlt_abc', vmk);
388
+ * console.log('Ingots:', unsealed.ingotCount);
389
+ */
390
+ unseal(vaultId: string, vmk: string): Promise<UnsealedVault>;
391
+ /**
392
+ * List all vaults for the account.
393
+ *
394
+ * @example
395
+ * const vaults = await sv.vaults.list();
396
+ * vaults.forEach(v => console.log(v.name));
397
+ */
398
+ list(): Promise<VaultSummary[]>;
399
+ /**
400
+ * Delete a vault and all its ingots.
401
+ * This action is irreversible!
402
+ *
403
+ * @example
404
+ * await sv.vaults.delete('vlt_abc', vmk);
405
+ */
406
+ delete(vaultId: string, vmk: string): Promise<void>;
407
+ /**
408
+ * Upload a file as an ingot to an unsealed vault.
409
+ *
410
+ * @example
411
+ * const ingot = await sv.vaults.uploadIngot(unsealed, {
412
+ * file: myFile,
413
+ * name: 'document.pdf'
414
+ * });
415
+ */
416
+ uploadIngot(vault: UnsealedVault, options: UploadIngotOptions): Promise<Ingot>;
417
+ /**
418
+ * Download an ingot from an unsealed vault.
419
+ *
420
+ * @example
421
+ * const blob = await sv.vaults.downloadIngot(unsealed, 'ing_abc');
422
+ * const url = URL.createObjectURL(blob);
423
+ */
424
+ downloadIngot(vault: UnsealedVault, ingotId: string): Promise<Blob>;
425
+ /**
426
+ * List all ingots in an unsealed vault.
427
+ *
428
+ * @example
429
+ * const ingots = await sv.vaults.listIngots(unsealed);
430
+ * ingots.forEach(i => console.log(i.name, i.size));
431
+ */
432
+ listIngots(vault: UnsealedVault): Promise<Ingot[]>;
433
+ /**
434
+ * Delete an ingot from an unsealed vault.
435
+ *
436
+ * @example
437
+ * await sv.vaults.deleteIngot(unsealed, 'ing_abc');
438
+ */
439
+ deleteIngot(vault: UnsealedVault, ingotId: string): Promise<void>;
440
+ private validateCreateOptions;
441
+ private validateUploadOptions;
442
+ }
443
+
444
+ /**
445
+ * RNG Module Types
446
+ */
447
+ type RNGFormat = 'hex' | 'base64' | 'base64url' | 'alphanumeric' | 'alphanumeric-mixed' | 'password' | 'numeric' | 'uuid' | 'bytes';
448
+ interface GenerateOptions {
449
+ /** Number of bytes to generate (1-1024) */
450
+ bytes: number;
451
+ /** Output format (default: 'base64url') */
452
+ format?: RNGFormat;
453
+ }
454
+ interface RandomResult {
455
+ /** Generated random value */
456
+ value: string | number[];
457
+ /** Number of bytes generated */
458
+ bytes: number;
459
+ /** Format used */
460
+ format: RNGFormat;
461
+ /** Reference ID for billing/audit */
462
+ referenceId: string;
463
+ }
464
+
465
+ /**
466
+ * RNG Module
467
+ *
468
+ * Generate cryptographically secure random numbers.
469
+ * Uses hybrid entropy from AWS KMS HSM + local CSPRNG.
470
+ */
471
+
472
+ declare class RNGModule {
473
+ private readonly http;
474
+ constructor(http: HttpClient);
475
+ /**
476
+ * Generate cryptographically secure random bytes.
477
+ *
478
+ * @example
479
+ * const result = await sv.rng.generate({ bytes: 32, format: 'hex' });
480
+ * console.log(result.value);
481
+ */
482
+ generate(options: GenerateOptions): Promise<RandomResult>;
483
+ /**
484
+ * Generate a random UUID v4.
485
+ *
486
+ * @example
487
+ * const uuid = await sv.rng.uuid();
488
+ * console.log(uuid); // 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
489
+ */
490
+ uuid(): Promise<string>;
491
+ /**
492
+ * Generate a random hex string.
493
+ *
494
+ * @example
495
+ * const hex = await sv.rng.hex(16);
496
+ * console.log(hex); // '1a2b3c4d5e6f7890...'
497
+ */
498
+ hex(bytes: number): Promise<string>;
499
+ /**
500
+ * Generate a random alphanumeric string.
501
+ *
502
+ * @example
503
+ * const code = await sv.rng.alphanumeric(8);
504
+ * console.log(code); // 'A1B2C3D4'
505
+ */
506
+ alphanumeric(bytes: number): Promise<string>;
507
+ /**
508
+ * Generate a random password with special characters.
509
+ *
510
+ * @example
511
+ * const password = await sv.rng.password(16);
512
+ * console.log(password); // 'aB3$xY7!mN9@pQ2#'
513
+ */
514
+ password(bytes: number): Promise<string>;
515
+ private validateOptions;
516
+ }
517
+
518
+ /**
519
+ * SparkVault Debug Logger
520
+ *
521
+ * Conditional logging that respects debug mode setting.
522
+ * When debug is enabled, logs detailed information to console.
523
+ * When disabled (default), only fatal errors are logged.
524
+ */
525
+ /**
526
+ * Enable or disable debug logging
527
+ */
528
+ declare function setDebugMode(enabled: boolean): void;
529
+ /**
530
+ * Logger object for convenient access
531
+ */
532
+ declare const logger: {
533
+ /**
534
+ * Debug level - verbose details for troubleshooting
535
+ */
536
+ debug: (message: string, ...args: unknown[]) => void;
537
+ /**
538
+ * Info level - general information
539
+ */
540
+ info: (message: string, ...args: unknown[]) => void;
541
+ /**
542
+ * Warn level - warnings that don't prevent operation
543
+ */
544
+ warn: (message: string, ...args: unknown[]) => void;
545
+ /**
546
+ * Error level - always logged regardless of debug mode
547
+ */
548
+ error: (message: string, ...args: unknown[]) => void;
549
+ /**
550
+ * Group related logs together (only in debug mode)
551
+ */
552
+ group: (label: string) => void;
553
+ /**
554
+ * End a log group
555
+ */
556
+ groupEnd: () => void;
557
+ };
558
+
559
+ /**
560
+ * SparkVault SDK Error Types
561
+ */
562
+ declare class SparkVaultError extends Error {
563
+ readonly code: string;
564
+ readonly statusCode?: number;
565
+ readonly details?: Record<string, unknown>;
566
+ constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
567
+ }
568
+ declare class AuthenticationError extends SparkVaultError {
569
+ constructor(message: string, details?: Record<string, unknown>);
570
+ }
571
+ declare class AuthorizationError extends SparkVaultError {
572
+ constructor(message: string, details?: Record<string, unknown>);
573
+ }
574
+ declare class ValidationError extends SparkVaultError {
575
+ constructor(message: string, details?: Record<string, unknown>);
576
+ }
577
+ declare class NetworkError extends SparkVaultError {
578
+ constructor(message: string, details?: Record<string, unknown>);
579
+ }
580
+ declare class TimeoutError extends SparkVaultError {
581
+ constructor(message?: string);
582
+ }
583
+ declare class UserCancelledError extends SparkVaultError {
584
+ constructor(message?: string);
585
+ }
586
+ declare class PopupBlockedError extends SparkVaultError {
587
+ constructor();
588
+ }
589
+
590
+ /**
591
+ * SparkVault JavaScript SDK
592
+ *
593
+ * A unified SDK for Identity, Sparks, Vaults, and RNG.
594
+ *
595
+ * @example Auto-Init (Zero-Config)
596
+ * ```html
597
+ * <script
598
+ * async
599
+ * src="https://cdn.sparkvault.com/sdk/v1/sparkvault.js"
600
+ * data-account-id="acc_your_account"
601
+ * data-attach-selector=".js-sparkvault-auth"
602
+ * data-success-url="https://example.com/auth/verify-token"
603
+ * data-debug="true"
604
+ * ></script>
605
+ *
606
+ * <button class="js-sparkvault-auth">Login with SparkVault</button>
607
+ * ```
608
+ *
609
+ * @example Manual Init
610
+ * ```html
611
+ * <script src="https://cdn.sparkvault.com/sdk/v1/sparkvault.js"></script>
612
+ * <script>
613
+ * const sv = SparkVault.init({
614
+ * accountId: 'acc_your_account'
615
+ * });
616
+ *
617
+ * // Open identity verification modal
618
+ * const result = await sv.identity.pop();
619
+ * console.log(result.identity, result.identityType);
620
+ * </script>
621
+ * ```
622
+ */
623
+
624
+ declare class SparkVault {
625
+ /** Identity verification module */
626
+ readonly identity: IdentityModule;
627
+ /** Ephemeral encrypted secrets module */
628
+ readonly sparks: SparksModule;
629
+ /** Persistent encrypted storage module */
630
+ readonly vaults: VaultsModule;
631
+ /** Cryptographic random number generation module */
632
+ readonly rng: RNGModule;
633
+ private readonly config;
634
+ private constructor();
635
+ /**
636
+ * Initialize the SparkVault SDK.
637
+ *
638
+ * @param config - SDK configuration
639
+ * @returns SparkVault instance
640
+ *
641
+ * @example
642
+ * const sv = SparkVault.init({
643
+ * accountId: 'acc_your_account'
644
+ * });
645
+ */
646
+ static init(config: SparkVaultConfig): SparkVault;
647
+ /** Get the SDK version */
648
+ static get version(): string;
649
+ }
650
+
651
+ declare global {
652
+ interface Window {
653
+ SparkVault: typeof SparkVault;
654
+ }
655
+ }
656
+
657
+ export { AuthenticationError, AuthorizationError, NetworkError, PopupBlockedError, SparkVault, SparkVaultError, TimeoutError, UserCancelledError, ValidationError, SparkVault as default, logger, setDebugMode };
658
+ export type { AuthMethod, CreateSparkOptions, CreateVaultOptions, GenerateOptions, Ingot, RNGFormat, RandomResult, Spark, SparkPayload, SparkVaultConfig, Theme, TokenClaims, UnsealedVault, UploadIngotOptions, Vault, VaultSummary, VerifyOptions, VerifyResult };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * SparkVault Debug Logger
3
+ *
4
+ * Conditional logging that respects debug mode setting.
5
+ * When debug is enabled, logs detailed information to console.
6
+ * When disabled (default), only fatal errors are logged.
7
+ */
8
+ /**
9
+ * Enable or disable debug logging
10
+ */
11
+ export declare function setDebugMode(enabled: boolean): void;
12
+ /**
13
+ * Check if debug mode is enabled
14
+ */
15
+ export declare function isDebugEnabled(): boolean;
16
+ /**
17
+ * Logger object for convenient access
18
+ */
19
+ export declare const logger: {
20
+ /**
21
+ * Debug level - verbose details for troubleshooting
22
+ */
23
+ debug: (message: string, ...args: unknown[]) => void;
24
+ /**
25
+ * Info level - general information
26
+ */
27
+ info: (message: string, ...args: unknown[]) => void;
28
+ /**
29
+ * Warn level - warnings that don't prevent operation
30
+ */
31
+ warn: (message: string, ...args: unknown[]) => void;
32
+ /**
33
+ * Error level - always logged regardless of debug mode
34
+ */
35
+ error: (message: string, ...args: unknown[]) => void;
36
+ /**
37
+ * Group related logs together (only in debug mode)
38
+ */
39
+ group: (label: string) => void;
40
+ /**
41
+ * End a log group
42
+ */
43
+ groupEnd: () => void;
44
+ };
45
+ export default logger;